Create moving average filter

조회 수: 7 (최근 30일)
LM
LM 2011년 12월 26일
Hi, I need some help in writing a code for the moving average filter but without using any of the existing matlab functions. It's going to be applied to black and white images, 256x256 pixels, with N rows and M columns:
f(i,j), i=1,2,,N and j=1,2,,M f(i,j)=[0,255]
If the function is applied to each of the rows of the image, represented by the array:
[f1 f2 f3 fk-1 fk fk+1 fM]
And with the corresponding exit array:
[g1 g2 g3 gk-1 gk gk+1 gM]
How to solve this, in order to create the moving average filter?:
gk=(agk-1+bgk+cgk+1)/(a+b+c) for k=2,3,,M-1 and a=b=c=1
(and to make sure the length of the arrays is the same, g1= f1 e gM = fM )
Thankyou
  댓글 수: 2
bym
bym 2011년 12월 26일
"without using any of the existing matlab functions" is vague
LM
LM 2011년 12월 26일
Sorry, I mean the filter function.

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

답변 (2개)

Image Analyst
Image Analyst 2011년 12월 26일
Sounds like a class assignment. Think about it. Do you think you could do it with 4 for loops? Maybe one pair that visits every pixel in the image (iterates over rows and columns), and another pair inside that visits every pixel in your NxM window that is centered over the pixel you're visiting?
  댓글 수: 1
LM
LM 2011년 12월 26일
Yes, I wasn't sure on the structure I should use here, but thanks for your suggestion, I'll try to do it :)

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


Jan
Jan 2011년 12월 26일
The moving average can be calculated for the columns at first and the rows afterwards.
For the moving average along the rows or columns a single loop is sufficient: One vector is added to the accumulator and one vector is subtracted.
  댓글 수: 2
Walter Roberson
Walter Roberson 2011년 12월 26일
Though that does have the disadvantage of having cumulative round-off error.
Jan
Jan 2011년 12월 26일
@Walter: That's correct, but for a 256x256 pixel image this will very likely not matter. If it is a 8 bit grey scale or 8x3 bit RGB image: Using an accumulator of type DOUBLE will be sufficient - as long as the picture are small enough.

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

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by