G rect - A Matlab toolbox for georectifying digital images

De POLR
Sauter à la navigation Sauter à la recherche

Introduction

This toolbox contains a series of Matlab functions for georectifying highly oblique digital images. This is useful in oceanography for obtaining quantitative information on sea-surface patterns such as those induced by internal waves, fronts or sea-ice.

Although this toobox was initially developed to georectify geophysical images it can be used just as well for rectifying laboratory images. The following images show examples of such image rectifications.

Example of a geophysical photo showing sea-ice distribution in the St. Lawrence Estuary.
Same as previous photo once georectified.
Example of a laboratory basin photo.
Same as previous once georectified.

How to get the package

Click on this link to download the package: g_rect_package_1.0.

Once expanded the g_rect package is organized as follow:

  • g_rect_package
    • src (the source codes)
      • g_rect (contains the main georectification functions)
      • g_calib (contains camera calibration functions)
      • g_stabilize (contains image stabilization functions)
    • Examples
      • Field (a field example)
      • Lab (a lab example)

The main georectification functions are found within the g_rect directory. The other two directories are for more advanced processing if the camera needs to be calibrated (g_calib) or if you need to stabilize (i.e. removing small movements between successive images) a series of images (g_stabilize). You may not need to play at all with these.

g_rect: Quick Start

For a quick start let's only play with the main function called g_rect.m found under the g_rect directory. First you should set this directory into your Matlab path (File -> Set Path).

Then go with Matlab into the directory Examples/Field. You will find there an image (IMG_6614.JPG) and a file named parameters.dat. This is the main input parameter file that you need to edit for a given image or for a given series of images.

This input parameter file looks like this:

Input file: parameters.dat

% I/O information
imgFname      =  'IMG_6614.JPG';   % This is the reference image
firstImgFname =  'IMG_6614.JPG';  % This is just to indicate the first image of a sequence 
lastImgFname  =  'IMG_6614.JPG'; % This is just to indicate the last image of a sequence 
outputFname   =  'g_rect.mat';      % This is the output filename where the new coordinates will be stored.

% Field or lab case situation.
% Set field = true for field situation and field = false for lab situation.
% Lab situation does not expect to work with latitude and longitude but simply with meters.
field = true; 
 
% Camera position
% lat/lon for field situation
% meter for lab situation
LON0 = -70.6010167;
LAT0 =  47.2713000; 
 
% Offset from center of the principal point (generally zero)
ic = 0;
jc = 0;

% Parameters
hfov =      45.0;     % Field of view of the camera
lambda =    2;        % Dip angle above vertical (e.g. straight down = 90, horizontal = 0)
phi =       0.0;      % Tilt angle (generally close to 0)
H =         720;      % Camera altitude
theta =     70.0;     % View angle clockwise from North (e.g. straight East = 90)

% Uncertainty in parameters. Set the uncertainty to 0.0 for fixed parameters.
dhfov =     20.0; 
dlambda =   10.0;
dphi =      5.0;
dH =        0.0; 
dtheta =    20.0; 

% Order of the polynomial correction (0, 1 or 2) 
polyOrder = 1;

% To save memory calculation can be done in single precision.
% For higher precision set the variable 'precision' to 'double'.
precision = 'double';

% Ground Control Points (GCP). 
% The data must come right after the gcpData = true 
gcpData = true;
360  829  -70.561367  47.303783
 54  719  -70.54500   47.335
 99  661  -70.505     47.375
452  641  -70.435     47.389
429  633  -70.418     47.408
816  644  -70.393     47.368


This file contains all parameters required to perform a georectification. You can add spaces and comments as you wish within this file. One specify format needs however to be respected. The ground control points (gcp) must appear right after the variable gcpData = true; These ground control points represent the lon-lat position associated with some image coordinates.

If you know perfectly some of the camera parameters (e.g. the field of view) you simply have to set the uncertainty of this parameter to zero (e.g. dfov = 0). Otherwise, for other parameters with some uncertainty the minimization algorithm will search within the given uncertainty to find the best parameters values that gives a best fit between the image control points once georectified and the ground control points (see Bourgault, 2008, for details).

To run the georectification, all you have to do in principle is to edit this file and to type in Matlab g_rect at the command line. You will then be prompted for the name of the input parameter file (it does not have to be called parameters.in). You image will appear with the GCPs as well as a table re-listing all of your parameters. If you're ok with this type enter.

You will then see the algorithm searching the parameter space and will eventually return the result for the set of parameters found. A file will be created, named accoring to the name given in the variable outputFname. This is the main result file that contain all important variables. The most important matrices created are named LAT and LON. These two matrices have the same size as your original image and provides the latitude and longitude of every associated pixel. You can then make a figure using for example the command pcolor (or m_pcolor if you use the m_map package) with LON and LAT as the arguments for the position and a third argument for the pixel intensity which could simply be the mean of the RGB channel if you want to reduce a color image to a grayscale image. Fancier color representation could also be done but this is up to you.

The g_rect package works best with the m_map package installed.

References