From: Bluebird on
Hi folks,

I want to implement a sliding window to extract information from an image, my implementation is i use a for loop that is shifted by 1 pixel at the time to go over all the image and save the values in a matrix (WindowX,WindowY,NumberOfWindows).

Two problem arose, 1- it is very slow
2- as the size of the image increases, the number of extracted windows increases hene increases the matrix size and get the erro ??? Maximum variable size allowed by the program
is exceeded.

Below is my implemetation

%Moving Window
zgray=1000*rand(500,500); % Assume this the image


deltax=1; % the shifting by x in each iteration
deltay=1; % the shifting by y in each iteration
XWindowWidth=24; % The size of the moving window
YWindowWidth=24;


[ImHeight,ImWidth, ImDepth]=size(zgray);
% Here i find the number of subwindows to be extracted from the moving window from all the image
NofXsubWindoes=1+floor((ImWidth-XWindowWidth)/deltax);
NofYsubWindoes=1+floor((ImHeight-YWindowWidth)/deltay);

% Prealocating the the resultant sliding window
Temp24x24Imgae=(zeros(24,24,NofYsubWindoes*NofXsubWindoes));
TempCounter=1;

for y=1:NofYsubWindoes
for x=1:NofXsubWindoes
Temp24x24Imgae(:,:,TempCounter)=zgray((deltay*(y-1)+1):deltay*(y-1) +...
YWindowWidth,(deltax*(x-1)+1):deltax*(x-1)+XWindowWidth);
TempCounter=TempCounter+1;
end

end

Any suggestion ?
From: Bluebird on
Can reshape be used in this case? i amunable to figureout how to do this other than the 2 for loops above.

Thank you
From: Matt J on
"Bluebird " <wlouis(a)ryerson.ca> wrote in message <hn8trt$9cq$1(a)fred.mathworks.com>...
> Hi folks,
>
> I want to implement a sliding window to extract information from an image, my implementation is i use a for loop that is shifted by 1 pixel at the time to go over all the image and save the values in a matrix (WindowX,WindowY,NumberOfWindows).
>
> Two problem arose, 1- it is very slow
> 2- as the size of the image increases, the number of extracted windows increases hene increases the matrix size and get the erro ??? Maximum variable size allowed by the program
> is exceeded.
=====================

Do you really need to save all of the windows? Why not just save the results of processing each one, e.g., using blockproc() in conjunction with circshift() ?
From: Bluebird on
"Matt J " <mattjacREMOVE(a)THISieee.spam> wrote in message <hne6ra$kpe$1(a)fred.mathworks.com>...
> "Bluebird " <wlouis(a)ryerson.ca> wrote in message <hn8trt$9cq$1(a)fred.mathworks.com>...
> > Hi folks,
> >
> > I want to implement a sliding window to extract information from an image, my implementation is i use a for loop that is shifted by 1 pixel at the time to go over all the image and save the values in a matrix (WindowX,WindowY,NumberOfWindows).
> >
> > Two problem arose, 1- it is very slow
> > 2- as the size of the image increases, the number of extracted windows increases hene increases the matrix size and get the erro ??? Maximum variable size allowed by the program
> > is exceeded.
> =====================
>
> Do you really need to save all of the windows? Why not just save the results of processing each one, e.g., using blockproc() in conjunction with circshift() ?


Thank you Matt... No i dont really need to save them, the reason why i am saving them is to know the position of the block processed. For example if the window 50 has value 'x' then i know location of x in the actual image as it correspond to window 50. I hope this is clear.

Can you kindly please advice me on how to use blockproc in conjuction with circ function.

Thank you for your help
From: Matt J on
"Bluebird " <wlouis(a)ryerson.ca> wrote in message <hne83a$enh$1(a)fred.mathworks.com>...

> Can you kindly please advice me on how to use blockproc in conjuction with circ function.
===========

You'll probably have to rely mainly on the help doc for blockproc and circshift.

Basically, blockproc will tile the image into disjoint, non-overlapping windows and apply a function specified by you to each window. Since you want overlapping windows, you will have to run blockproc several times on shifted versions of the image. circshift is one possible way of performing the shift.