1
votes

Hi I have code which puts a sliding window over an image in Matlab. If the pixels within the sliding window meet certain conditions then I need to highlight that sliding window on the original image by putting a rectangle around it.

Can anyone explain to me how to do this?

Thanks.

 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(:)); %calculate mean intensity of pixels
                 window2(x,y).average=average2;
                % display(window2(x,y).average);


                % if the intensity of the 8x8 window is greater than
                % 210 then considered suspicious-
                 if average2>210
                 %%%% THEN HIGHLIGH THIS WINDOW ON THE ORG IMAGE (Z)
                 end 
             end
         end
1

1 Answers

0
votes

If you want to display this in a figure, you can use the imrect function. If you want to draw the rectangle into the image itself, and you have the Computer Vision System Toolbox, you can use insertShape or insertObjectAnnotation functions.