% PROBLEM 5.3 % =========== % Load the image imbase = ['../text/images/']; gs = imread([imbase,'cameraman.tif']); % Grayscale A = double(gs); % Speciay the different filters Ha = [-1 -1 0 ; -1 0 1 ; 0 1 1]; Hb = [0 -1 -1 ; 1 0 -1 ; 1 1 0]; Hc = [-1 -1 -1 ; 2 2 2 ; -1 -1 -1]; Hd = [-1 2 -1 ; -1 2 -1 ; -1 2 -1]; He = [-1 -1 -1 ; -1 8 -1 ; -1 -1 -1]; Hf = [1 1 1 ; 1 1 1 ; 1 1 1]; Hg = [-1 0 1 ; -1 0 1 ; -1 0 1]; Hh = [0 -1 0 ; -1 4 -1 ; 0 -1 0]; % Do the filtering Ya = filter2(Ha,A); Yb = filter2(Hb,A); Yc = filter2(Hc,A); Yd = filter2(Hd,A); Ye = filter2(He,A); Yf = filter2(Hf,A); Yg = filter2(Hg,A); Yh = filter2(Hh,A); % Plot the results figure(1);clf;colormap gray subplot(331);imagesc(A);title('Original image'); colorbar subplot(332);imagesc(Ya);title('Filter a: 45 degree edges'); colorbar subplot(333);imagesc(Yb);title('Filter b: -45 degree edges'); colorbar subplot(334);imagesc(Yc);title('Filter c: Horizontal edges'); colorbar subplot(335);imagesc(Yd);title('Filter d: Vertical edges'); colorbar subplot(336);imagesc(Ye);title('Filter e: Laplacian'); colorbar subplot(337);imagesc(Yf);title('Filter f: Smoothing'); colorbar subplot(338);imagesc(Yg);title('Filter g Vertical edges'); colorbar subplot(339);imagesc(Yh);title('Filter h: Laplacian'); colorbar print -djpeg p5p3.jpg clear all % PROBLEM 5.10 % ============ imbase = ['../text/images/']; % Cameraman image gs = imread([imbase,'cameraman.tif']); % Grayscale A = double(gs); % Mandrill image load('mandrill.mat'); B = im2uint8(ind2gray(X,map)); figure(1);clf;colormap(gray); figure(2);clf;colormap(gray); alpha = linspace(0,1,9); for idx = 1:length(alpha) h = fspecial('laplacian',alpha(idx)); fa = filter2(h,A,'same'); fb = filter2(h,B,'same'); figure(1);subplot(3,3,idx); imagesc(fa);title(['Laplacian \alpha= ',num2str(alpha(idx))]) figure(2);subplot(3,3,idx); imagesc(fb);title(['Laplacian \alpha= ',num2str(alpha(idx))]) end figure(1);print -djpeg p5p10_lap_cam.jpg figure(2);print -djpeg p5p10_lap_man.jpg figure(1);clf;colormap(gray); figure(2);clf;colormap(gray); hsize = [3 7 11]; sig = [.1 1 10]; cnt = 1; for idx1 = 1:length(hsize) for idx2 = 1:length(sig) h = fspecial('log',hsize(idx1),sig(idx2)); fa = filter2(h,A,'same'); fb = filter2(h,B,'same'); figure(1);subplot(3,3,cnt); imagesc(fa); title(['LoG size = ',num2str(hsize(idx1)),' \sigma = ',num2str(sig(idx2))]) figure(2);subplot(3,3,cnt); imagesc(fb); title(['LoG size = ',num2str(hsize(idx1)),' \sigma = ',num2str(sig(idx2))]) cnt = cnt+1; end end figure(1);print -djpeg p5p10_log_cam.jpg figure(2);print -djpeg p5p10_log_man.jpg % PROBLEM 5.18 % ============ % Cameraman image gs = imread([imbase,'cameraman.tif']); % Grayscale gs = double(gs); % Do the blur b = ones(3)/9; gs1 = filter2(b,gs,'same'); % Do the unsharp mask usm = fspecial('unsharp',.9); gs2 = filter2(usm,gs1,'same'); % Plot the results figure(1);clf;colormap(gray); subplot(131);imagesc(gs(30:100,90:160));title('Original');axis square subplot(132);imagesc(gs1(30:100,90:160));title('Blurred');axis square subplot(133);imagesc(gs2(30:100,90:160));title('After unsharp masking');axis square print -djpeg p5p18.jpg