├── NLMeans2 ├── MAE.m ├── MSE.m ├── start2.m ├── NLmeans.m ├── NLmeans2.m ├── dog256.bmp ├── edge0.bmp ├── edge1.bmp ├── edge2.bmp ├── lena128.bmp ├── lena256.bmp ├── lena512.bmp ├── lena64.bmp ├── result1.bmp ├── result2.bmp ├── result3.bmp ├── result4.bmp ├── result5.bmp ├── result6.bmp ├── zebra64.bmp ├── baboon512.bmp ├── barbara64.bmp ├── bridge128.bmp ├── bridge256.bmp ├── bridge64.bmp ├── couple256.bmp ├── manmade64.bmp ├── peppers64.bmp ├── sobel8_grad.m ├── start_edge.m ├── zebra128.bmp ├── zebra256.bmp ├── barbara128.bmp ├── barbara256.bmp ├── barbara512.bmp ├── cameraman256.bmp ├── goldhill512.bmp ├── manmade128.bmp ├── manmade256.bmp ├── peppers128.bmp ├── peppers256.bmp ├── peppers512.bmp ├── PSNR.m ├── SNR.m └── ssim_index.m └── README.md /NLMeans2/MAE.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkh178/an-improved-NLM-image-denoising-algorithm-based-on-edge-detection/HEAD/NLMeans2/MAE.m -------------------------------------------------------------------------------- /NLMeans2/MSE.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkh178/an-improved-NLM-image-denoising-algorithm-based-on-edge-detection/HEAD/NLMeans2/MSE.m -------------------------------------------------------------------------------- /NLMeans2/start2.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkh178/an-improved-NLM-image-denoising-algorithm-based-on-edge-detection/HEAD/NLMeans2/start2.m -------------------------------------------------------------------------------- /NLMeans2/NLmeans.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkh178/an-improved-NLM-image-denoising-algorithm-based-on-edge-detection/HEAD/NLMeans2/NLmeans.m -------------------------------------------------------------------------------- /NLMeans2/NLmeans2.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkh178/an-improved-NLM-image-denoising-algorithm-based-on-edge-detection/HEAD/NLMeans2/NLmeans2.m -------------------------------------------------------------------------------- /NLMeans2/dog256.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkh178/an-improved-NLM-image-denoising-algorithm-based-on-edge-detection/HEAD/NLMeans2/dog256.bmp -------------------------------------------------------------------------------- /NLMeans2/edge0.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkh178/an-improved-NLM-image-denoising-algorithm-based-on-edge-detection/HEAD/NLMeans2/edge0.bmp -------------------------------------------------------------------------------- /NLMeans2/edge1.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkh178/an-improved-NLM-image-denoising-algorithm-based-on-edge-detection/HEAD/NLMeans2/edge1.bmp -------------------------------------------------------------------------------- /NLMeans2/edge2.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkh178/an-improved-NLM-image-denoising-algorithm-based-on-edge-detection/HEAD/NLMeans2/edge2.bmp -------------------------------------------------------------------------------- /NLMeans2/lena128.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkh178/an-improved-NLM-image-denoising-algorithm-based-on-edge-detection/HEAD/NLMeans2/lena128.bmp -------------------------------------------------------------------------------- /NLMeans2/lena256.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkh178/an-improved-NLM-image-denoising-algorithm-based-on-edge-detection/HEAD/NLMeans2/lena256.bmp -------------------------------------------------------------------------------- /NLMeans2/lena512.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkh178/an-improved-NLM-image-denoising-algorithm-based-on-edge-detection/HEAD/NLMeans2/lena512.bmp -------------------------------------------------------------------------------- /NLMeans2/lena64.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkh178/an-improved-NLM-image-denoising-algorithm-based-on-edge-detection/HEAD/NLMeans2/lena64.bmp -------------------------------------------------------------------------------- /NLMeans2/result1.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkh178/an-improved-NLM-image-denoising-algorithm-based-on-edge-detection/HEAD/NLMeans2/result1.bmp -------------------------------------------------------------------------------- /NLMeans2/result2.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkh178/an-improved-NLM-image-denoising-algorithm-based-on-edge-detection/HEAD/NLMeans2/result2.bmp -------------------------------------------------------------------------------- /NLMeans2/result3.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkh178/an-improved-NLM-image-denoising-algorithm-based-on-edge-detection/HEAD/NLMeans2/result3.bmp -------------------------------------------------------------------------------- /NLMeans2/result4.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkh178/an-improved-NLM-image-denoising-algorithm-based-on-edge-detection/HEAD/NLMeans2/result4.bmp -------------------------------------------------------------------------------- /NLMeans2/result5.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkh178/an-improved-NLM-image-denoising-algorithm-based-on-edge-detection/HEAD/NLMeans2/result5.bmp -------------------------------------------------------------------------------- /NLMeans2/result6.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkh178/an-improved-NLM-image-denoising-algorithm-based-on-edge-detection/HEAD/NLMeans2/result6.bmp -------------------------------------------------------------------------------- /NLMeans2/zebra64.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkh178/an-improved-NLM-image-denoising-algorithm-based-on-edge-detection/HEAD/NLMeans2/zebra64.bmp -------------------------------------------------------------------------------- /NLMeans2/baboon512.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkh178/an-improved-NLM-image-denoising-algorithm-based-on-edge-detection/HEAD/NLMeans2/baboon512.bmp -------------------------------------------------------------------------------- /NLMeans2/barbara64.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkh178/an-improved-NLM-image-denoising-algorithm-based-on-edge-detection/HEAD/NLMeans2/barbara64.bmp -------------------------------------------------------------------------------- /NLMeans2/bridge128.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkh178/an-improved-NLM-image-denoising-algorithm-based-on-edge-detection/HEAD/NLMeans2/bridge128.bmp -------------------------------------------------------------------------------- /NLMeans2/bridge256.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkh178/an-improved-NLM-image-denoising-algorithm-based-on-edge-detection/HEAD/NLMeans2/bridge256.bmp -------------------------------------------------------------------------------- /NLMeans2/bridge64.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkh178/an-improved-NLM-image-denoising-algorithm-based-on-edge-detection/HEAD/NLMeans2/bridge64.bmp -------------------------------------------------------------------------------- /NLMeans2/couple256.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkh178/an-improved-NLM-image-denoising-algorithm-based-on-edge-detection/HEAD/NLMeans2/couple256.bmp -------------------------------------------------------------------------------- /NLMeans2/manmade64.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkh178/an-improved-NLM-image-denoising-algorithm-based-on-edge-detection/HEAD/NLMeans2/manmade64.bmp -------------------------------------------------------------------------------- /NLMeans2/peppers64.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkh178/an-improved-NLM-image-denoising-algorithm-based-on-edge-detection/HEAD/NLMeans2/peppers64.bmp -------------------------------------------------------------------------------- /NLMeans2/sobel8_grad.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkh178/an-improved-NLM-image-denoising-algorithm-based-on-edge-detection/HEAD/NLMeans2/sobel8_grad.m -------------------------------------------------------------------------------- /NLMeans2/start_edge.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkh178/an-improved-NLM-image-denoising-algorithm-based-on-edge-detection/HEAD/NLMeans2/start_edge.m -------------------------------------------------------------------------------- /NLMeans2/zebra128.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkh178/an-improved-NLM-image-denoising-algorithm-based-on-edge-detection/HEAD/NLMeans2/zebra128.bmp -------------------------------------------------------------------------------- /NLMeans2/zebra256.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkh178/an-improved-NLM-image-denoising-algorithm-based-on-edge-detection/HEAD/NLMeans2/zebra256.bmp -------------------------------------------------------------------------------- /NLMeans2/barbara128.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkh178/an-improved-NLM-image-denoising-algorithm-based-on-edge-detection/HEAD/NLMeans2/barbara128.bmp -------------------------------------------------------------------------------- /NLMeans2/barbara256.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkh178/an-improved-NLM-image-denoising-algorithm-based-on-edge-detection/HEAD/NLMeans2/barbara256.bmp -------------------------------------------------------------------------------- /NLMeans2/barbara512.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkh178/an-improved-NLM-image-denoising-algorithm-based-on-edge-detection/HEAD/NLMeans2/barbara512.bmp -------------------------------------------------------------------------------- /NLMeans2/cameraman256.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkh178/an-improved-NLM-image-denoising-algorithm-based-on-edge-detection/HEAD/NLMeans2/cameraman256.bmp -------------------------------------------------------------------------------- /NLMeans2/goldhill512.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkh178/an-improved-NLM-image-denoising-algorithm-based-on-edge-detection/HEAD/NLMeans2/goldhill512.bmp -------------------------------------------------------------------------------- /NLMeans2/manmade128.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkh178/an-improved-NLM-image-denoising-algorithm-based-on-edge-detection/HEAD/NLMeans2/manmade128.bmp -------------------------------------------------------------------------------- /NLMeans2/manmade256.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkh178/an-improved-NLM-image-denoising-algorithm-based-on-edge-detection/HEAD/NLMeans2/manmade256.bmp -------------------------------------------------------------------------------- /NLMeans2/peppers128.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkh178/an-improved-NLM-image-denoising-algorithm-based-on-edge-detection/HEAD/NLMeans2/peppers128.bmp -------------------------------------------------------------------------------- /NLMeans2/peppers256.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkh178/an-improved-NLM-image-denoising-algorithm-based-on-edge-detection/HEAD/NLMeans2/peppers256.bmp -------------------------------------------------------------------------------- /NLMeans2/peppers512.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkh178/an-improved-NLM-image-denoising-algorithm-based-on-edge-detection/HEAD/NLMeans2/peppers512.bmp -------------------------------------------------------------------------------- /NLMeans2/PSNR.m: -------------------------------------------------------------------------------- 1 | %PSNR 2 | function S=PSNR(Im_original,Im_modified) 3 | 4 | if (size(Im_original)~=size(Im_modified)) 5 | error ('error:image sizes do not agree') 6 | end 7 | 8 | 9 | [m,n]=size(Im_original); 10 | A=double(Im_original); 11 | B=double(Im_modified); 12 | sumaDif=0; 13 | maxI=m*n*max(max(A.^2)); 14 | for u=1:m 15 | for v=1:n 16 | sumaDif=sumaDif+(A(u,v)-B(u,v))^2; 17 | end 18 | end 19 | if (sumaDif==0) 20 | sumaDif=1; 21 | end 22 | S=maxI/sumaDif; 23 | S=10*log10(S); 24 | -------------------------------------------------------------------------------- /NLMeans2/SNR.m: -------------------------------------------------------------------------------- 1 | %SNR 2 | function Sn=SNR(Im_original,Im_modified) 3 | 4 | if (size(Im_original)~=size(Im_modified)) 5 | error ('error:image sizes do not agree') 6 | end 7 | 8 | else 9 | A=double(Im_original); 10 | B=double(Im_modified); 11 | end 12 | 13 | [m,n]=size(A); 14 | sumaI=0; 15 | sumaDif=0; 16 | for u=1:m 17 | for v=1:n 18 | sumaI=sumaI+A(u,v)^2; 19 | sumaDif=sumaDif+(A(u,v)-B(u,v))^2; 20 | end 21 | end 22 | 23 | if (sumaDif==0) 24 | sumaDif=1; 25 | end 26 | 27 | Sn=sumaI/sumaDif; 28 | Sn=10*log10(Sn); -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # An improved NLM image denoising algorithm based on edge detection 2 | Aiming at the removal of gaussian noise, we systematically analyze the shortage of non-local means image denonising algorithm (NLM), finding it is easy to lose structure information when dealing with the image containing complex edges and textures by NLM algorithm. In order to solve this problem, a non-local means image denoising based on edge detection is proposed in this thesis. The innovation of the proposed algorithm is mainly manifested in the following : (1) An improved Sobel operator with eight directions is proposed to extract a more accurate edge image; (2) To make the neighborhoods with similar structure obtain more weight, not only the Euclidean distance but also the edge image are considered when the similarity of neighborhoods is measured. Many experiments demonstrate that in both subjective and objective evaluation principles the performance of the improved algorithm has a good effect, and the visual effect of the denoised image is good. 3 | -------------------------------------------------------------------------------- /NLMeans2/ssim_index.m: -------------------------------------------------------------------------------- 1 | function [mssim, ssim_map] = ssim_index(img1, img2, K, window, L) 2 | 3 | %======================================================================== 4 | %SSIM Index, Version 1.0 5 | %Copyright(c) 2003 Zhou Wang 6 | %All Rights Reserved. 7 | % 8 | %The author was with Howard Hughes Medical Institute, and Laboratory 9 | %for Computational Vision at Center for Neural Science and Courant 10 | %Institute of Mathematical Sciences, New York University, USA. He is 11 | %currently with Department of Electrical and Computer Engineering, 12 | %University of Waterloo, Canada. 13 | % 14 | %---------------------------------------------------------------------- 15 | %Permission to use, copy, or modify this software and its documentation 16 | %for educational and research purposes only and without fee is hereby 17 | %granted, provided that this copyright notice and the original authors' 18 | %names appear on all copies and supporting documentation. This program 19 | %shall not be used, rewritten, or adapted as the basis of a commercial 20 | %software or hardware product without first obtaining permission of the 21 | %authors. The authors make no representations about the suitability of 22 | %this software for any purpose. It is provided "as is" without express 23 | %or implied warranty. 24 | %---------------------------------------------------------------------- 25 | % 26 | %This is an implementation of the algorithm for calculating the 27 | %Structural SIMilarity (SSIM) index between two images. Please refer 28 | %to the following paper: 29 | % 30 | %Z. Wang, A. C. Bovik, H. R. Sheikh, and E. P. Simoncelli, "Image 31 | %quality assessment: From error measurement to structural similarity" 32 | %IEEE Transactios on Image Processing, vol. 13, no. 4, Apr. 2004. 33 | % 34 | %Kindly report any suggestions or corrections to zhouwang@ieee.org 35 | % 36 | %---------------------------------------------------------------------- 37 | % 38 | %Input : (1) img1: the first image being compared 39 | % (2) img2: the second image being compared 40 | % (3) K: constants in the SSIM index formula (see the above 41 | % reference). defualt value: K = [0.01 0.03] 42 | % (4) window: local window for statistics (see the above 43 | % reference). default widnow is Gaussian given by 44 | % window = fspecial('gaussian', 11, 1.5); 45 | % (5) L: dynamic range of the images. default: L = 255 46 | % 47 | %Output: (1) mssim: the mean SSIM index value between 2 images. 48 | % If one of the images being compared is regarded as 49 | % perfect quality, then mssim can be considered as the 50 | % quality measure of the other image. 51 | % If img1 = img2, then mssim = 1. 52 | % (2) ssim_map: the SSIM index map of the test image. The map 53 | % has a smaller size than the input images. The actual size: 54 | % size(img1) - size(window) + 1. 55 | % 56 | %Default Usage: 57 | % Given 2 test images img1 and img2, whose dynamic range is 0-255 58 | % 59 | % [mssim ssim_map] = ssim_index(img1, img2); 60 | % 61 | %Advanced Usage: 62 | % User defined parameters. For example 63 | % 64 | % K = [0.05 0.05]; 65 | % window = ones(8); 66 | % L = 100; 67 | % [mssim ssim_map] = ssim_index(img1, img2, K, window, L); 68 | % 69 | %See the results: 70 | % 71 | % mssim %Gives the mssim value 72 | % imshow(max(0, ssim_map).^4) %Shows the SSIM index map 73 | % 74 | %======================================================================== 75 | 76 | 77 | if (nargin < 2 | nargin > 5) 78 | mssim = -Inf; 79 | ssim_map = -Inf; 80 | return; 81 | end 82 | 83 | if (size(img1) ~= size(img2)) 84 | mssim = -Inf; 85 | ssim_map = -Inf; 86 | return; 87 | end 88 | 89 | [M N] = size(img1); 90 | 91 | if (nargin == 2) 92 | if ((M < 11) | (N < 11)) 93 | mssim = -Inf; 94 | ssim_map = -Inf; 95 | return 96 | end 97 | window = fspecial('gaussian', 11, 1.5); % 98 | K(1) = 0.01; % default settings 99 | K(2) = 0.03; % 100 | L = 255; % 101 | end 102 | 103 | if (nargin == 3) 104 | if ((M < 11) | (N < 11)) 105 | mssim = -Inf; 106 | ssim_map = -Inf; 107 | return 108 | end 109 | window = fspecial('gaussian', 11, 1.5); 110 | L = 255; 111 | if (length(K) == 2) 112 | if (K(1) < 0 | K(2) < 0) 113 | mssim = -Inf; 114 | ssim_map = -Inf; 115 | return; 116 | end 117 | else 118 | mssim = -Inf; 119 | ssim_map = -Inf; 120 | return; 121 | end 122 | end 123 | 124 | if (nargin == 4) 125 | [H W] = size(window); 126 | if ((H*W) < 4 | (H > M) | (W > N)) 127 | mssim = -Inf; 128 | ssim_map = -Inf; 129 | return 130 | end 131 | L = 255; 132 | if (length(K) == 2) 133 | if (K(1) < 0 | K(2) < 0) 134 | mssim = -Inf; 135 | ssim_map = -Inf; 136 | return; 137 | end 138 | else 139 | mssim = -Inf; 140 | ssim_map = -Inf; 141 | return; 142 | end 143 | end 144 | 145 | if (nargin == 5) 146 | [H W] = size(window); 147 | if ((H*W) < 4 | (H > M) | (W > N)) 148 | mssim = -Inf; 149 | ssim_map = -Inf; 150 | return 151 | end 152 | if (length(K) == 2) 153 | if (K(1) < 0 | K(2) < 0) 154 | mssim = -Inf; 155 | ssim_map = -Inf; 156 | return; 157 | end 158 | else 159 | mssim = -Inf; 160 | ssim_map = -Inf; 161 | return; 162 | end 163 | end 164 | 165 | C1 = (K(1)*L)^2; 166 | C2 = (K(2)*L)^2; 167 | window = window/sum(sum(window)); 168 | img1 = double(img1); 169 | img2 = double(img2); 170 | 171 | mu1 = filter2(window, img1, 'valid'); 172 | mu2 = filter2(window, img2, 'valid'); 173 | mu1_sq = mu1.*mu1; 174 | mu2_sq = mu2.*mu2; 175 | mu1_mu2 = mu1.*mu2; 176 | sigma1_sq = filter2(window, img1.*img1, 'valid') - mu1_sq; 177 | sigma2_sq = filter2(window, img2.*img2, 'valid') - mu2_sq; 178 | sigma12 = filter2(window, img1.*img2, 'valid') - mu1_mu2; 179 | 180 | if (C1 > 0 & C2 > 0) 181 | ssim_map = ((2*mu1_mu2 + C1).*(2*sigma12 + C2))./((mu1_sq + mu2_sq + C1).*(sigma1_sq + sigma2_sq + C2)); 182 | else 183 | numerator1 = 2*mu1_mu2 + C1; 184 | numerator2 = 2*sigma12 + C2; 185 | denominator1 = mu1_sq + mu2_sq + C1; 186 | denominator2 = sigma1_sq + sigma2_sq + C2; 187 | ssim_map = ones(size(mu1)); 188 | index = (denominator1.*denominator2 > 0); 189 | ssim_map(index) = (numerator1(index).*numerator2(index))./(denominator1(index).*denominator2(index)); 190 | index = (denominator1 ~= 0) & (denominator2 == 0); 191 | ssim_map(index) = numerator1(index)./denominator1(index); 192 | end 193 | 194 | mssim = mean2(ssim_map); 195 | 196 | return 197 | --------------------------------------------------------------------------------