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

2024-09-30 03:24:03 发布

您现在位置:Python中文网/ 问答频道 /正文

有两个光栅,如下所示。仅由四个值组成的值[1,2,3,4]。另一个由800到2500之间的值组成。问题是遍历所有光栅-1区域并找到位于每个区域或段内部的光栅-2的最大值

Flow chart

理论上,它看起来很简单,但我找不到实现它的方法。我正在阅读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.

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

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

但是raster-1似乎没有效果


Tags: ofthe方法in文档image区域for
1条回答
网友
1楼 · 发布于 2024-09-30 03:24:03

移除我所做的小物件

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

我得到了我想要的结果

相关问题 更多 >

    热门问题