【问题标题】:Matlab- Put rectangle on imageMatlab-在图像上放置矩形
【发布时间】:2014-04-23 12:22:53
【问题描述】:

我的图像上有一个滑动窗口。如果该窗口内的平均强度 > 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

【问题讨论】:

    标签: matlab image-processing matlab-cvst glcm


    【解决方案1】:

    尝试使用 [col1 row1 32 32] 而不是 [x y 32 32]。我不明白你为什么要以你的方式计算 x 和 y 。你最终会切换 x 和 y,它们在“单元格”中,而不是在像素中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多