I searched the internet for only the following two articles about surface blur:
1. http://bbs.redocn.com/viewthread.php? Tid = 274838 & extra = & page = 1
2. http://blog.csdn.net/maozefa/article/details/7710321
The principle of article 1 is clear, but there is no code. The principle of article 2 is not clear. But with the code, you can see whether you can understand the assembly.
The difference between surface blur and other fuzzy models is that the entire image uses only one template matrix while the surface blur requires a template matrix for each pixel. Therefore, the amount of computing is much larger.
The template matrix is calculated as follows: w (I, j) = 1-abs (x (I, j)-X (R + 1, R + 1)/(2.5 * t ). In fact, I always feel that he gave the wrong formula in the document of AFU. The first article is correct.
Make sure that the fuzzy template has two parameters. 1. R is the template radius, so the entire template matrix has (2 * r + 1) ^ 2 pixels; 2. T is the threshold value. It is determined that different pixels in the template have different weights. W is the template matrix. X (I, j) is the selected pixel of the current template. X (R + 1, R + 1) is the middle pixel of the current template, that is, the selected pixel of the current image.
The above explanation may be confusing in the cloud, but it doesn't matter. The following code can be well understood.
Clear all; close all; clc; r = 11; % radius T = 36; % threshold W = zeros (2 * r + 1, 2 * r1_11_1_img1_imread('lena.jpg '); IMG = double (IMG); [m n] = size (IMG); imshow (mat2gray (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); % the border extension imgn (1: m + R, N + R + 1: n + 2 * r + 1) = imgn (1: m + R, N: N + r); imgn (m + R + 1: m + 2 * r + 1, R + 1: n + 2 * r + 1) = imgn (M: m + R, R + 1: n + 2 * r + 1); imgn (1: m + 2 * r + 1, 1: R) = imgn (1: m + 2 * r + 1, R + * r); for I = R + 1: m + R for J = R + 1: N + r w = 1-abs (imgn (I-r: I + R, J-R: J + r)-imgn (I, j)/(2.5 * t ); % The key here is for P = * r + 1 for q = * r + 1 if W (p, q) <= 0 w (p, q) = 0; end end S = W. * imgn (I-r: I + R, J-R: J + r); % The following is a General Weighted average imgn (I, j) = sum (s)/sum (w); endendfigure; IMG = imgn (R + 1: m + R, R + 1: N + r ); imshow (mat2gray (IMG ));
The following figure shows the processing result:
Source image
The processing result here
In Photoshop, set the radius to 11 and the threshold to 36.
The overall gray scale is slightly different, but the overall gray scale is good. It is the same to add mat2gray () in MATLAB.