Docsity

Interpolation and Edge Detection | Image Processing | EECS 556, Exams of Electrical and Electronics Engineering

Toggle sidebar
bg1
EECS 556, Winter 2002 Exam 2 Solutions, p. 1
1. Interpolation and edge detection.
a. See fig:
b. Cubic is best in terms of MSE, but most expensive in terms of computational
time. Based on a frequency response that is most similar to the rect function, we
did expect cubic to be best in terms of MSE. Nearest neighbor is best in terms of
computation, but is substantially worse in terms of MSE (and appearance). The
linear interpolation might be a good compromise in that it is nearly as good a
cubic, but not as computationally expensive.
c. See figs:
pf3
pf4
pf5

Partial preview of the text

Download Interpolation and Edge Detection | Image Processing | EECS 556 and more Exams Electrical and Electronics Engineering in PDF only on Docsity!

  1. Interpolation and edge detection. a. See fig:

b. Cubic is best in terms of MSE, but most expensive in terms of computational time. Based on a frequency response that is most similar to the rect function, we did expect cubic to be best in terms of MSE. Nearest neighbor is best in terms of computation, but is substantially worse in terms of MSE (and appearance). The linear interpolation might be a good compromise in that it is nearly as good a cubic, but not as computationally expensive. c. See figs:

For the edge detection, I lowered the threshold substantially to eliminate false edges in nearly all interpolation methods. I also needed to modify the edge thinning algorithm for the nearest neighbor case since it was finding very few edges – it turns out that the gradient was often maximal in pairs of identically valued point and neither was declared the edge – my modification made them both edge pixels.

In my implementation, the cubic and linear are nearly equivalent. The cubic edge is less jagged, but has some discontinuities.

d. It was quite hard to find the edge in the nearest neighbor case, but looking at that gradient maps allowed us to select the edge pixels. For the full res, NN, linear, and cubic case, I measured object width as 71, 70, 70, and 71, respectively. The

theoretical width was 320 71. 06 3

W = = (the first fraction is the width of

the short dimension of the rect, the second is the rotation correction term, the last is the conversion from continuous to discrete. For the interpolation methods tested, the cubic was most accurate for this measure.

Matlab code (main): % pubpixel edge detection [wx wy] = ndgrid([-160:159]); thet = pi/3; wwx = wxcos(thet)+wysin(thet); wwy = -wxsin(thet)+wycos(thet); X = sinc(wwx./5.2).*sinc(wwy./3.3); xmini = real(fftshift(fft2(fftshift(X(129:192,129:192))))); xfull = real(fftshift(fft2(fftshift(X))));

upfact = 5; nsx = 64upfact; nsy = 64upfact; im0 = zeros([nsx nsy]); im0(1:5:nsx,1:5:nsy) = xmini;

% nearest neigbor k1 = ones([5 5]); im1 = conv2(im0,k1,'same'); mse1 = mean((im1(:)-xfull(:)).^2); % linear k21 = [ (1:5) (4:-1:1)]/5; k2 = k21'k21; im2 = conv2(im0,k2,'same'); mse2 = mean((im2(:)-xfull(:)).^2); % cubic xx = [-1.8:.2:1.8]; k31 = (abs(xx) < 1).(1-2.5.xx.^2+1.5.abs(xx).^3) + ... (1-(abs(xx) < 1)).(2-4.abs(xx)+2.5.xx.^2-0.5.abs(xx).^3); k3 = k31'*k31; im3 = conv2(im0,k3,'same'); mse3 = mean((im3(:)-xfull(:)).^2);

% diplay figure(1) subplot(221); imagesc(xfull); colormap gray; colorbar title('Original Image'); subplot(222); imagesc(im1); colormap gray; colorbar str = sprintf('NN Interp, MSE = %.3f',mse1); title(str); subplot(223); imagesc(im2); colormap gray; colorbar str = sprintf('Linear Interp, MSE = %.3f',mse2); title(str); subplot(224); imagesc(im3); colormap gray; colorbar

better for smaller blocks. There are some blocky artifacts that could be eliminated using overlapping blocks with windowing functions. Smaller block sizes would also help.

Matlab Code: % wiener filtering problem load hw7image; [sx sy] = size(ho); % adding noise randn('seed',0); hon = ho + 10*randn([sx sy]);

% autocorrelation and noise estimates subim = hon(1:100,1:300); sigw = var(subim(:))

mho = mean(hon(:)); ho2 = hon-mho; r00 = mean(mean(ho2.^2)) r01 = mean(mean(ho2(1:end-1,:).ho2(2:end,:))) r10 = mean(mean(ho2(:,1:end-1).ho2(:,2:end))) r1 = (r10+r01)/2; sigs = r00 - sigw a = r1/sigs [nx ny] = ndgrid([-sx/2:sx/2-1],[-sy/2:sy/2-1]); r = abs(nx + i.ny); autocorrmod = sigs.(a.^r); PS = abs(fftshift(fft2(fftshift(autocorrmod))));

% derive and apply wiener filter filt = PS./(PS + sigw); fim = real(ifft2(fftshift(fftshift(fft2(ho2)).*filt))) + mho;

% work on 48x48 blocks afiltim = zeros([sx sy]); [nx ny] = ndgrid([-24:23],[-24:23]); r = abs(nx + i.ny); for bx = 1: for by = 1: subim = hon((by-1).48+[1:48],(bx-1).48+[1:48]); % do filtering here mho = mean(subim(:)); ho2 = subim-mho; r00 = mean(mean(ho2.^2)); r01 = mean(mean(ho2(1:end-1,:).ho2(2:end,:))); r10 = mean(mean(ho2(:,1:end-1).ho2(:,2:end))); r1 = (r10+r01)/2; sigs = r00 - sigw; a = r1/sigs; autocorrmod = sigs.(a.^r); PS = abs(fftshift(fft2(fftshift(autocorrmod)))); filt = PS./(PS + sigw); subimfilt = real(ifft2(fftshift(fftshift(fft2(ho2)).filt))) + mho; afiltim((by-1).48+[1:48],(bx-1).*48+[1:48]) = subimfilt; end end

% determine MSE's msen = mean((ho(:)-hon(:)).^2); msefilt = mean((ho(:)-fim(:)).^2); msea = mean((ho(:)-afiltim(:)).^2);

subplot(221); imagesc(ho); colormap gray; axis('image'); title('original image') subplot(222); imagesc(hon); colormap gray; axis('image'); str = sprintf('Noisy Image, MSE = %.1f',msen); title(str); subplot(223); imagesc(fim); colormap gray; axis('image'); str = sprintf('LSI Wiener Filter, MSE = %.1f',msefilt); title(str); subplot(224); imagesc(afiltim); colormap gray; axis('image'); str = sprintf('Block Adaptive Wiener Filter, MSE = %.1f',msea); title(str);

  1. Noise and deblurring. In order to derive an L.S.I. filter, we must assume that the input image, f , is WSS with autocorrelation and power spectrum: R (^) f ( n , m ) and P (^) f ( ω (^) x , ωy ), respectively. For convenience, we will also assume zero-mean. For the solutions below, we will simplify the problem by pulling the w to the other side of the blurring kernel:

where unm wnm bnm vn m

f nm bnm unm

gnm f nm bnm wnm bnm vnm

a. Using the deblurring-Wiener formulation that we derived in class

2

f x y x y u x y

f x y x y x y P B P

P B

H

ω ω ω ω ω ω

ω ω ω ω ω ω

where B ( ω x , ωy )= F { b ( n , m )}and 2

2 2 Pu ( ω (^) x , ωy )= σwB ( ωx , ωy ) + σv , so

(^2222)

f x y x y w x y v

f x y x y x y P B B

P B

H

ω ω ω ω σ ω ω σ

ω ω ω ω ω ω