[Scilab-users] Moving window over 2D grid

arctica1963 arctica1963 at gmail.com
Fri Aug 3 17:34:00 CEST 2018


Hello all,

I know this topic has been touched on before:

Efficient calculation for a moving window
<http://mailinglists.scilab.org/efficient-calculation-for-a-moving-window-td4035997.html#a4036023>  

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



More information about the users mailing list