Moving average with overlapping windows

7 visualizaciones (últimos 30 días)
Pierre S.
Pierre S. el 25 de Mzo. de 2016
Editada: Image Analyst el 25 de Mzo. de 2016
Hi,
I am looking for an efficient way to compute a moving average with overlapping windows for a matrix X along the first dimension.
A non-efficient solution is the following.
N = 3500000;
X = randn(N,20);
windowSize = 600;
stepSize = 100;
b = (1/windowSize)*ones(1,windowSize);
a = 1;
windowEnd = windowSize:stepSize:N-windowSize+1;
tic
X = filter(b,a,X) ;
X = X(windowEnd) ;
toc
In this solution, I am computing a lot of averages that I am throwing away at the end... This is what I meant by 'non-efficient'.
Thank you in advance for your help.

Respuestas (1)

Image Analyst
Image Analyst el 25 de Mzo. de 2016
You can use blockproc() to move a 600x600 window along a matrix in "jumps" of 100. Look at all the arguments and let us know if you can't figure it out.
  2 comentarios
Pierre S.
Pierre S. el 25 de Mzo. de 2016
Thank you for the suggestion. I tried your suggestion. But unfortunately, blockproc() is much slower than filter()... Any other idea? Thanks again.
Image Analyst
Image Analyst el 25 de Mzo. de 2016
Editada: Image Analyst el 25 de Mzo. de 2016
You can use conv2() or imfilter(). They are very efficient and fast and highly optimized. However, they don't move in "jumps" of 100, they move by 1 pixel so they do a lot more computations. Whether it will be faster or not is for you to test.
tic;
kernel = ones(101) / 101^2;
blurredImage = conv2(X, kernel, 'same');
elapsedSeconds = toc

Iniciar sesión para comentar.

Categorías

Más información sobre Matched Filter and Ambiguity Function en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by