20121ee114_1_CA4_sol - UCLA Electrical Engineering Department EE114 Part 2 Image Processing Solutions to Computer assignment#4 Winter Quarter 2012 1

20121ee114_1_CA4_sol - UCLA Electrical Engineering...

This preview shows page 1 - 4 out of 4 pages.

UCLA, Electrical Engineering Department Winter Quarter 2012 EE114, Part 2: Image Processing Solutions to Computer assignment #4 1. m_files We need to write a couple of m_files. GenerateGaussian.m function h = GenerateGaussian (size, lambda) % this function generates a Gaussian matrix % generate the meshgrid and the Gaussian matrix [x,y]= meshgrid([- size / 2 : 1 : size / 2]); h = exp( - (x .* x + y .*y) / lambda); % find the sum and normalize the matrix sum_total = sum(sum(h)); h = h ./ sum_total; return; ConvolveImages.m function out = ConvolveImages (image, h) % this function convolves two images and % crop the result to the size of the first one % get the dimensions of the input images [y_i, x_i] = size(image); [y_h, x_h] = size (h); % convolve the images out = uint8(conv2(image, h)); %crop it to the correct size out = imcrop(out, [(x_h + 1)/ 2, (y_h + 1) / 2, x_i – 1, y_i – 1]); return;
Image of page 1