├── CSCI631 Image Denoising.pdf ├── DenoiseYourOwnImageUsingWaveletShrinkage.m ├── README.txt └── WaveletShrinkageTest.m /CSCI631 Image Denoising.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dhavalc25/Image-Denoising/bffc406b292660ae0452eee0e5209a36a4e30e3d/CSCI631 Image Denoising.pdf -------------------------------------------------------------------------------- /DenoiseYourOwnImageUsingWaveletShrinkage.m: -------------------------------------------------------------------------------- 1 | % CSCI 631: Foundations of Computer Vision 2 | % 3 | % Project Title: Image Denoising using Wavelet Shrinkage 4 | % 5 | % Created by: Dhaval Chauhan (dmc8686@rit.edu) 6 | % Created by: Anuja Vane (asv1612@rit.edu) 7 | % Computer Science Department 8 | % Rochester Institute of Technology 9 | % 10 | % Created on: 23, November, 2017 11 | % 12 | % A program to denoise's a noisy input image using Wavelet Shrinkage. 13 | % NO ARTIFICIAL GAUSSIAN NOISE IS INTRODUCED IN THIS PROGRAM. 14 | % This program assumes that the input image has at least 12 Megapixel 15 | % resolution. 16 | 17 | 18 | % This function takes in path of an noisy image file, denoise's it using 19 | % Wavelet Shrinkage, and displays them. 20 | function DenoiseYourOwnImageUsingWaveletShrinkage( noisy_input_image_path ) 21 | 22 | % Read input image. ( Assumption is that input image is Color ) 23 | im = imread( noisy_input_image_path ); 24 | im_r = im(:,:,1); 25 | im_g = im(:,:,2); 26 | im_b = im(:,:,3); 27 | 28 | % Consider all 3 channels have noise in them. 29 | % ( Assumption is that input image is already noisy ) 30 | im_noise_r = im_r; 31 | im_noise_g = im_g; 32 | im_noise_b = im_b; 33 | 34 | % Combine noisy channels in 1 image. 35 | im_noise = im; 36 | im_noise(:,:,1) = im_noise_r; 37 | im_noise(:,:,2) = im_noise_g; 38 | im_noise(:,:,3) = im_noise_b; 39 | 40 | % Define a wavelet variable that uses a Bi-orthogonal wavelet with 41 | % 5 vanishing levels and 3 reconstruction levels. 42 | wavelet_name = 'bior3.5'; 43 | 44 | % Number of decomposition levels 45 | decomposition_level = 24; 46 | 47 | % Do wavelet decomposition after converting the noisy image to 48 | % Bi-orthogonal wavelet domain and get the decomposition 49 | % vector. 50 | [decomp_vector_r, S_r] = wavedec2( im_noise_r, decomposition_level, wavelet_name ); 51 | [decomp_vector_g, S_g] = wavedec2( im_noise_g, decomposition_level, wavelet_name ); 52 | [decomp_vector_b, S_b] = wavedec2( im_noise_b, decomposition_level, wavelet_name ); 53 | 54 | % Get a 2D level dependent threshold using the penalhi method. 55 | threshold_r = wthrmngr( 'dw2ddenoLVL', 'penalhi', decomp_vector_r, S_r, 9); 56 | threshold_g = wthrmngr( 'dw2ddenoLVL', 'penalhi', decomp_vector_g, S_g, 9); 57 | threshold_b = wthrmngr( 'dw2ddenoLVL', 'penalhi', decomp_vector_b, S_b, 9); 58 | 59 | % set threshold type as Soft Threshold 60 | sorh = 's'; 61 | 62 | % Get a denoised image using the above threshold of type Soft. 63 | [im_ws_r_s, CXC, LXC] = wdencmp('lvd', decomp_vector_r, S_r, ... 64 | wavelet_name, decomposition_level, threshold_r,sorh); 65 | [im_ws_g_s, CXC, LXC] = wdencmp('lvd', decomp_vector_g, S_g, ... 66 | wavelet_name, decomposition_level, threshold_g,sorh); 67 | [im_ws_b_s, CXC, LXC] = wdencmp('lvd', decomp_vector_b, S_b, ... 68 | wavelet_name, decomposition_level, threshold_b,sorh); 69 | 70 | % set threshold type as Hard Threshold 71 | sorh = 'h'; 72 | 73 | % Get a denoised image using the above threshold of type Hard. 74 | [im_ws_r_h, CXC, LXC] = wdencmp('lvd', decomp_vector_r, S_r, ... 75 | wavelet_name, decomposition_level, threshold_r,sorh); 76 | [im_ws_g_h, CXC, LXC] = wdencmp('lvd', decomp_vector_g, S_g, ... 77 | wavelet_name, decomposition_level, threshold_g,sorh); 78 | [im_ws_b_h, CXC, LXC] = wdencmp('lvd', decomp_vector_b, S_b, ... 79 | wavelet_name, decomposition_level, threshold_b,sorh); 80 | 81 | % Merge all the soft thresholded channels to 1 3D image. 82 | im_ws_s = im; 83 | im_ws_s(:,:,1) = im_ws_r_s; 84 | im_ws_s(:,:,2) = im_ws_g_s; 85 | im_ws_s(:,:,3) = im_ws_b_s; 86 | 87 | % Merge all the hard thresholded channels to 1 3D image. 88 | im_ws_h = im; 89 | im_ws_h(:,:,1) = im_ws_r_h; 90 | im_ws_h(:,:,2) = im_ws_g_h; 91 | im_ws_h(:,:,3) = im_ws_b_h; 92 | 93 | % Display original input image 94 | figure(); 95 | imshow(im); 96 | title('Original Image'); 97 | 98 | % Display image with hard threshold denoising. 99 | figure(); 100 | imshow(im_ws_h); 101 | title('Wavelet Shrinkage using a hard threshold'); 102 | 103 | % Display image with soft threshold denoising. 104 | figure(); 105 | title('Wavelet Shrinkage using a soft threshold'); 106 | imshow(im_ws_s); 107 | end 108 | 109 | -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | README file! 2 | 3 | CSCI 631: Foundations of Computer Vision 4 | 5 | Project Title: Image Denoising using Wavelet Shrinkage 6 | 7 | Created by: Dhaval Chauhan (dmc8686@rit.edu) 8 | Created by: Anuja Vane (asv1612@rit.edu) 9 | Computer Science Department 10 | Rochester Institute of Technology 11 | 12 | Created on: 08, December, 2017 13 | 14 | Instructions to use MATLAB scripts: 15 | 1) Run WaveletShrinkageTest( ); to induce noise 16 | in a clean input image and see it denoise using several denoising 17 | methods like local average, median filter and wavelet shrinkage. 18 | Needs around 2 - 3 megapixel pictures to work properly. 19 | 20 | 2) Run DenoiseYourOwnImageUsingWaveletShrinkage( ); 21 | to remove noise from your input noisy picture using Wavelet Shrinkage. 22 | Needs around 12 - 16 megapixel pictures to work properly. -------------------------------------------------------------------------------- /WaveletShrinkageTest.m: -------------------------------------------------------------------------------- 1 | % CSCI 631: Foundations of Computer Vision 2 | % 3 | % Project Title: Image Denoising using Wavelet Shrinkage 4 | % 5 | % Created by: Dhaval Chauhan (dmc8686@rit.edu) 6 | % Created by: Anuja Vane (asv1612@rit.edu) 7 | % Computer Science Department 8 | % Rochester Institute of Technology 9 | % 10 | % Created on: 21, November, 2017 11 | % 12 | % A program to see comparisons between multiple noise reduction techniques. 13 | % User will pass path of a clean image and this program will add noise to 14 | % it and then denoise it for the user to see the difference between 15 | % performance of multiple methods. 16 | 17 | 18 | % This function takes in path of an image file, checks whether its a color 19 | % image or a grayscale image, and calls a function that does wavelet 20 | % shrinkage function on the input image. 21 | function WaveletShrinkageTest( input_image_path ) 22 | 23 | % Read in the input image. 24 | im = imread( input_image_path ); 25 | 26 | % Get the dimensions of the input image. 27 | dims = size( im ); 28 | 29 | % Check if it a color or a grayscale image and call the denoise 30 | % function. 31 | if ( length(dims) > 2 ) 32 | 33 | % Call denoise method for a color image. 34 | wavelet_denoise( im, 'c' ); 35 | else 36 | 37 | % Call denoise method for a grayscale image. 38 | wavelet_denoise( im, 'g' ); 39 | end 40 | end 41 | 42 | % This function performs denoising on the input image and shows the output 43 | % results of all the denoising method. 44 | function wavelet_denoise( im , color_or_gray ) 45 | 46 | % If the image is in grayscale. 47 | if color_or_gray == 'g' 48 | 49 | % Introduce Gaussian noise with mean 0 and standard deviation 0.01 50 | im_noise = imnoise( im, 'gaussian', 0, 0.01 ); 51 | 52 | % Do median filtering on the noisy image. 53 | im_median_fltrd = medfilt2( im_noise ); 54 | 55 | % Create a Gaussian filter of size 3 and standard deviation 5. 56 | fltr = fspecial( 'gaussian', 3, 5 ); 57 | 58 | % Filter the noisy image using the gaussian filter matrix obtained 59 | % above. 60 | im_lclavg_fltrd = imfilter( im_noise, fltr, 'same', 'repl' ); 61 | 62 | % Define a wavelet variable that uses a Bi-orthogonal wavelet with 63 | % 5 vanishing levels and 3 reconstruction levels. 64 | wavelet_name = 'bior3.5'; 65 | 66 | % Number of decomposition levels 67 | decomposition_level = 5; 68 | 69 | % Do wavelet decomposition after converting the noisy image to 70 | % Bi-orthogonal wavelet domain and get the decomposition 71 | % vector. 72 | [decomp_vector, S] = wavedec2( im_noise, decomposition_level, wavelet_name ); 73 | 74 | % Get horizontal, vertical and diagonal coefficients using the 75 | % wavelet and the decomposition level 5. 76 | [H1,V1,D1] = detcoef2( 'all', decomp_vector, S, 5 ); 77 | 78 | % Get approximate coefficients from wavelet and the decomposition 79 | % of level 5. 80 | A1 = appcoef2(decomp_vector,S,'bior3.5',5); 81 | 82 | % Get image of the coefficients from level 5 decomposed image. 83 | V1img = wcodemat(V1,255,'mat',5); 84 | H1img = wcodemat(H1,255,'mat',5); 85 | D1img = wcodemat(D1,255,'mat',5); 86 | A1img = wcodemat(A1,255,'mat',5); 87 | 88 | % Display the coefficient images. 89 | figure; 90 | imagesc(V1img); 91 | figure; 92 | imagesc(H1img); 93 | figure; 94 | imagesc(D1img); 95 | figure; 96 | imagesc(A1img); 97 | figure; 98 | 99 | % Get inverse 2D DWT of level 5 decomposed image and display it. 100 | out = idwt2( A1,H1,V1,D1,'bior3.5' ); 101 | figure; 102 | imagesc(out); 103 | 104 | % Get a 2D level dependent threshold using the penalhi method. 105 | threshold1 = wthrmngr( 'dw2ddenoLVL', 'penalhi', decomp_vector, S, 5 ); 106 | 107 | % set threshold type as Soft Threshold 108 | sorh = 's'; 109 | 110 | % Get a denoised image using the above threshold of type Soft. 111 | [im_ws_s, CXC, LXC] = wdencmp( 'lvd', decomp_vector, S, ... 112 | wavelet_name, decomposition_level, threshold1, sorh ); 113 | 114 | % set threshold type as Hard Threshold 115 | sorh = 'h'; 116 | 117 | % Get a denoised image using the above threshold of type Hard. 118 | [im_ws_h, CXC, LXC] = wdencmp( 'lvd', decomp_vector, S, ... 119 | wavelet_name, decomposition_level, threshold1, sorh ); 120 | 121 | % Display original input image. 122 | figure; 123 | imshow(im); colormap gray; axis off; 124 | title('Original Image'); 125 | 126 | % Display noisy image. 127 | figure; 128 | imshow(im_noise); colormap gray; axis off; 129 | title('Noise introduced Image'); 130 | 131 | % Display local averaged image. 132 | figure; 133 | imshow(im_lclavg_fltrd); colormap gray; axis off; 134 | title('Gaussian Blur filtering'); 135 | 136 | % Display median filtered image. 137 | figure; 138 | imshow(im_median_fltrd); colormap gray; axis off; 139 | title('Median filtering'); 140 | 141 | % Display wavelet denoised using hard threshold image 142 | figure; 143 | 144 | % Convert to uint8 format. 145 | im_ws_h_norm = im_ws_h - min(im_ws_h(:)); 146 | im_ws_h_norm = im_ws_h_norm ./ max(im_ws_h_norm(:)); 147 | im_ws_h = im2uint8( im_ws_h_norm ); 148 | imshow(im_ws_h); colormap gray; axis off; 149 | title('Wavelet Shrinkage using a hard threshold'); 150 | 151 | % Display wavelet denoised using soft threshold image 152 | figure; 153 | 154 | % Convert to uint8 format. 155 | im_ws_s_norm = im_ws_s - min(im_ws_s(:)); 156 | im_ws_s_norm = im_ws_s_norm ./ max(im_ws_s_norm(:)); 157 | im_ws_s = im2uint8( im_ws_s_norm ); 158 | imshow(im_ws_s); colormap gray; axis off; 159 | title('Wavelet Shrinkage using a soft threshold'); 160 | 161 | % Show surface of noisy image. 162 | figure; 163 | mesh(im_noise); 164 | 165 | % Show surface of soft thresholded image. 166 | figure; 167 | mesh(im_ws_s); 168 | 169 | % Calculate mean square errors of the output images. 170 | im_mse_med = immse( im, im_median_fltrd ); 171 | im_mse_lclavg = immse( im, im_lclavg_fltrd ); 172 | im_mse_ws_h = immse( im, im_ws_h ); 173 | im_mse_ws_s = immse( im, im_ws_s ); 174 | 175 | % Display the MSEs in console. 176 | disp( im_mse_med );format long g; 177 | disp( im_mse_lclavg );format long g; 178 | disp( im_mse_ws_h );format long g; 179 | disp( im_mse_ws_s );format long g; 180 | 181 | % If the input image is a Color image. 182 | else 183 | 184 | % Get the Red, Green, and Blue channels. 185 | im_r = im(:,:,1); 186 | im_g = im(:,:,2); 187 | im_b = im(:,:,3); 188 | 189 | % Introduce noise in all 3 channels. 190 | im_noise_r = imnoise( im_r, 'gaussian', 0, 0.03 ); 191 | im_noise_g = imnoise( im_g, 'gaussian', 0, 0.03 ); 192 | im_noise_b = imnoise( im_b, 'gaussian', 0, 0.03 ); 193 | 194 | % Merge all 3 channels to 1 3D image matrix again. 195 | im_noise = im; 196 | im_noise(:,:,1) = im_noise_r; 197 | im_noise(:,:,2) = im_noise_g; 198 | im_noise(:,:,3) = im_noise_b; 199 | 200 | % Do median filtering on the noisy image. 201 | im_median_fltrd = im; 202 | im_median_fltrd(:,:,1) = medfilt2( im_noise_r ); 203 | im_median_fltrd(:,:,2) = medfilt2( im_noise_g ); 204 | im_median_fltrd(:,:,3) = medfilt2( im_noise_b ); 205 | 206 | % Do local averaging on the noisy image. 207 | fltr = fspecial( 'gaussian', 3, 5 ); 208 | im_lclavg_fltrd = im; 209 | im_lclavg_fltrd(:,:,1) = imfilter( im_noise_r, fltr, 'same', 'repl' ); 210 | im_lclavg_fltrd(:,:,2) = imfilter( im_noise_g, fltr, 'same', 'repl' ); 211 | im_lclavg_fltrd(:,:,3) = imfilter( im_noise_b, fltr, 'same', 'repl' ); 212 | 213 | % Define a wavelet variable that uses a Bi-orthogonal wavelet with 214 | % 5 vanishing levels and 3 reconstruction levels. 215 | wavelet_name = 'bior3.5'; 216 | 217 | % Number of decomposition levels 218 | decomposition_level = 5; 219 | 220 | % Do wavelet decomposition after converting the noisy image to 221 | % Bi-orthogonal wavelet domain and get the decomposition 222 | % vector. 223 | [decomp_vector_r, S_r] = wavedec2( im_noise_r, decomposition_level, wavelet_name ); 224 | [decomp_vector_g, S_g] = wavedec2( im_noise_g, decomposition_level, wavelet_name ); 225 | [decomp_vector_b, S_b] = wavedec2( im_noise_b, decomposition_level, wavelet_name ); 226 | 227 | % Get a 2D level dependent threshold using the penalhi method. 228 | threshold_r = wthrmngr( 'dw2ddenoLVL', 'penalhi', decomp_vector_r, S_r, 3); 229 | threshold_g = wthrmngr( 'dw2ddenoLVL', 'penalhi', decomp_vector_g, S_g, 3); 230 | threshold_b = wthrmngr( 'dw2ddenoLVL', 'penalhi', decomp_vector_b, S_b, 3); 231 | 232 | % set threshold type as Soft Threshold 233 | sorh = 's'; 234 | 235 | % Get a denoised image using the above threshold of type Soft. 236 | [im_ws_r_s, CXC, LXC] = wdencmp('lvd', decomp_vector_r, S_r, ... 237 | wavelet_name, decomposition_level, threshold_r,sorh); 238 | [im_ws_g_s, CXC, LXC] = wdencmp('lvd', decomp_vector_g, S_g, ... 239 | wavelet_name, decomposition_level, threshold_g,sorh); 240 | [im_ws_b_s, CXC, LXC] = wdencmp('lvd', decomp_vector_b, S_b, ... 241 | wavelet_name, decomposition_level, threshold_b,sorh); 242 | 243 | % set threshold type as Hard Threshold 244 | sorh = 'h'; 245 | 246 | % Get a denoised image using the above threshold of type Hard. 247 | [im_ws_r_h, CXC, LXC] = wdencmp('lvd', decomp_vector_r, S_r, ... 248 | wavelet_name, decomposition_level, threshold_r,sorh); 249 | [im_ws_g_h, CXC, LXC] = wdencmp('lvd', decomp_vector_g, S_g, ... 250 | wavelet_name, decomposition_level, threshold_g,sorh); 251 | [im_ws_b_h, CXC, LXC] = wdencmp('lvd', decomp_vector_b, S_b, ... 252 | wavelet_name, decomposition_level, threshold_b,sorh); 253 | 254 | % Merge all the soft thresholded channels to 1 3D image. 255 | im_ws_s = im; 256 | im_ws_s(:,:,1) = im_ws_r_s; 257 | im_ws_s(:,:,2) = im_ws_g_s; 258 | im_ws_s(:,:,3) = im_ws_b_s; 259 | 260 | % Merge all the hard thresholded channels to 1 3D image. 261 | im_ws_h = im; 262 | im_ws_h(:,:,1) = im_ws_r_h; 263 | im_ws_h(:,:,2) = im_ws_g_h; 264 | im_ws_h(:,:,3) = im_ws_b_h; 265 | 266 | % Display original input image 267 | figure; 268 | imshow(im); colormap gray; axis off; 269 | title('Original Image'); 270 | 271 | % Display noisy image. 272 | figure; 273 | imshow(im_noise); colormap gray; axis off; 274 | title('Noise introduced Image'); 275 | 276 | % Display Local averaged image. 277 | figure; 278 | imshow(im_lclavg_fltrd); colormap gray; axis off; 279 | title('Gaussian Blur filtering'); 280 | 281 | % Display Median filtered image. 282 | figure; 283 | imshow(im_median_fltrd); colormap gray; axis off; 284 | title('Median filtering'); 285 | 286 | % Display image with hard threshold denoising. 287 | figure; 288 | imshow(im_ws_h); colormap gray; axis off; 289 | title('Wavelet Shrinkage using a hard threshold'); 290 | 291 | % Display image with soft threshold denoising. 292 | figure; 293 | imshow(im_ws_s); colormap gray; axis off; 294 | title('Wavelet Shrinkage using a soft threshold'); 295 | end 296 | end --------------------------------------------------------------------------------