# [Scilab-users] Moving window over 2D grid

5 messages
Open this post in threaded view
|

## [Scilab-users] Moving window over 2D grid

 Hello all, I know this topic has been touched on before: Efficient calculation for a moving window   I am looking at running a moving window over a grid, incrementally shifting along rows and columns, to allow processing within a window, with output appended to a file (e.g. some mathematical function) Can the code below be adapted for such processing: // START OF CODE n = 100; m = 20; // moving window size function y=f(x) // function f can be anything but must operate on columns of input x     y = mean(x,'c');   endfunction // Initial loop solution: y = rand(1,n); y1 = zeros(1,n-m+1); for i=1:n-m+1     y1(i)=f(y(i:i-1+m)); end // Optimized solution with vectorization: [X,Y] = meshgrid(1:m,1:n-m+1); y2 = f(matrix(y(X+Y-1),n-m+1,m)); printf("difference = %g\n",norm(y1-y2')) // END OF CODE I have a grid with has nx_cols=120 and ny_rows=120, and I want to run say a 10x10 window, shifting 5 units (rows and columns for overlaps) over the whole grid and calculate within each window. I am assuming that one has to do this via indexing rows and columns respectively. Hopefully this can be clarified. Sorry if this is a very basic query! Thanks Lester -- Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html_______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
Open this post in threaded view
|

## Re: Moving window over 2D grid

 What type of function you need to evaluate at each patch? How long does it take to run with the simplest double-loop implementation? Your problem seems to have only 24 x 24 = 576 iterations ... _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
Open this post in threaded view
|

## Re: Moving window over 2D grid

 Hi Rafael, At the moment I am just looking to get a general methodology/script to test. The real data grid is more like 1500x1500 or more. The function could be anything really (e.g. z=f(x,y)), but ultimately I am looking to run a radial averaged PSD from which one can extract depth to magnetic sources (that's another story as they say!). Not sure if that is any clearer. As I say, just looking for a general structure to test, before jumping ahead. I'm guessing it needs a nested for loop for rows and columns? -- Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html_______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users