user1853871
user1853871

Reputation: 249

Highlight sliding window in matlab

I have the following code which creates a sliding window over the image Final.

I created a copy of the original image:

ZwindowedMarked=Final;

I applied the sliding image to the original image

N = 32;
 info = repmat(struct, ceil(size(Final, 1) / N), ceil(size(Final, 2) / N)); 
  for row = 1:N:size(Final, 1)%loop through each pixel in the image matrix
     for col = 1:N:size(Z, 2)
         r = (row - 1) / N + 1;
         c = (col - 1) / N + 1;

          imgWindow = Final(row:min(end,row+N-1), col:min(end,col+N-1));           
          average = mean(imgWindow(:)); 
          window(r, c).average=average;
          display(window(r, c).average);



        % if mean pixel intensity is greater than 200 then highlight the window

        if average>180  
        ZWindowedMarked  = insertShape(Z, 'rectangle', [col row 32 32]);
        end 

    end 
 end 
 figure(2);
 imshow(ZWindowedMarked)

However although there are lots of windows with average greater than 180 it is only displaying one rectangle on the image. Can anyone show me how to highlight all sliding windows with average greater than 180 on the same image??

Thanks

Upvotes: 0

Views: 183

Answers (1)

Geoff
Geoff

Reputation: 1603

From the above code, can we assume that Final, Z, and ZWindowedMarked are all initially the same image (before the iterations)? You may want to make that clear in the code and just decide on using Z or Final but not both.

What you need to do to ensure that all rectangles are drawn on the windowed image (ZWindowedMarked) and pass that marked up image to the insertShape function

 % if mean pixel average is greater than 180 then highlight the window
 if average>180  
   ZWindowedMarked  = insertShape(ZWindowedMarked, 'rectangle', [col row 32 32]);
 end 

rather than passing the original untouched Z to the above function. (Note the changes to the comments as well.)

Hope this helps!

Upvotes: 1

Related Questions