查找位于另一个栅格的每个段内的(一个栅格的)最大值

Finding maximum values (of one raster) which are inside each segment of another raster

有如下两个光栅。一个只包含四个值 [1,2,3,4]。另一个由 800 到 2500 之间的值组成。问题是遍历所有 raster-1 区域并找到位于 each 区域内的 raster-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.

这个问题还有另一个固有的问题,我不能 post 作为一个不同的主题。如您所见,raster-1 上有很多孤立的像素,可以将其解释为一个区域并产生很多额外的最大值。为了防止这种情况,我使用了:

raster1 = raster1.astype(int)
raster1 = skimage.morphology.remove_small_objects(raster1 , min_size=20, connectivity=2, in_place=True)

但是raster-1好像没有效果

移除我做过的小物件

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)`

我得到了我想要的结果。