highlight a sliding window on image

2 views (last 30 days)
Ciara
Ciara on 24 Apr 2014
Answered: Image Analyst on 1 Sep 2014
Hi I have a sliding window on my image. If the pixels within a sliding window meet certain conditions then I need to higlight this window on the image so that it can be seen were the suspicious pixels are.
I have tried the following but the window is apprearing in the wrong position. Can anyone help me please:
if average>200
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 the intensity of the 8x8 window is greater than
% 210 then considered suspicious- calculate GLCM-
if average2>210
offsets0 = [0 1];%-1 1; -1 0; -1 -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)
% display('there is mass ')%use for testing
end
end
end
end % end if>210
end %end for col1
end %end for row1
end %end if average>200
end% end for col
end %end for row
Z1 = insertShape(Z, 'rectangle', [x y 8 8]);
figure(2);
imshow(Z1);

Answers (1)

Image Analyst
Image Analyst on 1 Sep 2014
Try using plot() to plot the corners of a rectangle - use 5 vertices so the box is closed, and put "drawnow" after you call plot so you'll see it.

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!