% CS143, Intro to Computer Vision, Michael Black % Matlab code from the Sept 17 class % Goal: illustrate image smoothing with a Gaussian % read in and display the peppers image cd c:\black\Teaching\cs143.03\data\ im=double(imread('peppers256.tif')); figure(1); imagesc(im); colormap gray axis off axis image % add random noise to the image nim=im+20*(rand(size(im))-0.5); figure(2); imagesc(nim); colormap gray axis off axis image % look at the difference between the original and % noisy images. Note that there is no structure to % the noise (it is independent and identically distributed). figure(3); colormap gray; imagesc(nim-im); % Construct a really big Gaussian filter with large variance. figure(4); G=fspecial('gaussian',15,2.5) surf(G) % Construct a 3X3 Gaussian G=fspecial('gaussian',5,1) surf(G) % convolve an image with the filter we created cim=conv2(nim,G,'same'); imagesc(cim) cim2 = imfilter(nim,G,'symmetric','conv'); % look at the difference between the convolved image % and the original % Notice that in addition to reducing the noise, % it is no longer unstructured. By applying this % isotropic filter, we smoothed the edges and these % now appear in the "noise". imagesc(im-cim2) colormap gray % look at the difference from the noisy image. imagesc(nim-cim)