0
votes

Hi I have implemented a sliding window over an image in matlab using this code:

N = 32;
info = repmat(struct, ceil(size(Z, 1) / N), ceil(size(Z, 2) / N)); 
for row = 1:N:size(Z, 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 = Z(row:min(end,row+N-1), col:min(end,col+N-1));


      average = mean(imgWindow(:)); 
      window(r, c).average=average;


     % if mean pixel intensity is greater than 200 then keep the window for
     % further inspection. If not then discard the window.

     if average<200
       imgWindow=false;
     end 

  end 
end 


figure(2);
imshow(Z);

The aim of this code is to check the mean intensity within each sliding window and if the mean intensity is less than 200 then turn the pixels inside the window black.

However when I try to view the resulting image after the sliding window and travelled the whole image , I just see the orginal image again.

Can anyone please help me with this?

1

1 Answers

1
votes

The above code is missing functionality that will actually set the sliding window portion of the image to black if the window intensity is less than 200. There is the following block:

if average<200
   imgWindow=false;
 end 

but there is no corresponding line of code to set the original block in the image Z to zero.

I think what you want to do is create a copy of the original image:

ZWindowed = Z;

then continue as before, grabbing the window from Z. When the window intensity is less than 200, then do the following:

if average<200
   % zero out the data corresponding to the window
   ZWindowed(row:min(end,row+N-1), col:min(end,col+N-1)) = 0;
 end 

Then display the image less those windows whose intensity is less than 200:

imshow(ZWindowed);

The above code assumes that the image is mxn only (and so is not RGB).