% Problem 2 clear all % Use meshgrid as previously to get a grid of points in x-y space x = linspace(-1,1,101)'; y = x; [X Y] = meshgrid(x,y); % Each row of this matrix hold the different combinations of sigma1 sigma2 % andrho we want to evaluate sigrho = [0.5 0.5 0 ; .5 .25 0 ; .5 .5 -0.5 ; .5 .5 0.5 ; .5 .25 0.5]; figure(1);clf % Loop over all values of s1, s2, and rho for idx = 1:size(sigrho,1) % The sig1, sig2, and rho paramaters for this iteration s1 = sigrho(idx,1); s2 = sigrho(idx,2); rho = sigrho(idx,3); % Build the Gaussian h_tmp = exp(-(0.5/(1-rho*rho))*( ... (X/s1).^2 + (Y/s2).^2 - (2.*X.*Y*rho/(s1*s2)) )); % Normalize it so the area = 1 h_tmp = h_tmp/sum(sum(h_tmp)); g(:,:,idx) = h_tmp; % Plot subplot(3,2,idx);imagesc(x,y,g(:,:,idx));axis square title(['\sigma_1 = ',num2str(s1),' \sigma_2 = ',num2str(s2),' \rho = ',num2str(rho)]); end % McAndrew Problem 5.6 clear; figure(1);clf;colormap(gray) % Get the image as requested in the text load('mandrill.mat'); m = im2uint8(ind2gray(X,map));5 % The four sizes of averagers we are going to use a_size = [3 7 11 17]; % Loop over all sizes for idx = 1:length(a_size) % Use fspecial to get the filters h = fspecial('average',[a_size(idx) a_size(idx)]); % Do the filtering m_filt = filter2(h,m,'same'); % Plot subplot(2,2,idx);imshow(uint8(fix(m_filt))); title(['Filter size = ',num2str(a_size(idx))]); end print -djpeg ps02p5p6.jpg % McAndrew Problem 5.7 % Same sequence of steps as in part 5.6 clear; figure(1);clf;colormap(gray) load('mandrill.mat'); m = im2uint8(ind2gray(X,map)); g_params = [... 3 .5 ; 3 1 ; 3 2; ... 7 1 ; 7 3 ; 7 6; ... 11 1 ; 11 4 ; 11 8; ... 21 1 ; 21 5 ; 21 10]; for idx = 1:size(g_params,1) h = fspecial('gaussian',g_params(idx,1),g_params(idx,2)); m_filt = filter2(h,m,'same'); subplot(4,3,idx);imshow(uint8(fix(m_filt))); title(['Size = ',num2str(g_params(idx,1)),' Std. dev. = ', num2str(idx,2)]); end print -djpeg ps02p5p7.jpg