Professional Documents
Culture Documents
Summer Semester 2013 Prof. Bernt Schiele, Dr. Mario Fritz <{schiele,mfritz}@mpi-inf.mpg.de> Dr. Fabio Galasso, Siyu Tang <{galasso,tang}@mpi-inf-mpg.de>
graf_gray=rgb2gray(graf) close all; image(graf_gray); imagesc(graf_gray); imshow(graf_gray); c) Look at the colormap. Create and set a new colormap which varies from 1 to 0, 0 to 1, and several random maps. Display the image. Explain what happens. map=colormap; map1=map(end:-1:1,:); map2=rand(64,3); close all; image(graf_gray); colormap(map1); colormap(map2); colormap(default); colormap(gray); d) Brighten and darken the image. bgraf=graf*2; image(bgraf); dgraf=graf/2; image(dgraf); e) Assign row 200 in the image to a variable. Display it with a plot. Repeat that for column 300. row200=graf_gray(200,:); plot(row200); column300=graf_gray(:,300); plot(column300); f) Remove a rectangular region from the image and display the region. Crop a rectangular region from the image containing only the head of the karate man and display it as a new image. close all; graf1=graf; graf1(130:260,240:450, :)=0; imshow(graf1); graf2=graf(130:260,240:450,:); imshow(graf2); g) Crop the head of the chicken and rotate it by 45 degrees. Try dierent methods (nearest, bilinear, bicubic). Explain the observations. close all; subplot(1, 3, 1); graf4=imrotate(graf2,45,nearest); imshow(graf4); subplot(1, 3, 2); graf4=imrotate(graf2,45,bilinear); imshow(graf4); subplot(1, 3, 3); graf4=imrotate(graf2,45,bicubic); imshow(graf4); h) Sample the image (reduce the size). Use dierent sampling step sizes (2, 4, 8). Explain what happens. close all; subplot(1, 3, 1); graf5=graf_gray(1:2:end,1:2:end); imshow(graf5); subplot(1, 3, 2); graf5=graf_gray(1:4:end,1:4:end); imshow(graf5); subplot(1, 3, 3); graf5=graf_gray(1:8:end,1:8:end); imshow(graf5); i) Create a mirror image. Concatenate 2 or 4 images. graf6=graf_gray(:,end:-1:1); imshow(graf6);
graf7=[graf_gray,graf_gray;graf_gray,graf_gray]; imshow(graf7); j) Assign row 200 in the image to a variable. Display it with a plot. Create a lter which is a vector of 10 equal elements summing to 1. Convolve the row with the lter and plot the result. Explain what happens. row200=graf_gray(200,:); plot(row200); filt1=ones(1,10)/10; newrow=conv(double(row200), filt1); hold on; plot(newrow, r-); k) Create a 2D blur lter of size 10 10 which sums to 1. Convolve it with the image and display the new image. Create a 1D lter of size 10 which sums to 1. Convolve it with the lines of the image. Transpose the lter and convolve it with rows of the ltered image. Explain what happens. filtersize=10; filt2D=ones(filtersize,filtersize)/(filtersize*filtersize); graf8=conv2(double(graf_gray),filt2D); imagesc(graf8); filt1D=ones(1,filtersize)/filtersize; graf9=conv2(double(graf_gray),filt1D); graf10=conv2(graf9,filt1D); imagesc(graf10); max(max(graf10 - graf8)) l) Create a function called basicimproc which takes as arguments an image inimg and ve numbers x, y, the size of a square, rotationangle and filtersize. The function should crop a square region out of the image, rotate it by the desired angle, blur the cropped region, and then return it as outimg. It should also display the intermediate result images. Create a new le called basicimproc.m with your preferred editor and begin the script: function outimg=basicimproc(inimg, x, y, size, rotationangle, filtersize) ... ... end
where is the standard deviation and x is a vector of integer values. Open the le gauss.m with your preferred editor and begin the script: function G=gauss(sigma) ... ... end b) Implement a 2D Gaussian lter in gaussianfilter.m. The function should take an image as an input and return the result of convolution of this image with 2D Gaussian kernel. See Fig. 1 for illustration of Gaussian ltering. Width and height of the lter should be 2 (3 sigma) + 1. You can take advantage of the Matlabs conv2 function if you dont want to implement convolution yourself. Open the le called gaussianfilter.m with your preferred editor and begin the script: function outimg=gaussianfilter(inimg,sigma) ... ... end
(a)
(b)
Figure 1: (a) Original image (b) Image after applying a Gaussian lter with = 4.0. Hint: use the fact that 2D Gaussian lter is separable to speed up computations. c) Implement a function gaussdx.m for creating a Gaussian derivative lter in 1D according to the following equation d G = dx = x2 d 1 exp( 2 ) dx 2 2 1 x2 x exp( 2 ) 2 2 3
(2) (3)
The eect of applying a lter can be studied by observing its so-called impulse response. For this, create a test image in which only the central pixel has a non-zero value: imgImp = zeros(25,25); imgImp(13,13) = 1.0; Now, create the following 1D lter kernels G and D. sigma = 6.0; G = gauss(sigma); D = gaussdx(sigma); What happens when you apply the following lter combinations? (For best visualization, display the result image with the imagesc command). 1. 2. 3. 4. 5. rst rst rst rst rst G, then G. G, then D. D, then G. G, then D. D, then G.
d) Use the functions gauss and gaussdx in order to implement a function gaussderiv that returns the 2D Gaussian derivatives of an input image in x and y direction. Try the function on the given example images. Please turn in your solution by sending an email to Fabio Galasso <galasso@ mpi-inf. mpg. de> including all relevant m-les before Wednesday, May 1st, 23:59.