0

画像にスライディング ウィンドウがあります。そのウィンドウ内の平均強度が > 210 の場合、そのウィンドウで GLCM フィーチャが計算されます。GLCM 機能が if ステートメントの条件を満たしている場合、このスライディング ウィンドウの周りに四角形を描画する必要があります。次のコードを使用してこれを試しましたが、長方形が画像上の正しい位置にありません。四角形を描画するコードを間違った場所に置いたのか、それとも間違った座標を渡したのかわかりません。誰でもこれで私を助けてくれますか?

N2=8;
info2 = repmat(struct, ceil(size(Z, 1) / N2), ceil(size(Z, 2) / N2)); 
for row1 = 1:N2:size(Z, 1)%loop through each pixel in the 8x8 window
    for col1 = 1:N2:size(Z, 2)
        x = (row1 - 1) / N2 + 1;
        y = (col1 - 1) / N2 + 1;

        imgWindow2 = Z(row1:min(end,row1+N2-1), col1:min(end,col1+N2-1));
        average2 = mean(imgWindow2(:));
        window2(x,y).average=average2;

        if average2>210
            offsets0 = [0 1];
            glcms = graycomatrix(imgWindow2,'Offset',offsets0);
            stats = graycoprops(glcms,'all');

            correlation=[stats.Correlation];  
            contrast=[stats.Contrast];
            homogeneity=[stats.Homogeneity];
            energy=[stats.Energy];

            %if these conditions are met then this window contains an ROI
            if (homogeneity > 0.9)
                if  (contrast<0.2)
                    if (energy>0.6)                                                      
                        %%show the ROI on the original image%%
                        Z1  = insertShape(Z, 'rectangle', [x y 32 32]);
                        figure(2);      
                        imshow(Z1);
                    end                                                                                           
                end
            end
        end % end if>210
    end 
end % window
4

1 に答える 1