【问题标题】:compression/packing压缩/打包
【发布时间】:2010-06-30 22:53:05
【问题描述】:

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

p.s.:我正在处理 2D 图像

【问题讨论】:

    标签: image compression packing quadtree


    【解决方案1】:

    我会选择递归解决方案。类似于

    的东西
    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
    

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

    【讨论】:

      猜你喜欢
      • 2010-11-16
      • 2011-03-10
      • 1970-01-01
      • 2018-06-25
      • 1970-01-01
      • 1970-01-01
      • 2011-06-26
      • 2016-04-22
      • 1970-01-01
      相关资源
      最近更新 更多