MATLAB exercise program (Border Processing during image filtering 2)

Source: Internet
Author: User

I was so weak that I thought that boundary processing could be well handled using the method I used in the previous article, and the results were not good. I just made a comparison with the standard imfilter function. In fact, imfilter function still has some parameters that I don't use, such as 'replicate' and 'initric '. If these parameters are added, my results are far less than those of Matlab, so this time I don't need the previous method, so I can use boundary extension.

Boundary expansion adds R pixels around the source image, replaces the r pixel value with the R pixel at the far Outer side of the source image, and then filters the new image, the size of the source image is enough. Although this method is slightly higher than the previous method in terms of time and space complexity, the effect is indeed good, and the code is also very concise.

Clear all; close all; clc; r = 20; W = fspecial ('average', [2 * r + 1 2 * r1_11_1_1_img1_imread('lena.jpg '); IMG = mat2gray (IMG ); [m n] = size (IMG); imshow (IMG); imgn = zeros (m + 2 * r + 1, n + 2 * r + 1 ); imgn (R + 1: m + R, R + 1: N + R) = IMG; imgn (1: R, R + 1: N + R) = IMG (1: r, 1: N); % extended upper boundary imgn (1: m + R, N + R + 1: n + 2 * r + 1) = imgn (1: m + R, N: N + r); % extend the right boundary imgn (m + R + 1: m + 2 * r + 1, R + 1: n + 2 * r + 1) = imgn (M: m + R, R + 1: n + 2 * r + 1); % extend the lower boundary imgn (1: m + 2 * r +: R) = imgn (1: m + 2 * r + 1, R + * r); % extend the left boundary for I = R + 1: m + R for J = R + 1: N + r s = imgn (I-r: I + R, J-R: J + r ). * w; imgn (I, j) = sum (s)/sum (w); endendfigure; imshow (mat2gray (imgn (R + 1: m + R, R + 1: N + r); figure; IMG = imfilter (IMG, W, 'replicate'); imshow (mat2gray (IMG ))

The following figure shows the effect after processing. It can be seen that the black around the image in the previous article is no longer displayed. Although the last two images are somewhat different, they only use different methods to expand the border. However, using different methods to expand the border will certainly have different effects.

Source image

Filter by yourself

Directly call system function Filtering

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.