Thread Subject: Sliding window implementation and exceer variable size

Subject: Sliding window implementation and exceer variable size

From: Bluebird

Date: 10 Mar, 2010 20:02:05

Message: 1 of 6

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 ?

Subject: Sliding window implementation and exceer variable size

From: Bluebird

Date: 12 Mar, 2010 19:54:08

Message: 2 of 6

Can reshape be used in this case? i amunable to figureout how to do this other than the 2 for loops above.

Thank you

Subject: Sliding window implementation and exceer variable size

From: Matt J

Date: 12 Mar, 2010 20:06:03

Message: 3 of 6

"Bluebird " <wlouis@ryerson.ca> wrote in message <hn8trt$9cq$1@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() ?

Subject: Sliding window implementation and exceer variable size

From: Bluebird

Date: 12 Mar, 2010 20:27:22

Message: 4 of 6

"Matt J " <mattjacREMOVE@THISieee.spam> wrote in message <hne6ra$kpe$1@fred.mathworks.com>...
> "Bluebird " <wlouis@ryerson.ca> wrote in message <hn8trt$9cq$1@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

Subject: Sliding window implementation and exceer variable size

From: Matt J

Date: 12 Mar, 2010 20:45:24

Message: 5 of 6

"Bluebird " <wlouis@ryerson.ca> wrote in message <hne83a$enh$1@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.

Subject: Sliding window implementation and exceer variable size

From: Bluebird

Date: 12 Mar, 2010 20:55:11

Message: 6 of 6

Thank you very much Matt...

I will give it a shot..

Thank you again

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
for loop Louis 10 Mar, 2010 15:04:08
sliding window Louis 10 Mar, 2010 15:04:08
variable size e... Louis 10 Mar, 2010 15:04:08
rssFeed for this Thread

Contact us at files@mathworks.com