|
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 ?
|