1

問題があります: 0 または 1 を含む配列 nxm がある場合、0 の値を四角形にグループ化する必要があります。最初は単純な四分木を使用しましたが、ツリーの同じレベルにある異なるノードは同じ値を持ちます。Rツリーが私の問題または別のデータ構造で機能するかどうかは完全にはわかりません。この構造を事前計算ステップで使用するだけなので、それだけです。

ps: 2D 画像を扱っています

4

1 に答える 1

0

私は再帰的な解決策を選びます。の線に沿った何か

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-08-20T09:39:12.170 に答える