1
我有一个问题: 给定一个包含0或1的数组nxm,我需要将0值 分组为矩形。在开始时,我使用了一个简单的四叉树,但树的同一级别中的不同节点具有相同的值。我是 不能完全确定R-tree是否适用于我的问题或其他数据结构,因为我只是在预计算步骤 中使用此结构,就是这样。压缩/包装
p.s .:我正在处理2D图像
我有一个问题: 给定一个包含0或1的数组nxm,我需要将0值 分组为矩形。在开始时,我使用了一个简单的四叉树,但树的同一级别中的不同节点具有相同的值。我是 不能完全确定R-tree是否适用于我的问题或其他数据结构,因为我只是在预计算步骤 中使用此结构,就是这样。压缩/包装
p.s .:我正在处理2D图像
我会选择递归解决方案。东西沿线
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
我还没有编码它自己,只是伪代码。我今天下班时会改变它,但这也应该起作用。 欢呼