首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在另一个栅格的每一段中寻找(一个栅格的)最大值

在另一个栅格的每一段中寻找(一个栅格的)最大值
EN

Stack Overflow用户
提问于 2021-09-23 11:15:10
回答 1查看 181关注 0票数 0

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

从理论上讲,这看起来很简单,但我无法找到实现它的方法。我正在阅读scikit image文档,而且越来越困惑。从理论上讲,这将是:

代码语言:javascript
复制
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上有很多孤立的像素,它可以被解释为一个区域,并产生许多额外的最大值。为了防止这种情况,我用:

代码语言:javascript
复制
raster1 = raster1.astype(int)
raster1 = skimage.morphology.remove_small_objects(raster1 , min_size=20, connectivity=2, in_place=True)

raster-1似乎没有效果。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-10-01 20:50:26

删除我所做的小对象

array_aspect = sp.median_filter(array_aspect,size=10)

这给了我很好的结果。

为了找到每个封闭部分的最大海拔,我已经做了如下工作:

代码语言:javascript
复制
# %%% 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)`

我得到了我想要的结果。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69298943

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档