                                  
                                 Huy Buu HO

                                     and

                              Willem-Jan Goddrie

  
                               IMAGE PROCESSING


1 Introduction :
----------------
The program has been written in Turbo Pascal 6.0 under the Borland Package
and is intended to be an introduction to "Digital Image Processing" (DIP).

The demo displays the general outline of DIP and illustrates some theories
and algorithms of:  - Image Enhancing
                    - Image Manipulation
                    - Morphological functions
                    - Image Identification

The demo is designed to be user-interactive and the majority of options,
which can be selected by the touch of a key, are menu driven.

When the user is required to input a filename or a number of more than one
character, a return is necessary.


2 Requirements :
----------------
To run the demo the following equipment is required :

   i.  an IBM Compatible PC ( 286 or above )
   ii. VGA Card and monitor

To decrease the processing time of the demo it is recommendable to execute
the program from the C-drive.


3 Potential Applications :
--------------------------
DIP already has applications in many subjects such as :
     Geology       - Analysing rock surface, features, and fissures
     Medicine      - Cellular measurement, Implant analysis
     Astronomy     - Enhancing, smoothing images
     Metal Plating - Evenness, Quantitative measurements

as well as in a growing number of other fields.


4 Techniques and Algorithms :
-----------------------------
The algorithm of each of the functions are written and set out according to
the theories contained in 'Digital Image Processing' by Wintz & Gonzales
[1] and 'Computer-Assisted Microscopy' by Russ [2].

Where possible some of the processing techniques, such as variables and
loops, are shortened to increase the speed of the processing time.


5 The Demonstration Program :
-----------------------------
The demo is completely menu driven and all options are displayed on the
bottom half of the screen.  The user should find that the information given
in the menus is sufficient for the purposes of the demo.  Further infor-    
mation about each function and option is given below.


5.1 Screen Presentation :
-------------------------
The Title screen contains a brief introduction to the parties involved with
the project and is followed by a description of the demo.  An outline of 
the Main Working Screen is shown over leaf.  


   Ŀ
     ACTIVE WINDOW          TEMPORARY WINDOW     HISTOGRAM  
    Ŀ ĿĿ
                                                      
                                                      
                                                      
                                                      
                                                      
             1                    2                   
                                                      
                                                      
                                                      
                                                      
                                                      
     ٳ         
    Ŀ    5    
                                                       
                                                       
                                                       
                                                       
             3                     4                   
                                                       
                                                       
                                                       
                                                       
    ٳ
   
   Figure 1 : Working Screen

    BOX : 
     1 - The Active Window into which the original image is loaded and on   
         which all the processes are based.
     2 - The Temporary Window into which all the resulting images are       
         output after being processed.
     3 - The Main Menu ; other menus and options are detailed.
     4 - As box 3 but it also indicates to the user when a process is       
         active.
     5 - Displays a histogram of an image for reference or later use


5.2 Description of Menus and Options :
--------------------------------------

Main Menu :
-----------
The main menu lists the major functions and options which may be chosen
merely by pressing the appropriate key as indicated in front of the
function name.

The various functions and options are explained in more detail later on in
this document.

The Main Menu is as follows :

   Ŀ
          MAIN MENU                                        
                                  F1 Clear Active Window   
     F  Filters                   F2 Clear Tempry Window   
                                  F3 Load Image Onto Active
     H  Histogram                 F4 Save Image From Active
                                  F5 Active >> Tempry Win  
     C  Combination               F6 Active << Tempry Win  
                                  F7 Normal 16 Grey Levels 
     M  Morphology Applications   F8 Inverse 16 Grey Levels
                                  F9 Pseudo Colours        
     T  Threshold-Segment                                  
                                                           
     Q  Quantification            ESC Alt- X to Exit       
   
   Figure 2 : Main Menu

The 'F' commands are self explanatory with the result or effect of each
function being seen instantly, except for F3 & F4 which require filenames
to be entered by the user.

ESC-key and ALT-X
-----------------
The Esc-key can be used to exit the demo whilst in the Main Menu.  The ESC-
key is also used for returning to the Main Menu from Sub Menus and to stop
a process whilst in progress.  ALT-X can be used to leave the demo from the
Main Menu.


F3 Load Menu
------------
In this menu a list of all .RIC format files is displayed page by page in
box 3.  If there is more than one page of filenames, the user is prompted
to press a key in order to display the next page.  To load one of these 
files, the user enters the filename WITHOUT the extension .RIC.  ESC will
return the user to the Main Menu.

If an incorrect filename is entered, the message 'File Not Extant' is
displayed below the filename and the Main Menu is shown again.

  Ŀ
          IMAGES                      LOAD MENU            
    BEATRICE.RIC    SUXES1.RIC      To Load Image Onto     
    BRIGITTE.RIC    SUXES2.RIC      Active Window          
    CARRE.RIC       THTEST.RIC      Enter Name             
    CELTEST.RIC     SOPHIA.RIC                             
    MORPH.RIC       CELLS.RIC       REBEC...               
    MORPH23.RIC     MORPH44.RIC                            
                                                           
              More.....             ESC to Ignore          
  
  Figure 3 : Load Menu


F4 Save Menu
------------
When this option is chosen, the user is prompted to enter a filename or
press ESC to return to the Main Menu.  If a filename already exists on
disk, the program displays the message 'File Already Exists' and returns to
Main Menu.

  Ŀ
                                      SAVE IMAGE           
                                To Save Image From         
                                Active Window              
                                Enter Name                 
                                                           
                                CELL....                   
                                                           
                                                           
                               ESC to Ignore               
  
  Figure 4 : Save Menu


F  Filters :
------------
When this option is chosen a submenu appears with the following options :

F Filtering Smoothing
---------------------
From this menu the user may choose either Neighbourhood or Median Filter-
ing, followed by an option of Mask-Window 3 or 5.

  Ŀ
    FILTERING - SMOOTHING               MEDIAN FILTER      
                                                           
    N neighbourhood              Please Choose Mask Window 
    M median filter                         3 - 5          
                                                           
                                              3            
                                                           
                                                           
    choose N M                   Esc to Ignore             
  
  Figure 5 : Filtering-Smoothing Menu


With a mask window, Neighbourhood filter is based on the median value of
the mask window which is calculated as follows:

              W(xy) = (a+b+c+d+e+f+g+h+i)/9

                      Ŀ 
                       a  b  c 
                      Ĵ
                       d  e  f 
                      Ĵ
                       g  h  i 
                      
               Figure 6 : a 3x3 mask window

Median filter is the median value of the windows' values and it's the
middle value in the range of grey levels.  However, in this program the
user may choose which order value in the array from the 3x3 mask window
option.


G Gradient - Edge Detection
---------------------------
Here these functions are used to highlight or outline the edges of an image
to show and distinguish different objects.  In the demo there are three
techniques :

(1) Laplacian Operator:  This uses a 3x3 mask window with a fixed value as
shown below and it is passed over the image, pixel by pixel.

                  Pixel(x,y) = (b+d+f+h) - 4e

(2) Sobel Operator:  This uses two 3x3 mask windows, one for the x direc-
tion, the other for the y direction and the result is the addition of the x
and y processes.

   Ŀ
   -1 -2 -1                -1  0  1 
   Ĵ               Ĵ
    0  0  0                -2  0  2 
   Ĵ               Ĵ
    1  2  1                -1  0  1 
   
   Figure 7 : Sobel Operator

3) Global Thresholding:  This is a fast process which detects the differ-
ence in grey levels between the x (x+1) and y (y+1) neighbours.  An
ON_pixel assigned to that pixel denotes an edge when there is a difference.

  Ŀ
  GRADIENT-EDGE DETECTION       GLOBAL THRESHOLDING        
                                                           
                                                           
     L Laplacian Operator    1. Edge over Original Images  
                                                           
     S Sobel Operator        2. Edge over Black Back Ground
                                                           
     G Global Thresholding                                 
                                                           
                                                           
     Choose L S G               Esc to Ignore              
  
  Figure 8 : Gradient-Edge Detection


N Add Noise To Image
--------------------
This procedure adds a random pattern of artificial noise to the image in
order to demonstrate the smoothing processes.


H Histogram
-------------
When this option is chosen a submenu appears with the following  options :


H Histogram of Image
--------------------
This displays a histogram in the temporary window of the image's grey
levels between  0-15.  If the user wishes to keep the histogram for later
use, it can be stored in the window on the right of the Temporary Window by
pressing RETURN. The Histogram of the Active Window is stored into memory
when the image is loaded from disk.


E  Histogram Equalisation
-------------------------
The Histogram Equalisation technique redistributes a concentrated band of
grey levels evenly over the entire scale.  The purpose is to improve the
visibility of the image.  The histogram of the equalised image is also
stored in memory.


T Transfer and Histogram
------------------------
This is a slow image transfer as the histogram of the image is also being
carried out.  This is particularly useful when the user has applied some 


COMBINATIONS of images and would like to see the Histogram of a resultant
image.

C Combination of Images
-----------------------
An Addition, Subtraction, Division and Multiplication of the Active and
Temporary Image can be performed by choosing the functions as shown in the
following menu.

  Ŀ
          COMBINATION                    ADDITION          
                                                           
         A addition                 1 set overflow to 0/15 
         S subtraction              2 set modulo 15        
         D division                                        
         M multiplcn                                       
                                                           
                                                           
    Choose A S D M                 ESC to Ignore           
  
  Figure 9 : Combination Menu


Modes 1 and 2 set the limit and value of the pixel.  In the Addition
procedure when two values are added together the maximum value is 15 in
mode 1.  In mode 2 the modulo value is the maximum colour value subtracted
from the resulting value which is greater than 15.  This is the reverse for
the Subtraction procedure.  In Mode 1 zero is assigned to the values that
are less than zero and in mode 2 the maximum colour is added to the result
value which is less than zero.

Division is the active image divided by the temporary image and multiplied
by a factor which is chosen by the user between 1 and 15.  For this
technique a value of 15 is allocated when the result value is greater than 
15 or the value from the Temporary Window is zero.

Multiplication is the active image multiplied by the temporary image and
divided by a factor between 1 and 15.  The value of 15 is given when the
output value is higher than 15.


M Morphology Application :
--------------------------
In this section the algorithms are designed to work with binarised images.
Therefore the user needs to threshold the image or load in a binary image
before performing any of these functions.
A very basic example is known as erosion and dilation and their useful
functions include smoothing feature outlines, joining broken or discontin-
uous features, and separating touching ones.
The name 'opening' comes from the tendency of this sequence of operations
to open up gaps between touching features, or to open up cavities near the
periphery of features so that they are not enclosed.  The original feature
area is not exactly recovered when a 'closing' procedure is applied because
the initial erosion eliminates some of the original outside pixels.


                  Opening = Erosion + Dilation 
                  Closing = Dilation + Erosion

  Ŀ
        MORPHOLOGY                                         
                                                           
        D Dilation                                         
        E Erosion                                          
        O Opening                                          
        C Closing                                          
                                                           
                                                           
    Choose D E O C                 ESC to Ignore           
  
  Figure 10 : Morphology


After choosing one of the options above, the user has to choose other
conditions in order the carry out the process :

        1. Choose Matrix Type [1..7]

        2. Choose N OFF neighbours in order to Dilate/Erode
             Matrix Type 5 [1..4]
             Matrix Type 6 [1..8]
             Matrix Type 7 [1..20]


        3. Enter N of Iterations [1..15]

   Matrix type :
                                     
        1 : Horizontal Vector       Ŀ 
                                             
                                    Ĵ
                                          
                                    Ĵ
                                             
                                    

        2 : Vertical Vector         Ŀ
                                            
                                    Ĵ
                                            
                                    Ĵ
                                            
                                    

        3 : Diagonal Vector         Ŀ 
                                            
                                    Ĵ
                                            
                                    Ĵ
                                            
                                    

        4 : Diagonal Vector         Ŀ 
                                            
                                    Ĵ
                                            
                                    Ĵ
                                            
                                    

        5 : Cross Matrix            Ŀ 
                                            
                                    Ĵ
                                          
                                    Ĵ
                                            
                                    

        6 : Square Matrix           Ŀ 
                                          
                                    Ĵ
                                          
                                    Ĵ
                                          
                                    

        7 : Circular Matrix         Ŀ
                                                
                                    Ĵ
                                              
                                    Ĵ
                                              
                                    Ĵ
                                              
                                    Ĵ
                                                
                                    

      2 N OFF Neighbours :

       This option is only indicated when matrix type 5 or above has been   
       chosen.  The N which is used to dilate a pixel when it's neigh-     
       bour(s) are OFF, and vice versa for erosion
 
       3 N of Iterations :

       This is a number of times the process should be repeated.

       All the options above are selected by the user.


T Thresholding Segment Image
----------------------------
This is to segmentate or separate an object from the background within the
frame.  It is normally used to convert an image of different grey levels
into binary image from a particular grey value which can be observed from
the histogram of the image.  Any values below the chosen one, will be
omitted and any above will be passed through and then set to the maximum
value (white/15).  This is particular useful for the morphology functions.

   Ŀ
     THRESHOLDING - SEGMENTATION                           
                                                           
       Please Enter Threshold                              
       To Threshold the Image                              
                                                           
               1..                                         
                                                           
                                                           
      ESC to Ignore                                        
   
   Figure 11 : Thresholding-Segmentation Menu


Q  Quantification :
-------------------
When this option is chosen a submenu appears with the following options :

I Identification
----------------
When this option is chosen the program takes the objects one by one from
the Active window and calculates the :
      - Area 
      - Perimeter
and shows the objects in the Temporary Window one by one with the measured
factors.

  Ŀ
    Number of object :  2                                  
                                                           
    Area       : 645                                       
                                                           
    Perimeter  : 422.23                                    
                                                           
                                                           
                                                           
                                                           
  
  Figure 12 : Identification


G Geometric Calculation
-----------------------
With this option the program calculates the maximum diameter, the angle of
this diameter and the breadth of each object.  As the option uses the files
of the object which are created when measuring the perimeter, it is neces-
sary to choose the option I Identification first.


  Ŀ
   Number of object :  2                                   
                                                           
   Maximum diameter : 30                                   
                                                           
   Diameter angle   : 15                                   
                                                           
   Breadth          : 17                                   
                                                           
                                                           
  
  Figure 13 : Geometric Calculation


M  Map of Distance :
--------------------
This option creates a map of distance of the image in the Active window. In
the map of distance each pixel of an object is replaced with a value which
responds to its distance from the edge of the object. 


S  Separation :
---------------
This option separates the touching and over-lapping objects in the image.
Before choosing this option it is necessary to create the map of distance
with the option M Map of Distance.


