MorphoGraph and Imagery - Practical Session 1

Targeted skills:

- Handling the link between an image, a structuring element (given in various forms), and a graph.

- Programming elementary image processing functions in C.

- Getting started with PINK.

- Editing a structuring element with the esedit program from PINK library.

- Writing a basic shell script made of few lines.

- Forseeing the effect of a dilation and of an erosion depending on the chosen structuring element on toy (very-small_size) images and on real images

Step 1: Getting started with the working environment

1a. Start a Linux session.

1b. Create a directory named MorphoGraph and a subdirectory named PS1.

1c. Download the archive TP1.tgz and save it in your directory PS1.This archive contains, among others, basic programs to manipulate graphs, images, and structuring elements. Documentation of the programs can be found here: documentation .

1d. Uncompress this archive by typing 'tar -xvzf IN3M22_TP1.tgz' in a terminal.

1e. You are finally ready to start the first Practical Session of the course!

Step 2: Implement a morphological dilation algorithm

2a. Review the contents of the source file Dilatation.c. The skeleton of a program has been made for you. As you can notice by reading the main function, there are 4 main steps

i) reading of the image ;

ii) reading of a (translation invariant) structuring element (s.e.) ;

iii) creation of the graph G that corresponds to the read s.e.; and

iv) dilation of the set of white image pixels.

Find out these 4 steps in the code.

2b. Before going further, it may be useful to have a glance at the description of the data structures used to represent a graph by the 'gamma' map (successor map). You can also refer to the source code documentation, in particular:

-> the definitions of the main structures (graphe, cell, ... )

-> the basic functions for handling graphs (see in particular InitGraphe, AjouteArc, ... )

2d. The goal of the next question will be to complete the C codes which was given to you. In order to help you with that task, you should first write C functions that make the correspondence between the coordinates of a pixel in the image and the number (index) associated to a vertex in the graph. In order to make such correspondance, we shall consider a scanning of the pixels in a raster order (pixels by pixel on a line and the a line after one another). Thus, since the vertices are numbered from 0 to N (N being the number of image pixels), the top left pixel of the image will be associated to the vertex numbered 0 in the graph and the bottom right pixel will be mapped to the vertex numbered N-1. An example showing how the other pixels are considered with the raster scanning order is provided in Figure 1 below.

perso.esiee.fr/~coustyj/EnglishMorphoGraph/CoordinatesVertex.svg

-> Write a function, called 'getVertex', that returns the number of a vertex corresponding to the horizontal and vertical coordinates provided as parameters. Your function should also take as parameters the number of lines and of columns of the image.

-> Write a function, called 'getHorizontalCoordinate', that returns the horizontal integer coordinate of a pixel provided, as a parameter, the number of the vertex associated to this pixel. Your function could also take as parameters the number of lines and of columns of the image.

-> Write a function, called 'getVerticalCoordinate', that returns the vertical integer coordinate of a pixel provided, as a parameter, the number of the vertex associated to this pixel. Your function could also take as parameters the number of lines and of columns of the image.

2d. Fill in the code corresponding to step iii and compile your program by typing 'make' in the terminal.

2e. Test your dilation program on the image cell3.pgm that is located in the directory named 'Images'.

-> To visualize an image, use the commands 'display' or 'xv'.

-> To generate and save a s.e., use the command "esedit.tcl width height seName.pgm" where 'width' and 'height' are respectively the width and height of the s.e. and where seName.pgm is the name of the file in which the structuring element will be saved. In order to be able to use the program esedit.tcl, you must first set up the image processing librairy PINK by following the instructions below:


- download PINK library at https://perso.esiee.fr/~coupriem/pink.tgz
- open a terminal
- change current directory to the directory wher PINK was downloaded
- then, uncompress PINK with 'tar -xvzf pink.tgz'
- 'cd PINK'
- compile PINK: './makelin'
- create a file name '.pink.start' in your directory homedir
- add the two following lines in the .pink.start file :
>> export PINK=[main_pink_directory]
>> export PATH=$PATH:$PINK/linux/bin:$PINK/scripts:$PINK/tcl
where you replace [main_pink_directory] by the path of the directory where PINK is installed.
- before using PINK in a terminal enter the following command line 'source ~/homedir/.pink.start'.

Step 3: Implement a morphological erosion by duality

3a. The command 'inverse' (from PINK) allows the complement of a binary image to be computed. Try this command on the image cell3.pgm

3b. Due to the 'inverse' command et your dilation program, erode the object of the 'image cell3.pgm by any s.e. at your convenience (that is to say compute *δ_Γ(X)).

3c. Having to type three command lines whenever you want to apply an erosion is a bit tedious. To solve this problem, you can use a shell script.

-> Read the documentation that is here, in french, and its google translation.

-> Write a shell script that allows an image to be eroded by a s.e. (that is to say, a script to compute *δ_Γ(X)).

Step 5: Exercises

5b. Complete the exercise p30 of the materials "Mathematical morphology: basic operators". Test your method on one of the image of the practical session.

5c. Complete the exercise p28 of the materials "Mathematical morphology: basic operators".