首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >压缩/打包

压缩/打包
EN

Stack Overflow用户
提问于 2010-07-01 06:53:06
回答 1查看 103关注 0票数 1

我有一个问题:给定一个包含0或1的数组nxm,我需要将0值分组为矩形。一开始,我使用的是一个简单的四叉树,但树的同一层中的不同节点具有相同的值。我不能完全确定R-tree是否适用于我的问题或其他数据结构,因为我只会在预计算步骤中使用此结构,仅此而已。

附言:我正在处理2D图像

EN

回答 1

Stack Overflow用户

发布于 2010-08-20 17:39:12

我会选择递归解决方案。一些类似的东西

代码语言:javascript
复制
iszeroes returns 1 if matrix has only zeroes
def search_for_zeroes(matrix, colormatrix)
!   conquer - part, matrix is essentially only a cell   
    if size(matrix) .eq. 1 then 
        search_for_zeroes = iszeroes(matrix)
        if iszeroes(colormatrix(matrix)then 
            colormatrix(matrix) = black) 
        end if  
    end if
!   divide - part, looks if four cells are all zero and colors them black
    if search_for_zeroes(upper_left) and search_for_zeroes(upper_right) 
        and search_for_zeroes(lower_left) and search_for_zeroes(lower_right) then
        search_for_zeroes = true
        colormatrix(matrix) = black         
    end if

我没有自己编写代码,只是伪代码。当我今天下班的时候,我会改变它,但这也应该可以。干杯

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

https://stackoverflow.com/questions/3153989

复制
相关文章

相似问题

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