g_viz_field.m 3.28 KB
Newer Older
Pascal Bourgault's avatar
Pascal Bourgault committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
function [h_figure,h_pcolor,h_datetext] = g_viz_field(imgFname,rectFile,varargin)
%G_VIZ_FIELD Generates a map with a georectified image
%       G_VIZ_FIELD Generates a map with the georectified image in imgFname
%                   Converts in grayscale if needed.
%       Inputs:
%           imgFname,   filename of the image to georectify
%           rectFile,   .mat file created by g_rect
%       Parameters (name, value)
%           showTime,   Default 0, if 1, displays the timestamp of the
%                       image in the figure's title
%           showLand,   Default 0, if 'f' or 'h', displays the land contour
%                       with m_gshhs_f or m_gshhs_f
%           landcolor,  Default [241 235 144]/255, Color of the land on the
%                       map
%
%       Outputs:
%           h_figure, h_pcolor and h_datetext are the handles to the
%               corresponding objects in the figure, for use in g_viz_anim
%

show_time = 0;
show_land = 0;
land_color = [241 235 144]/255;
if length(varargin) > 1
    for i=1:2:length(varargin)
        switch lower(varargin{i})
            case 'showtime'
                show_time = varargin{i+1};
            case 'showland'
                show_land = varargin{i+1};
            case 'landcolor'
                land_color = varargin{i+1};
        end
    end
end

Daniel Bourgault's avatar
Daniel Bourgault committed
37
38
39
40
41
42

% Set some plotting parameters
ms = 10;  % Marker Size
fs = 10;  % Font size
lw = 2;  % Line width

Pascal Bourgault's avatar
Pascal Bourgault committed
43
load(rectFile);
Daniel Bourgault's avatar
Daniel Bourgault committed
44

Pascal Bourgault's avatar
Pascal Bourgault committed
45
%p = size(LON,3);
Daniel Bourgault's avatar
Daniel Bourgault committed
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63

lon_min = min(lon_gcp);
lon_max = max(lon_gcp);
lat_min = min(lat_gcp);
lat_max = max(lat_gcp);
lon_min = min(lon_min,LON0);
lon_max = max(lon_max,LON0);
lat_min = min(lat_min,LAT0);
lat_max = max(lat_max,LAT0);

fac = 0.1;
lon_min= lon_min - fac*abs(lon_max-lon_min);
lon_max= lon_max + fac*abs(lon_max-lon_min);
lat_min= lat_min - fac*abs(lat_max-lat_min);
lat_max= lat_max + fac*abs(lat_max-lat_min);

rgb0 = double(imread(imgFname))/255;

Pascal Bourgault's avatar
Pascal Bourgault committed
64
pp = size(rgb0,3);
Daniel Bourgault's avatar
Daniel Bourgault committed
65
if pp == 3
Pascal Bourgault's avatar
Pascal Bourgault committed
66
  int = g_rgb2gray(rgb0); 
Daniel Bourgault's avatar
Daniel Bourgault committed
67
68
69
70
71
72
73
74
else
  int = rgb0;     
end
clear rgb0;
int = int';

int = int - nanmean(nanmean(int));

Pascal Bourgault's avatar
Pascal Bourgault committed
75

Daniel Bourgault's avatar
Daniel Bourgault committed
76
77
78
79
80

m_proj('mercator','longitudes',[lon_min lon_max],'latitudes',[lat_min lat_max]);
hold on;

[X,Y] = m_ll2xy(LON,LAT);
Pascal Bourgault's avatar
Pascal Bourgault committed
81
82
cmap = contrast(int,256);
colormap(cmap);
Daniel Bourgault's avatar
Daniel Bourgault committed
83
84
85
86
87
h = pcolor(X,Y,int);
shading('interp');


% Uncomment one of these lines if you want the coastline to be pltoted.
Pascal Bourgault's avatar
Pascal Bourgault committed
88
89
90
91
92
93
94
if show_land
    if strcmpi(show_land,'f')
        m_gshhs_f('patch',land_color)
    else
        m_gshhs_h('patch',land_color)
    end
end
Daniel Bourgault's avatar
Daniel Bourgault committed
95

Pascal Bourgault's avatar
Pascal Bourgault committed
96
97
98
99
100
101
102
103
104
105
106
if show_time
    info = imfinfo(imgFname);
    if isField(info,'DateTime')
        date = info.DateTime;
    elseif isField(info,'Comment')
        date = info.Comment;
    else
        date = '';
    end
    ht = title(date);
end
Daniel Bourgault's avatar
Daniel Bourgault committed
107
108
109
110
111
112
113
114
115
116
117
118
119
m_plot(LON0,LAT0,'kx','markersize',ms,'linewidth',lw);  % Camera location

%% Plot GCPs and ICPs.
for n=1:length(i_gcp)
  m_plot(lon_gcp(n),lat_gcp(n),'bo','markersize',ms,'linewidth',lw);
  m_plot(LON(i_gcp(n),j_gcp(n)),LAT(i_gcp(n),j_gcp(n)),'rx','MarkerSize',ms,'linewidth',lw);
end

%title([datestr(mtime,31),' UTC']);
%title([time,' UTC']);

clear LON LAT X Y

Pascal Bourgault's avatar
Pascal Bourgault committed
120
121
122
123
124
125
126
127
128
m_grid('box','fancy','fontsize',fs);

if nargout > 1
    h_figure = gcf;
    h_pcolor = h;
    if nargout == 3
        h_datetext = ht;
    end
end