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