UNIVERSITY OF OSLO Faculty of mathematics and natural sciences Examination in IN 106 Introduction to signal and image processing Day of examination: Wednesday 30 May - Friday 1 June 2001 Examination hours: 30 May 2001 09:00 1 June 2001 16:00 This exercise set consists of 7 pages. Appendices: None Permitted aids: Please make sure that your copy of the exercise set is complete before you attempt to answer anything. Parts of this exercise is to be performed by using programs from XITE, particularly xshow, and by using MATLAB programs. It is recommended that you do the exercise at the Department of Informatics (I), as hardware and software at this location has been prepared to solve the exercises given below. During the exam period, the studentadministration at I will arrange contact with the teachers. Do not send e-mails to the teachers. A small library of selected MATLAB functions are found in the appendix. When you work with sound data, you must use headphones. The results are to be presented in a written report, where theory, print-outs and illustrations made in MATLAB and images from xshow are included. It is an advantage if the report is made in e.g. LaTex or Word, but parts of the report that are technically dicult or very time-consuming to produce may be hand-written. The completed solution is to be handed in as a paper print-out, if no other arrangement has been agreed upon in advance. Only the written report will be judged, not home-pages, programs, les or any other material that you may have referred to in the report. The completed report in 2 identical copies is to be handed in to the student- administration at I within the given time limit, unless a postponement has been arranged with the student administration in advance. A random selection of students will in addition be subject to an oral examination, to take place on Friday 22 June 2001. If the censor and the course teachers, based on a preliminary review of the reports, feel a need to clarify doubtful cases, these will also be subject to the oral exam on June 22. Notication of the oral exam will be given on Friday 15 june 2001. The oral examination will mainly be based on points from the written report. The report should therefore be a result of your own independent eort! (Continued on page 2.) Examination in IN 106, Wednesday 30 May - Friday 1 June 2001 Exercise 1 Filtering We will work with the image format). Page 2 /hom/in106/img/blod.ti (and blod.img on XITE image This is a electron microscope image. You are going to work with data from one row of the image. Consider the samples from this row as a 1-dimensional signal. Which row you are going to use, depends on your date of birth. If your date of birth is dd.mm.yy, you should work with two rows given by x=40+dd and x=50+dd. (We study two rows because single rows may contain random variations from the main pattern. You should study both rows, but in your report you only need to include plots corresponding to one of the rows.) a) Plot the data in the given row. Explain what you see in 1D compared to the 2D image. b) Consider the lter with impulse response h = [0.0156 0.0938 0.2344 0.3125 0.234 0.0938 0.0156] Plot the absolute value of the frequency response of the lter and explain what type of lter this is. c) Filter the signal with the function toolbox). rlt in MATLAB (available from the dsprst Plot the original and ltered signal in the same plot. Plot only the data from a subsegment of length e.g. 200. You must choose the start position of the subsegment. How is the ltered signal compared to the original? d) How can you obtain a non-causal version of the ltered signal using the function? rlt Make a non-causal version of the ltered signal and plot the result together with the original for the same subsegment as above. e) Assume that you have a hardware implementation of a FIR lter with lter length 3, FILT3(x,h3) with impulse response h3 = [a b c]. How can you use this function to implement the lter with impulse response given in part a)? f ) Segmentation of the signal. The image blod.ti is an electron microscope image of blood. The bright objects are blood corpuscles and platelets. One row in the image can be considered as a signal with some interesting objects (the bright values). We are interested in identifying the transitions or edges between the objects (the bright levels) and the background. Your task is to try to nd the strongest contrasts in the signal, that is, the edges between background and blood corpuscles and platelets. Suggest a procedure for this, e.g. by combining a set of simple operations into a small algorithm in MATLAB. Test this algorithm on the 1D signal. Plot the original signal and the result after applying your algorithm. (Continued on page 3.) Examination in IN 106, Wednesday 30 May - Friday 1 June 2001 Exercise 2 Analyzing a speech signal You will now work with the speech signal a) Page 3 Read the sound signal /hom/in106/img/female.wav. female.wav using the soundsc to listen to the signal. function wavread. Use the function (Remember to use headphones!) See the MATLAB toolbox for recommendations when using sound. b) Plot the spectrogram of the signal. Explain what the spectrogram shows with respect to the sound you heard. c) The eect of the sampling frequency. When working in MATLAB, we can only study discrete signals. We cannot study the conversion from a continuous to a discrete signal (and back to a continuous again), but you will now study the eect of resampling a discrete signal with a lower sampling rate. Write a small MATLAB-function signal2 = downsamp(signal1,n) signal1. If signal1 signal2 should have N/n samples (the closest integer value). Use which selects only every n-th sample from the original signal has N samples the function to resample the sound signal such that the sampling rate is divided by two, and then divided by two again. You should thus create two new sound signals. Use e.g. the function subplot to shown the original sound signal and the two resampled signals on the same scale/in the same plot. You are not required to listen to the resampled signals now, but if you would like to listen to the resampled signal, do NOT use the MATLAB functions or sound soundsc, they do not handle dierent sampling frequencies as described in the manual. Instead, you can save the signal as a .wav-le and play it using other programs (either from a PC or by placing it on the WEB as you did in Obligatory exercise 2). d) Plot the spectrogram of the resampled signals and discuss what they show compared to the original. e) Reconstruction of the resampled signal. MATLAB cannot be used to convert the discrete signal to a continuous signal, but you will now try to reconstruct a signal with the same sampling rate as the original based on the resampled signals. Try to reconstruct the resampled signals with dierent choices of interpolation function using available MATLAB functions. Plot the reconstructed signals together with the original. When you have reconstructed the resampled signal to a signal with the same sampling rate as the original, you can listen to the signal using the soundsc function in MATLAB. How has the resampling and dierent choices of interpolation functions aected how the speech signal sounds? (Continued on page 4.) Examination in IN 106, Wednesday 30 May - Friday 1 June 2001 Exercise 3 Page 4 Images and histograms Assume that we have a 512×512 image with 256 steps in its grayscale. At the outset, the image only contains a background with a clear trend, so that the intensity increases smoothly from the left to the right hand edge of the image. Assume that we write your date of birth as ddmmyyyy, and let the background intensity increase from 100+dd at the left edge to 100+dd+63 at the right hand edge of the image. a) Explain and sketch what the histogram and the normalized histogram looks like. b) Now assume that a dark text is superimposed onto this background. The text pixels cover 1/4 of the image, and every text pixel has a gray value that is L steps lower than the local background. Which value L0 must we have for L so that it is possible to threshold the image without any error, using a global threshold? c) Sketch the normalized histogram for L ≤ L0 , and for L > L0 . Compute and indicate on the last sketch the location of the threshold that gives the smallest possible number of pixels misclassied by the thresholding. d) What does the histogram look like if we add Gaussian noise with mean value = 0 and a given variance to both text and background? e) We have decided to threshold the image and then median lter the result. But we are uncertain about which threshold is the best. Therefore, we threshold the image at all possible threshold values, median lter each binary image, and sum up the results. Discuss whether this is wise. (Continued on page 5.) Examination in IN 106, Wednesday 30 May - Friday 1 June 2001 Exercise 4 Entropy-thresholding G Assume that we have a given image with histogram Page 5 p(i), i ∈ [0, G − 1]. steps in its gray-scale, and a normalized We have seen that 1. order entropy H=− X pi log(pi ) i is a measure of information content in single pixels. Assume that we compute the entropy separately for the two parts of the histogram below and above the threshold H1 (t) = − " t X p(i) i=0 P1 (t) log p(i) P1 (t) " G−1 X p(i) p(i) log H2 (t) = − P2 (t) i=t+1 P2 (t) a) # , P1 (t) = t X t p(i) i=0 # , P2 (t) = G−1 X p(i) i=t+1 Compute and plot the function A(t) = H1 (t) + H2 (t) /hom/in106/img/lite-blod.ti (or lite-blod.img in XITE image format), and threshold the image at the gray value where A(t) has its maximum. for the image Discuss the eventual assumptions you have to make. Will histogram equalization inuence the placement of the threshold or the appearance of the binary image ? b) Compute and plot the function B(t) = min{H1 (t), H2 (t)} Does the maximum value of c) Show how the computation of Exercise 5 a) B(t) give a better threshold? H1 (t) and H2 (t) can be made more ecient. Compression and coding Implement an algorithm in MATLAB to perform the run-length transform row by row or column by column in the resulting image from one of the thresholdings in the exercise above. Assume that you start in the upper left hand corner, and that the rst pixel on top of a new column follows directly after the last pixel in the previous column (the rst pixel in a new row follows directly after the last pixel in the previous row). b) Find the average number of bytes per pixel after a row-by-row or column-bycolumn transform. c) Explain briey how to implement a Humann coding of the sequence of run lengths from the binary image. d) How would you compute the average number of bits per pixel after the Humann coding of the run lengths? (Continued on page 6.) Examination in IN 106, Wednesday 30 May - Friday 1 June 2001 Exercise 6 a) Page 6 Convolution Make a gradient operator that can estimate the gradient component x-direction in a digital image by the convolution (the symbol ∗ gx , in the here designates convolution) [1 1]T ∗ [1 1] ∗ [1 1]T ∗ [1 − 1] and a similar operator to nd the gradient component in the y direction, gy . The gradient components should be positive for edges where the intensity increases from left to right and from bottom to top in the image. Find the lter masks for the two operators. b) Does it matter in which sequence the convolutions in the expression above is performed? Explain briey. c) How can you do a simple extension of the operators above to d) Given two composite convolution operators: 1: q gx2 + gy2, where gx 5×5 or 7 × 7? is found by the operator [1 1]T ∗ [1 1] ∗ [1 1]T ∗ [1 1] ∗ [1 1]T ∗ [1 1] ∗ [1 1]T ∗ [1 − 1] and gy is found by the operator [1 1]T ∗ [1 1] ∗ [1 1]T ∗ [1 1] ∗ [1 1]T ∗ [1 1] ∗ [1 1] ∗ [−1 1]T 2: hx + hy , where hx is found by the operator [1 1]T ∗ [1 1] ∗ [1 1]T ∗ [1 − 1] ∗ [1 1]T ∗ [1 1] ∗ [1 1]T ∗ [1 − 1] and hy is found by the operator [1 1]T ∗ [1 1] ∗ [1 1] ∗ [−1 1]T ∗ [1 1]T ∗ [1 1] ∗ [1 1] ∗ [−1 1]T Which two common image processing operators do these correspond to? Discuss general advantages and disadvantages in the practical use of these operators. e) Show how you may put together elements of the operators above to form a 7×7 LoG operator, and how this ltering may be seen as a dierence between two low pass lterings. Good Luck! (Continued on page 7.) Examination in IN 106, Wednesday 30 May - Friday 1 June 2001 Page 7 MATLAB toolbox Here is a small set of useful hints and functions in MATLAB. Printing a gure: choose 'Print' on the gure menue. Choose 'Print to le' and print it using the IFI print programme if direct printing does not work. If the gure is in color and you do not have access to a color printer, you can print in greylevels on a regular printer. You can then describe what you saw on the screen compared to the paper print of the gure. Several curves on the same plot: plot(x1); hold; plot(x2); % x1 and x2 will now appear in the same plot Use hold one more time to release the plot such that your next plot is on a new gure. plot(x1(201:400)); Plot only parts of a signal Read and display a ti image: r=imread('bilde.ti'); imshow(r); bi2ti and ti2bi. rlt (available from the Conversion between TIFF and XITE image format: use Filtering: you are recommended to use the function dsprst toolbox). Local operations in 1D in MATLAB can be performed by: x2 = nllter(x,[3 1], 'max'); See MATLAB documentation or help for the function nllter. Frequency response: use the function freqz(h,1,zz); Given two set of index values t1=[1:1:100] and t2=[1:5:100] If signalinn is dened for indexes t2, you can interpolate by nyttsignal = interp1(t2,signalinn,t1,method); Try help interp1 to see dierent options for method. Plot of two signals dened for dierent indexes t1 and t2: plot(t1,signal1); plot(t2,signal2); Reading sound les on .wav format: [mysound,fs,nbits] =wavread('/hom/in106/myle.wav'); To play sound from MATLAB, we recommend that you use a SOLARIS workstation at IFI. If you use a dierent type of computer, you must make sure that you know how to play the sound. On a SOLARIS workstation, start the program gaintool from the unix prompt. Choose the option jack and plug in your headphones in the correct plug at the back of the computer. are correctly attached. soundsc(mysound); should now work if the earphones