Commit cc08ca2df28683cb06778613d94ef063b356fa83

Authored by Daniel Bourgault
1 parent 56902974
Exists in master

Addition of the function g_jpg_jpw.m created by Tom Shand to make .jpg and worldfile.

Examples/Example_1/parameters.dat
... ... @@ -98,11 +98,12 @@ precision = 'double';
98 98  
99 99 %% GROUND CONTROL POINTS (GCPs).
100 100 % The GCP data must come right after the 'gcpData = true' instruction
101   -% Column 1: horizontal image index of GCPs
102   -% Column 2: vertical image index of GCPs
103   -% Column 3: longitude (Geodetic) or x-position (Cartesian) of GCPs
104   -% Column 4: latitude (Geodetic) or y-position (Cartesian) of GCPs
105   -% Column 5 (optional): elevation (in m) of GCPs.
  101 +% Column 1: horizontal image index of GCPs
  102 +% Column 2: vertical image index of GCPs
  103 +% Column 3: longitude (Geodetic) or x-position (Cartesian) of GCPs
  104 +% Column 4: latitude (Geodetic) or y-position (Cartesian) of GCPs
  105 +% Column 5: elevation (in m) of GCPs (optional)
  106 +%
106 107 gcpData = true;
107 108 360 829 -70.561367 47.303783 0
108 109 54 719 -70.54500 47.335 0
... ...
Examples/Example_2/parameters.dat
... ... @@ -103,11 +103,11 @@ precision = 'double';
103 103  
104 104 %% GROUND CONTROL POINTS (GCPs).
105 105 % The GCP data must come right after the 'gcpData = true' instruction
106   -% Column 1: horizontal image index of GCPs
107   -% Column 2: vertical image index of GCPs
108   -% Column 3: longitude (Geodetic) or x-position (Cartesian) of GCPs
109   -% Column 4: latitude (Geodetic) or y-position (Cartesian) of GCPs
110   -% Column 5 (optional): elevation (in m) of GCPs.
  106 +% Column 1: horizontal image index of GCPs
  107 +% Column 2: vertical image index of GCPs
  108 +% Column 3: longitude (Geodetic) or x-position (Cartesian) of GCPs
  109 +% Column 4: latitude (Geodetic) or y-position (Cartesian) of GCPs
  110 +% Column 5: elevation (in m) of GCPs (optional)
111 111 %
112 112 gcpData = true;
113 113 1818 490 1661903.38 5316012.52 6.28
... ...
Examples/Example_3/parameters.dat
1   -
2   -
3   -% I/O information
  1 + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2 +%
  3 +% The image found in this folder ('IMG_8368.jpg') as well as the data found below in
  4 +% this parameter file are only to provide an example of the g_rect package applied
  5 +% to a laboratory situation. These data are not associated with any publication.
  6 +%
  7 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  8 +
  9 +%% INPUT/OUTPUT INFORMATION
  10 +% imgFname: This is the only image that will actually be treated
  11 +%
  12 +% firstImgFname: This is really just a comment not actually used by the algorithm
  13 +% that indicates the name of the first image of a sequence to which
  14 +% the georectification of image 'imgFname' could also be applied to.
  15 +%
  16 +% lastImgFname: Same as 'firstImgFname'but for the last sequential image.
  17 +%
  18 +% outputFname: This is the name of the output fil that will contain, among other
  19 +% variables, the matrices LON and LAT that will give the ground
  20 +% coordinate of every pixel of the image that are below the horizon.
  21 +%
4 22 imgFname = 'IMG_8368.jpg';
5 23 firstImgFname = 'IMG_8368.jpg';
6 24 lastImgFname = 'IMG_8368.jpg';
7 25 outputFname = 'IMG_8368_grect.mat';
8 26  
9   -% Field or lab case situation.
10   -% Set field = true for field situation and field = false for lab situation.
11   -frameRef = 'Cartesian';
12   -
13   -% Camera position
14   -% lat/lon for field situation
15   -% meter for lab situation
  27 +%% FRAME OF REFERENCE
  28 +% The frame of reference could be either 'Geodetic' or 'Cartesian'.
  29 +% If 'Geodetic' is used, longitudes and latitudes are expected for positions.
  30 +% If 'Cartesian' is used, x-y positions are expected (in m)
  31 +%
  32 +frameRef = 'Cartesian';
  33 +
  34 +%% CAMERA POSITION
  35 +% Set the longitude and latitude for ‘Geodetic’ frame of reference
  36 +% Set the x-y coordinate for ‘Cartesian’ frame of reference.
  37 +%
16 38 LON0 = 1.01;
17 39 LAT0 = 2.36;
18 40  
19   -% Offset from center of the principal point (generally zero)
  41 +%% OFFSET
  42 +% Offset from center of the principal point (generally zero)
  43 +%
20 44 ic = 0;
21 45 jc = 0;
22 46  
23   -% Parameters
  47 +%% CAMERA PARAMETERS
  48 +% These are either the initial guesses for the uncertain parameters, i.e. those
  49 +% with an uncertainty > 0 (see next section) or the exact values for the parameters
  50 +% with an uncertainty set to 0 below.
  51 +%
  52 +% hfov: Field of view of the camera (degree)
  53 +%
  54 +% lambda: Dip angle (degree) below horizontal (e.g. straight down = 90, horizontal = 0)
  55 +%
  56 +% phi: Tilt angle (degree), generally close to 0.
  57 +%
  58 +% theta: View angle (degree) clockwise from North (e.g. straight East = 90)
  59 +%
  60 +% H: Camera altitude relative to the local water level (m)
  61 +%
24 62 hfov = 62.00; % Field of view of the camera
25 63 lambda = 53.0; % Dip angle below horizontal (e.g. straight down = 90, horizontal = 0)
26 64 phi = 1.0; % Tilt angle (generally close to 0).
27 65 H = 1.755; % Camera altitude (m)
28 66 theta = 180.0; % View angle clockwise from North (e.g. straight East = 90)
29 67  
30   -% Uncertainty in parameters. Set the uncertainty to 0.0 for fixed parameters.
  68 +%% UNCERTAINTIES
  69 +% Set here the uncertainties of the associated camera parameters.
  70 +% Set the uncertainty to 0 for fixed parameters.
  71 +%
31 72 dhfov = 5.0;
32 73 dlambda = 10.0;
33 74 dphi = 5.0;
34 75 dH = 0.5;
35 76 dtheta = 20.0;
36 77  
37   -% Order of the polynomial correction (0, 1 or 2)
  78 +%% POLYNOMIAL CORRECTION
  79 +% After the geometrical correction, a polynomial correction of degree 1 or 2
  80 +% could be applied. This could correct for some unknown distortions that cannot be
  81 +% corrected on geometrical grounds. Play carefully with this option as it is a purely
  82 +% mathematical fit which may lead to unphysical corrections or may hide other
  83 +% prior problems with the actual geometrical correction. Always first set this option
  84 +% to '0' in which case there will be no polynomial correction applied. In principle,
  85 +% the geometrical fit without this option should already be pretty good. You could then
  86 +% fine tune the image with this option. Be extra careful when using the second order
  87 +% polynomial fit, especially outside the region of the GCPs as the image could there
  88 +% be completely distorted.
  89 +%
38 90 polyOrder = 2;
39   -
40   -
41   -% To save memory calculation can be done in single precision.
42   -% For higher precision set the variable 'precision' to 'double';
  91 +
  92 +%% PRECISION
  93 +% To save memory, calculations can be done in single precision.
  94 +% For higher precision set the variable 'precision' to 'double';
  95 +%
43 96 precision = 'double';
44 97  
45   -
46   -% Ground Control Points (GCP).
  98 +%% GROUND CONTROL POINTS (GCPs).
  99 +% The GCP data must come right after the 'gcpData = true' instruction
  100 +% Column 1: horizontal image index of GCPs
  101 +% Column 2: vertical image index of GCPs
  102 +% Column 3: longitude (Geodetic) or x-position (Cartesian) of GCPs
  103 +% Column 4: latitude (Geodetic) or y-position (Cartesian) of GCPs
  104 +% Column 5: elevation (in m) of GCPs (optional)
  105 +%
47 106 gcpData = true;
48 107 2999 226 0.500 0.00 0
49 108 1694 220 1.500 0.00 0
... ... @@ -56,12 +115,4 @@ gcpData = true;
56 115 4131 1580 0.000 1.23 0
57 116 521 2548 1.910 1.82 0
58 117 248 2328 2.060 1.71 0
59   - 14 1868 2.290 1.46 0
60   -
61   -
62   -
63   -
64   -
65   -
66   -
67   -
  118 + 14 1868 2.290 1.46 0
68 119 \ No newline at end of file
... ...
src/g_rect/g_jpg_jpw.m 0 → 100644
... ... @@ -0,0 +1,131 @@
  1 +function [] = g_jpg_jpw(LON,LAT,dx,lon_min,lon_max,lat_min,lat_max,grey)
  2 +%
  3 +% This function creates geotiff images given the longitudes (LON)
  4 +% and latitudes (LAT) of every pixels of the associated jpeg images found
  5 +% in the current folder. The matrices LON and LAT typically come from the
  6 +% g_rect package.
  7 +%
  8 +% The geotiff images are constructed by interpolating on a regular grid of
  9 +% size dx (in m) the irregularly-spaced pixel intensities defined by the
  10 +% LON-LAT pair.
  11 +%
  12 +% INPUT PARAMETERS:
  13 +%
  14 +% LON: A matrix of size identical to the associated images in the current
  15 +% folder that gives the longitude of every pixel of those images.
  16 +% This matrix would typically come from the g_rect package.
  17 +%
  18 +% LAT: Same as LON but for the latitude.
  19 +%
  20 +% dx: The grid size (in m) of the regularly-spaced interpolated
  21 +% geotif image
  22 +%
  23 +% lon_min: The longitude of the southwest corner of the desired
  24 +% geotif image.
  25 +%
  26 +% lon_max: The longitude of the northeastcorner of the desired
  27 +% geotif image.
  28 +%
  29 +% lat_min: The latitude of the southwest corner of the desired
  30 +% geotif image.
  31 +%
  32 +% lat_max: The latitude of the northeastcorner of the desired
  33 +% geotif image.
  34 +%
  35 +% grey: greyscale (1) or rgb (2)
  36 +%
  37 +% OUTPUT:
  38 +%
  39 +% This function writes geotiff images that have the same name as the
  40 +% jpeg images but with the extension .tif
  41 +%
  42 +% LAST REVISION: 5 May 2020
  43 +%
  44 +% AUTHOR:
  45 +% - Daniel Bourgault (daniel_bourgault@uqar.ca)
  46 +%
  47 +% Hacked around by Tom Shand 8/5/20 to output as JPG + worldfile and grey
  48 +% or RGB options.
  49 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  50 +
  51 +% Construct the vectors 'lon' and 'lat' that define the interpolating
  52 +% grid of constant resolution dx (in m)
  53 +
  54 +%TDS 8/5/20 swapped this
  55 +% lat0 = (lat_min + lat_max)/2;
  56 +% dlat = dx/(1852*60);
  57 +% dlon = dlat/cosd(lat0);
  58 +% lon = [lon_min:dlon:lon_max];
  59 +% lat = [lat_min:dlat:lat_max];
  60 +%For this
  61 +lon = [lon_min:dx:lon_max];
  62 +lat = [lat_min:dx:lat_max];
  63 +
  64 +% Find the indices of only the finite values in the matrix LON
  65 +% so that the interpolation is only done on finite values and does
  66 +% not spend time interpolating NaNs.
  67 +ifinite = find(isfinite(LON) == 1);
  68 +
  69 +% Find all .jpg images in the current folder
  70 +img_fname = dir('*.jpg');
  71 +N_img = length(img_fname);
  72 +
  73 +% Loop over all images
  74 +for i = 1:N_img
  75 +
  76 + image = imread(img_fname(i).name);
  77 +
  78 + if grey == 1
  79 + % Convert to gray scale
  80 + img = rgb2gray(image);
  81 + img = double(img);
  82 + img = img';
  83 +
  84 + % Interpolate on the regular grid defined above by the vector
  85 + % lon and lat
  86 + img_interp = griddata(LON(ifinite),LAT(ifinite),img(ifinite),lon,lat');
  87 + % Convert real numbers to unsigned integers
  88 + img_interp = uint8(img_interp);
  89 +
  90 + else
  91 + imgrgb=double(image);
  92 + imgr=imgrgb(:,:,1)';
  93 + imgg=imgrgb(:,:,2)';
  94 + imgb=imgrgb(:,:,3)';
  95 +
  96 + img_interpr = griddata(LON(ifinite),LAT(ifinite),imgr(ifinite),lon,lat');
  97 + img_interpg = griddata(LON(ifinite),LAT(ifinite),imgg(ifinite),lon,lat');
  98 + img_interpb = griddata(LON(ifinite),LAT(ifinite),imgb(ifinite),lon,lat');
  99 +
  100 + img2=zeros(size(img_interpb));
  101 + img2(:,:,1)=img_interpr;
  102 + img2(:,:,2)=img_interpg;
  103 + img2(:,:,3)=img_interpb;
  104 + img_interp = uint8(img2);
  105 +
  106 + end
  107 +
  108 + % Write the jpg + worldfile
  109 + jpg_img_fname = [img_fname(i).name(1:end-4),'rect.jpg']
  110 + imwrite(flipud(img_interp),jpg_img_fname,'Quality',100)
  111 +
  112 + % Setting worldfile values
  113 + xpixel=dx;
  114 + yrot=0;
  115 + xrot=0;
  116 + ypixel=-dx;
  117 + xcoord=lon_min;
  118 + ycoord=lat_max;
  119 +
  120 + % Export csv with gps coordinates of the line.
  121 + % worldfilenme_name = strcat(photo,'_rectified','.jpw');
  122 + worldfilenme_name = [img_fname(i).name(1:end-4),'rect.jpw']
  123 + wldmatrix = [xpixel; yrot; xrot; ypixel; xcoord; ycoord];
  124 + dlmwrite(worldfilenme_name,wldmatrix,'precision', 10)
  125 +
  126 + % Write the geotiff file
  127 + % geotif_img_fname = [img_fname(i).name(1:end-3),'tif']
  128 + % bbox = [lon_min, lat_min; lon_max, lat_max];
  129 + % geotiffwrite(geotif_img_fname, bbox, flipud(img_interp),8);
  130 +
  131 +end
0 132 \ No newline at end of file
... ...