Assignment 1
Assignment 1
Assignment 1
a) Separability
Make a 2D smoothing filter of size 9 x 9 and with a standard deviation of 1.5 by sampling the
Gaussian function f(x,y).
Sample the 1D Gaussian functions f(x) and f(y) to make the 1D filters of size 1x9 and 9x1, respectively.
Verify the separable property of the Gaussian filter by computing gg=gx*gy. Use
"gg=conv2(gx,gy);" for the computation. Show the filter weights for g (2D filter) and for gg
(convolution of gx and gy). Compare the weights!
Page 1 of 4
b) Low-pass filtering (smoothing)
Load the image “blood1.tif” and filter the image by using the 2D filter g.
f=imread('blood1.tif');
f=double(f(1:256,1:256));
y=conv2(f,g,’valid’); %filter the image
subplot(2,2,1); imshow(f/255); % original image
subplot(2,2,2); imshow(y/255); % smoothed image
How many products are required when filtering the image using the 2D filter?
Now, use filter separability to filter the image by means of the two 1D filters gx and gy ((f*gx)*gy).
Control (by computing the sum of the squared differences) that you obtain the same result you
obtained when you filtered the image with the 2D filter g.
How many multiplications are used when filtering the image using the 1D filters?
Make low-pass filters gx and gy of larger sizes (1x15, 15x1, std=3) and filter the image “blood1.tif”.
Explain how the smoothing effect varies when the size of the filter is changed.
Extract the subpart of the original image and of the noisy image that also appear in the filtered
image.
Try reducing the variance of the noise to 0.001. Does filtering still help? Why?
Page 2 of 4
2. Derivative filters and the extraction of edges
The partial derivatives of the Gaussian filter G(x,y) can be used (but for a sign change) as derivative
(edge) filters in the x and y directions of the image.
-∂/∂x{G(x,y)} = −∂/∂x{G(x)} G(y)
= −∂/∂x{exp(−x2/2σ2 )} exp(−y2/2σ2)
= x/σ2 exp(−x2/2σ2 ) exp(−y2/2σ2)
= −G'(x) G(y)
By sampling the 1D Gaussian function G(x) and its derivative G'(x) and using separability, we can
construct derivative filters along the x and y directions of the image.
Filter the image “blood1.tif” in the x-direction ((f*dx)*gy) and in the y-direction ((f*dy)*gx).
Show the original image and the filtered images (x and y derivatives).
r
Compute the magnitude of the gradient: ∇I = (∂I / ∂x) 2 + (∂I / ∂y ) 2 and display the resulting
(edge-filtered) image.
Page 3 of 4
b) Edge filtering in the presence of noise
Does the fact that derivation is performed using derivatives of Gaussians help?
Page 4 of 4