matlab中给图像加几个矩形框_Matlab-在图像上放置矩形

I have a sliding window on my image. If the average intensity within that window is > 210 then GLCM features are calculated on that window. If the GLCM features meet the conditions in the if statements then a rectangle should be drawn around this sliding window. I have tried this using the following code however the rectangle is not in the correct position on the image. I am unsure if I have put the code which draws the rectangle in the wrong place or if I have passed in the wrong coordinates. Can anyone help me with this please?

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

解决方案

Try using [col1 row1 32 32] instead of [x y 32 32]. I don't understand why you are computing x and y the way you do. You end up with x and y switched, and they are in "cells", not in pixels.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值