I need to implement a one-dimensional M-point averaging filter for a matrix consisting of values (pixels of an image) between 0 and 1, such that each pixel value is replaced by the equal-weighted average of its (M 1)/2 neighbors to its left, (M 1)/2 neighbors to its right, and the pixel value itself.
For instance, for M = 3, it would be like:
y[n,m]= 1/3 (x[n,m1] + x[n,m] + x[n,m+1])
Please help me out with this. Thank you.

댓글 수: 2

Austin Thai
Austin Thai 2021년 4월 17일
편집: Austin Thai 2021년 4월 17일
Have you checked out the movmean function? You should be able to do
y[n,:]=movmean(x(n,:),3)

댓글을 달려면 로그인하십시오.

 채택된 답변

the cyclist
the cyclist 2021년 4월 17일
편집: the cyclist 2021년 4월 17일

0 개 추천

You should be able to use the movmean function. For example:
% Define some data
A = reshape(1:15,3,5);
% Take the moving average of 3 elements, across the rows.
movmean(A,3,2)
ans = 3×5
2.5000 4.0000 7.0000 10.0000 11.5000 3.5000 5.0000 8.0000 11.0000 12.5000 4.5000 6.0000 9.0000 12.0000 13.5000

추가 답변 (0개)

질문:

2021년 4월 17일

댓글:

2021년 4월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by