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?
0 个评论
采纳的回答
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 个评论
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
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).
0 个评论
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.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!