我有一个问题:给定一个包含0或1的数组nxm,我需要将0值分组为矩形。一开始,我使用的是一个简单的四叉树,但树的同一层中的不同节点具有相同的值。我不能完全确定R-tree是否适用于我的问题或其他数据结构,因为我只会在预计算步骤中使用此结构,仅此而已。
附言:我正在处理2D图像
发布于 2010-08-20 17:39:12
我会选择递归解决方案。一些类似的东西
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我没有自己编写代码,只是伪代码。当我今天下班的时候,我会改变它,但这也应该可以。干杯
https://stackoverflow.com/questions/3153989
复制相似问题