Starting from:
$35

$29

Image and Video processing Laboratory 1 Solution

    • Installation

        1. If you have already a MathWorks account, you can skip this step. Otherwise, create a MathWorks account using your EPFL email address using the following URL: https://www.mathworks.com/mwaccount/register



















    2. Go to the following URL and ll your MathWorks account credentials: https://www.mathworks.com/downloads/web_downloads/select_release



















2
3. On the next page, additional information is required. Choose the second option:
















4. In your MathWorks account page, choose the icon for downloading.

















5. Download the MATLAB Installer (version R2019b is suggested).





















Check for potential compatibly issues with your operating system in the following URL: https://www.mathworks.com/support/requirements/platform-road-map.html.

In case the suggested version is not supported in your system, download an older version and continue with the following steps.


    6. After downloading, run the MATLAB installer on your machine.



3

    7. In the MathWorks Installer window, choose the option: Log in with a MathWorks Account and press Next.





























8. Accept the terms of the license agreement and press Next.






































4

    9. Choose the option: Log in to your MathWorks Account and enter your credentials. Then, press Next.





























10. Choose a type of license and press Next.






































5
11. Choose the installation folder and press Next.





























    12. Choose the products/packages you want to install. For the purposes of this course, the Image Processing Toolbox and the Signal Processing Toolbox are su cient. Note that you can always add additional toolboxes after the MATLAB environment is installed.
































13. Press Install and wait for the software to download.



6
14. Press Next.




























    15. Activate MATLAB. If you are asked, ll in the credentials from your MathWorks account. Additional links that might be of help:

Matlab Total Academic Head Count (TAH) License: https://soft-epfl.epfl.ch/students/matlab/tah_en.cgi

Detailed description for MATLAB installation https://www.mathworks.com/help/install/ug/install-products-with-internet-connection. html


Online MATLAB editor: https://matlab.mathworks.com/

Labview: https://www.epfl.ch/campus/services/en/it-services/it-support/pro-softwares/



    • Introduction

2.1    Images in matlab

Matlab can use three types of data to store images and four formats.

The three types of data are:

uint8 Pixel values are coded as unsigned 8 bits integers. Possible values range from 0 to 255. This format is not suitable for algebraic operations.

uint16 Pixel values are coded as unsigned 16 bits integers. Possible values range from 0 to 65535. This format is similar to the pervious one but it o ers a wider range of values. it’s rarely used.



7

double Pixel values are coded in the oating point format using 64 bits. They can therefore take all possible reel values. This format uses more memory than the previous 2 formats. It enables us to perform e ciently all algebraic operations.

The four image formats are:

indexed The image is stored in a 2D matrix containing indeces to an associated color table (colormap). For data of type uint8 and unit16 the value 0 corresponds to the rst line of the colormap, 1 to the 2nd, and so on. For data of type double the value 1.0 corresponds to the rst line of the colormap, 2 to the 2nd, and so on.

RGB or truecolor The image is stored in a 3D matrix of dimension m n 3. The 3rd dimension gives the R, G, B values of the pixel.


intensity The image is stored in a 2D matrix. Each element of the matrix corresponds to the grey level of the pixel.

binary The image is stored in a 2D matrix with binary (0 or 1) coe  cients. 0 corresponds to black and 1 corresponds to white. Only data storage in uint8 and double are possible for this format.

colormap The table of colors associated with an image. It’s a matrix of type double of m lines and 3 columns. Each line gives the R, G, B values of a color. The coe cients take values between 0.0 and 1.0.

Note: The functions double, uint8, rgb2ind, gray2ind, etc., are used to convert from one format to another.

2.2    Matlab online help

The online Matlab help is available on the web http://www.mathworks.com/access/helpdesk/help/ helpdesk.html. For each command, help gives detailed information in the Matlab terminal.

2.3    Functions and Matlab scripts

In Matlab, we can de ne functions or execute commands using a script. Use the online help for information on function and script. The commands diary, load and save might be useful too.


    • Exercises

3.1    Images and color tables

    1. read and show the following images:

trees.tif (image with indexed format) lena.tif (image with truecolor format)

    2. Show the images in gray level and invert them (i.e. show the negative). For trees.tif do this by modifying its color table.

    3. Using a function, modify the color table according to the following rule:

r0    =    r
g0    =    g
b0    =    b

8
where r; g; b are the original color values, r0; g0; b0 are the new values and    is the correction factor.

Show the modi ed images for di erent values of (typically between 0.5 and 2) and deduce the utility of the gamma correction.

    4. Create the image of a chess board (8x8) with blue and yellow squares for the 2 following formats :indexed and truecolor. Save them to the TIFF format.

Note: In this exercise, we can use the functions imread, imwrite, image, imshow, imagesc, truesize, colormap, repmat, zeros, ones, end, etc.

3.2    Image quantization

Uniform quantization3 of a sample x is de ned as Q(x) = bx= c, where is the quantization step size. The operator byc (floor) rounds y to the closest integer smaller than y itself (i.e. rounds to ). The reconstructed value is x^ = Q(x) + =2.

Apply uniform quantization to the image lena-y.png in the grey level. Adjust the quantization step to obtain successively 128, 64, 32, 16, 8, 4 and 2 gray levels. Show the images to determine the number of grey levels after which the phenomenon of "false contours" appears.

3.3    Filtering

We have the following 5    5 separable 2D    lter:

    • 3
0:0357
60:24117
6    7
60:44647 0:0357  0:2411  0:4464  0:2411  0:0357 =
    • 7
40:24115
0:0357

2
0:00127449
0:00860727
0:01593648
0:00860727
0:00127449
3

0:00860727
0:05812921
0:10762704
0:05812921
0:00860727

6
0:01593648
0:10762704
0:19927296
0:10762704
0:01593648
7
6





7

0:00860727
0:05812921
0:10762704
0:05812921
0:00860727

6





7
4





5
6
0:00127449
0:00860727
0:01593648
0:00860727
0:00127449
7
Calculate and show the frequency response (magnitude only) of this lter. Then, apply the lter to the image gold-text.png (convolution between the lter and the image) and show the result.

Now consider the 3    3    lter

    • 3
1   4   1
1
44 26    45

6    1    4    1

Calculate and show it’s frequency response, Then, apply the lter to the resulting image in the previous step. What are your conclusions?

Note: In this exercise, we can use the following functions freqz2, imfilter, conv2, freqspace, mesh, meshgrid, etc.


    • this de nition is convenient for an even number of quantization levels.







9
3.4    Correlation

The gold-text.png is a natural image in which a text is inserted. Find the position of the letter g using the image g-letter.png and the correlation operator. Implement the correlation function in the spatial domain and the frequency domain.

Repeat the operation by adding a noise to the natural image with a normal distribution with standard deviations 5, 10, 25, 40 and 50 (for a dynamic range [ 128; 127]). What is the shape of the correlation product? What are your conclusions?

N.B.1: Apply the correlation function between images with zero nominal average . i.e. with a symmetric

dynamic range with respect to zero.(ex. [  128; 127], or [  0:5; 0:5]).

N.B.2: Don’t forget to take into account the translation introduced by the calculation of correlation in the Fourier domain.

Note: In this exercise, we can use the following functions conv2, fft2, real, max, randn, pixval, find, etc.


3.5    Resampling

Down sample the image sub4.tif by a factor 2 in each direction, by taking one pixel out of two. Show the resulting image. Repeat the operation to the resulting image to obtain an image downsampled by a factor of 4.

Describe the results?

3.6    Phase and magnitude of the 2DFT

    1. Calculate the 2D Fourier transform (2DFT) of the image lena-y.png. Then, calculate the inverse 2DFT by deleting the imaginary part . Repeat the operation by deleting the real part this time. Show the images and explain the results by only using image operations in the spatial domain (i.e. not passing by operations in the Fourier domain).

    2. Calculate the 2DFT of the image lena-y.png. Then, calculate the inverse DFT by setting the phase of the 2DFT to zero. Show the result (real part). Repeat the operation by setting the magnitude to 1 and maintaining the phase as it is. Give an interpretation of the results.

Note: The 2DFT of an image x(k; l), of dimension K    L, is de ned as

K1L1




K1L1
X(m; n) =
x(k; l)e 2j ( mkK + nlL ) =
x(k; l)WKmkWLnl
X X






X X
k=0  l=0




k=0  l=0

1 and or WN , e

j2

for m = 0; : : : ; K  1; n = 0; : : : ; L



.




N



3.7    Weber law

    1. Create a Matlab function named weber taking three parameters of intensity L1, L2 and Lb. This function returns a 2D matrix, described by gure 1.

    2. Determine your Weber constant. Start by taking the value Lb = 10. By varying the intensities L1 and L2, determine the weber constant experimentally.


L
;
(1)

L1



where    L = L2    L1 is the minimal intensity di erence we can perceive.

3. Same question, but by taking this time Lb = 200. Comment the results.

10







160 pixels
160 pixels


Lb

L 1
L2





    600 pixels

80 pixels







600 pixels

Figure 1: Test image for Weber constant determination



Note: it’s important to perform the whole weber experience under the same ambient illumination condi-tions and the same monitor settings.








































11

More products