20091ee114_1_CA5_sol

# 20091ee114_1_CA5_sol - d = double(i1 – double(i2 d2 = d d...

This preview shows pages 1–4. Sign up to view the full content.

UCLA, Electrical Engineering Department Winter Quarter 2009 EE114, Part 2: Image Processing Solution to Computer assignment #5 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;

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
PSNR.m function psnr = PSNR (i1, i2) % calculate PSNR of two images

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: d = double(i1) – double(i2) ; d2 = d .* d; psnr = 10 * log10 (255 * 255/ mean(mean(d2))); return; 2. Results Under matlab, type image = imread(‘image.tif’); imagesc(image); colormap (gray); to load and display image. 50 100 150 200 250 300 350 400 450 500 50 100 150 200 250 300 350 400 450 500 Type h5 = GenerateGaussian(40, 5); i5 = ConvolveImages(image, h5); imagesc(i5); PSNR5 = PSNR(image, i5); to generate Gaussian matrix with λ=5, convolve image with it, display the result and calculate the PSNR against the original. PSNR5 = 25.3865 Type 50 100 150 200 250 300 350 400 450 500 50 100 150 200 250 300 350 400 450 500 h10 = GenerateGaussian(40, 10); i10 = ConvolveImages(image, h10); imagesc(i10); PSNR10 = PSNR(image, i10); to generate Gaussian matrix with λ=10, convolve image with it, display the result and calculate the PSNR against the original. PSNR10 = 23.1213 50 100 150 200 250 300 350 400 450 500 50 100 150 200 250 300 350 400 450 500...
View Full Document

{[ snackBarMessage ]}

### Page1 / 4

20091ee114_1_CA5_sol - d = double(i1 – double(i2 d2 = d d...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online