下面有两个光栅。一个只有四个数值1,2,3,4,另一个值在800至2500之间。问题是要遍历所有的光栅-1区域,并找到位于、每个区域或段内的光栅-2的最大值。

从理论上讲,这看起来很简单,但我无法找到实现它的方法。我正在阅读scikit image文档,而且越来越困惑。从理论上讲,这将是:
for i in raster1rows:
for j in i:
# where j is a part of closed patch, iterate through the identical
# elements of raster-2 and find the maximum value.这个问题还有另一个固有的问题,我不能把它作为一个不同的话题来发表。正如你所看到的,栅格-1上有很多孤立的像素,它可以被解释为一个区域,并产生许多额外的最大值。为了防止这种情况,我用:
raster1 = raster1.astype(int)
raster1 = skimage.morphology.remove_small_objects(raster1 , min_size=20, connectivity=2, in_place=True)但raster-1似乎没有效果。
发布于 2021-10-01 20:50:26
删除我所做的小对象
array_aspect = sp.median_filter(array_aspect,size=10)
这给了我很好的结果。
为了找到每个封闭部分的最大海拔,我已经做了如下工作:
# %%% to flood-fill closed boundaries on the classified raster
p = 5
ind = 1
for i in rangerow:
for j in rangecol:
if array_aspect[i][j] in [0, 1, 2, 3, 4]:
print("{}. row: {} col: {} is {} is floodfilled with {}, {} meters".format(ind, i, j, array_aspect[i][j], p, array_dem[i][j]))
array_aspect = sk.flood_fill(array_aspect, (i,j), p, in_place=True, connectivity=2)
p = p + 1
else:
pass
ind = ind + 1
# %%% Finds the max elev inside each fill and returns an array-based [Y,X, (ELEV #in meters)]
p = 5
maxdems = {}
for i in rangerow:
for j in rangecol:
try:
if bool(maxdems[array_aspect[i][j]]) == False or maxdems[array_aspect[i][j]][-1] < array_dem[i][j]:
maxdems[array_aspect[i][j]] = [i, j, array_dem[i][j]]
else:
pass
except: #This is very diabolical, but yeah :))
maxdems[array_aspect[i][j]] = [i, j, array_dem[i][j]]
print(maxdems)`我得到了我想要的结果。
https://stackoverflow.com/questions/69298943
复制相似问题