필터 지우기
필터 지우기

How does fspecial average filter deal with overlap causes by edges of an image?

조회 수: 3 (최근 30일)
I am applying an average filter using the fspecial command. I am wondering how the average filter works on images whose dimensions are not multiples of the user-specified hsize. For example if a 3x3 filter is chosen and applied to a 10x10 pixel image, how does this filter deal with the last row and column?

채택된 답변

Thorsten
Thorsten 2013년 1월 15일
The filter is always centered on the pixel to be processed. At the boundary, missing values are by default replaced by zero.
imfilter(ones(10), ones(3))
Other boundary conditions can be found at the help of imfilter, e.g., 'replicate', which takes the missing values from the nearest border pixel:
imfilter(ones(10), ones(3), 'replicate')
  댓글 수: 2
B
B 2013년 1월 15일
Ok thanks. To be clear, does the averaging include the pixels diagonal to the pixel to be processed or is it only the four pixels that share an edge with it?
Thorsten
Thorsten 2013년 1월 18일
편집: Thorsten 2013년 1월 18일
Its includes all 3 x 3 pixels. OUTPUTIMAGE = imfilter(IMAGE, FILTER) works as follows: Center the FILTER on pixel (i, j) of IMAGE. Then weight every pixel of IMAGE with the values in FILTER at corresponding positions and sum all these values. Assign the summed value to OUTPUTIMAGE(i,j). Do this for all pixels in IMAGE.
Please do not forget to accept an answer.

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

추가 답변 (2개)

David
David 2013년 1월 15일
fspecial will just define the 3x3 filter you're using and imfilter is the function that actually applies it to the image. imfilter deals with the last row and column in the same way whatever the size of the input image.
Don't think of your 10x10 image as being divided in to 3x3 subsets, because it isn't. The filter is applied to every pixel individually: pixel (1,1), then (1,2), then (1,3), and every other pixel. Think of the filter as being applied to overlapping subsets, each position shifted by one pixel.
If you have some curious artefacts at the edge, consider the boundary options (see help imfilter).

Image Analyst
Image Analyst 2013년 1월 18일
fspecial() is not a filter. It is a kernel maker, a filter maker. You then use this kernel (filter) in a function that does the actual filtering, such as imfilter(), or conv2(). There are explanations of the "boundary or edge effects" in the help for those functions. There are different ways you can choose to handle the output value when the filter window falls off the edge of the image.

Community Treasure Hunt

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

Start Hunting!

Translated by