MATLAB implementation of non-neighbor denoising algorithm of nlmeansfilter

Source: Internet
Author: User
Function im = nlmeansfilter (I, Nb, SW, h) % nlfilter denoise the image of I % im = nlfilter (I, Nb, SW, H) outputs the denoised image of I % I is the original image. % Nb is a number which shows the neiborhood of the point (I, j) The % neiborhood of the point (I, j) is (2 * Nb + 1) * (2 * Nb + 1) % Sw is the search window. the size of the search window is (2 * SW + % 1) * (2 * SW + 1) % H acts as the filtering parameter % create the mirror (I _extend) of image ISW = Sw + NB; [height, width] = size (I); I _extend = uint8 (zeros (2 * SW + height, 2 * SW + width )); I _extend (1: SW, 1: Sw) = I (SW:-1:1, SW:-1:1); I _extend (1: SW, SW + 1: SW + width) = I (SW:-, 1: width); I _extend (1: SW, SW + width + * SW + width) = I (SW:-, width: -1: width-SW + 1); I _extend (SW + 1: SW + height, 1: Sw) = I (1: height, SW:-1:1 ); I _extend (SW + 1: SW + height, SW + 1: SW + width) = I (:, :); I _extend (SW + 1: SW + height, SW + width + * SW + width) =... I (1: height, width:-1: width-SW + 1); I _extend (SW + height + 1: 2 * SW + height, 1: Sw) =... I (Height:-1: height-SW + 1, SW:-1:1); I _extend (SW + height + 1: 2 * SW + height, SW + 1: SW + width) =... I (Height:-1: height-SW + 1, 1: width); I _extend (SW + height + 1: 2 * SW + height, SW + width + * SW + width) =... I (Height:-1: height-SW + 1, width:-1: width-SW + 1); Im = zeros (height, width ); I _extend = double (I _extend); H = H * h; for I = Sw + 1: SW + height for J = Sw + 1: SW + width disp ([I-SW, j-SW]); Tw = 0.0; Im = 0.0; for M = I-SW + NB: I + Sw-Nb for n = J-SW + NB: J + Sw-Nb % weight calculate the weight of (X2, Y2) to (x1, Y1) % pay attention to the class type conversion uint8 to double ndif = I _extend (I-NB: I + NB, J-NB: J + Nb)-I _extend (m-NB: m + NB, N-NB: N + Nb); euclidean2 = (ndif (:) '* ndif (:); % euclidean2 = sum (ndif (:). * ndif (:)); W = exp (-euclidean2/h); % (m, n)'s weight to (I, j ); im = IM + W * I _extend (m, n); Tw = TW + W; end IM (I-SW, J-SW) = IM/TW; endendim = uint8 (IM); figure, imshow (IM );

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.