Commit f83fc5a2d39e516019b5c1efc3c9614605f9d7c3

Authored by Pascal Bourgault
1 parent 6508a91f
Exists in master

Ajout de paramètres optionnels pour g_viz_field et g_stabilize + un GUI pour g_rect.

src/g_rect/g_rect_paramsGui.fig 0 → 100644
No preview for this file type
src/g_rect/g_rect_paramsGui.m 0 → 100644
... ... @@ -0,0 +1,725 @@
  1 +function varargout = g_rect_paramsGui(varargin)
  2 +% G_RECT_PARAMSGUI MATLAB code for g_rect_paramsGui.fig
  3 +% G_RECT_PARAMSGUI, Open a GUI for easily add GCP points and creat the
  4 +% parameters.dat file required by g_rect. It supports two folders of
  5 +% images at the same time, one of raw images and one of stabilized
  6 +% images (sometimes finding the boat is easier on the colored raw, but
  7 +% you need the precision of the stabilized images.)
  8 +% To open a folder, you need to choose an example image. Image
  9 +% filenames must contain only one string of numbers of constant length.
  10 +% Example: IMG_3456.jpg and IMG_0011.jpg
  11 +% or 342_img.png and 001_img.png
  12 +%
  13 +% The GPS file in input must be one of the two:
  14 +% Text file: 4 Columns : Lat; Lon; Date (yyyymmdd),; Time (HHMMSS)
  15 +% Mat file: one variable named Coord with 3 columns:
  16 +% Lat; Lon; Time (datenum from the same reference year as the pictures, usually 0)
  17 +%
  18 +% The choosed points may be shown on a map, defaults lat lon limits
  19 +% are for Pointe-Aux-Crêpes. This needs the m_map toolbox.
  20 +% Once all GCP are chosen, the next step button shows a dialog with all
  21 +% the parameters needed for the parameters.dat file.
  22 +%
  23 +% See also: GUIDE, GUIDATA, GUIHANDLES
  24 +% Last Modified by GUIDE v2.5 04-Aug-2015 11:42:15
  25 +
  26 +% Begin initialization code - DO NOT EDIT
  27 +gui_Singleton = 1;
  28 +gui_State = struct('gui_Name', mfilename, ...
  29 + 'gui_Singleton', gui_Singleton, ...
  30 + 'gui_OpeningFcn', @g_rect_paramsGui_OpeningFcn, ...
  31 + 'gui_OutputFcn', @g_rect_paramsGui_OutputFcn, ...
  32 + 'gui_LayoutFcn', [] , ...
  33 + 'gui_Callback', []);
  34 +if nargin && ischar(varargin{1})
  35 + gui_State.gui_Callback = str2func(varargin{1});
  36 +end
  37 +
  38 +if nargout
  39 + [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
  40 +else
  41 + gui_mainfcn(gui_State, varargin{:});
  42 +end
  43 +% End initialization code - DO NOT EDIT
  44 +
  45 +
  46 +% --- Executes just before g_rect_paramsGui is made visible.
  47 +function g_rect_paramsGui_OpeningFcn(hObject, eventdata, handles, varargin)
  48 +% This function has no output args, see OutputFcn.
  49 +% hObject handle to figure
  50 +% eventdata reserved - to be defined in a future version of MATLAB
  51 +% handles structure with handles and user data (see GUIDATA)
  52 +% varargin command line arguments to g_rect_paramsGui (see VARARGIN)
  53 +
  54 +% Choose default command line output for g_rect_paramsGui
  55 +handles.output = hObject;
  56 +set(handles.tblPoints,'data',{})
  57 +% Update handles structure
  58 +guidata(hObject, handles);
  59 +
  60 +% UIWAIT makes g_rect_paramsGui wait for user response (see UIRESUME)
  61 +% uiwait(handles.mainWindow);
  62 +
  63 +
  64 +% --- Outputs from this function are returned to the command line.
  65 +function varargout = g_rect_paramsGui_OutputFcn(hObject, eventdata, handles)
  66 +% varargout cell array for returning output args (see VARARGOUT);
  67 +% hObject handle to figure
  68 +% eventdata reserved - to be defined in a future version of MATLAB
  69 +% handles structure with handles and user data (see GUIDATA)
  70 +
  71 +% Get default command line output from handles structure
  72 +varargout{1} = handles.output;
  73 +
  74 +
  75 +
  76 +function edRawFol_Callback(hObject, eventdata, handles)
  77 +% hObject handle to edRawFol (see GCBO)
  78 +% eventdata reserved - to be defined in a future version of MATLAB
  79 +% handles structure with handles and user data (see GUIDATA)
  80 +% Hints: get(hObject,'String') returns contents of edRawFol as text
  81 +% str2double(get(hObject,'String')) returns contents of edRawFol as a double
  82 +
  83 +
  84 +% --- Executes during object creation, after setting all properties.
  85 +function edRawFol_CreateFcn(hObject, eventdata, handles)
  86 +% hObject handle to edRawFol (see GCBO)
  87 +% eventdata reserved - to be defined in a future version of MATLAB
  88 +% handles empty - handles not created until after all CreateFcns called
  89 +
  90 +% Hint: edit controls usually have a white background on Windows.
  91 +% See ISPC and COMPUTER.
  92 +if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  93 + set(hObject,'BackgroundColor','white');
  94 +end
  95 +
  96 +
  97 +% --- Executes on button press in btnRawFolChng.
  98 +function btnRawFolChng_Callback(hObject, eventdata, handles)
  99 +% hObject handle to btnRawFolChng (see GCBO)
  100 +% eventdata reserved - to be defined in a future version of MATLAB
  101 +% handles structure with handles and user data (see GUIDATA)
  102 +[refFile, newFolder] = uigetfile({'*.jpg;*.tif;*.png;*.gif','All Image Files';'*.*','All Files' },'Select one of the Raw images');
  103 +set(handles.edRawFol,'String',newFolder)
  104 +[fmt, num, tot, maxi,mini] = extractFmtNum(refFile,newFolder);
  105 +set(handles.edRawFmt,'String',fmt)
  106 +if ~isfield(handles,'refFile')
  107 + handles.refFile = num;
  108 +end
  109 +set(handles.edNumImage,'String',num2str(num));
  110 +set(handles.txOfImage,'String',sprintf('in %d image files',tot))
  111 +
  112 +set(handles.sliImage,'Max',maxi)
  113 +set(handles.sliImage,'Value',num)
  114 +set(handles.sliImage,'Min',mini)
  115 +set(handles.sliImage, 'SliderStep', [1/tot , 10/tot ]);
  116 +handles.ImMode = 0;
  117 +set(handles.btnStbImage,'String','Show stabilized')
  118 +guidata(hObject,handles)
  119 +update_Imfig(handles,hObject);
  120 +
  121 +
  122 +
  123 +
  124 +function edRawFmt_Callback(hObject, eventdata, handles)
  125 +% hObject handle to edRawFmt (see GCBO)
  126 +% eventdata reserved - to be defined in a future version of MATLAB
  127 +% handles structure with handles and user data (see GUIDATA)
  128 +% Hints: get(hObject,'String') returns contents of edRawFmt as text
  129 +% str2double(get(hObject,'String')) returns contents of edRawFmt as a double
  130 +
  131 +
  132 +% --- Executes during object creation, after setting all properties.
  133 +function edRawFmt_CreateFcn(hObject, eventdata, handles)
  134 +% hObject handle to edRawFmt (see GCBO)
  135 +% eventdata reserved - to be defined in a future version of MATLAB
  136 +% handles empty - handles not created until after all CreateFcns called
  137 +
  138 +% Hint: edit controls usually have a white background on Windows.
  139 +% See ISPC and COMPUTER.
  140 +if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  141 + set(hObject,'BackgroundColor','white');
  142 +end
  143 +
  144 +
  145 +
  146 +function edStbFol_Callback(hObject, eventdata, handles)
  147 +% hObject handle to edStbFol (see GCBO)
  148 +% eventdata reserved - to be defined in a future version of MATLAB
  149 +% handles structure with handles and user data (see GUIDATA)
  150 +% Hints: get(hObject,'String') returns contents of edStbFol as text
  151 +% str2double(get(hObject,'String')) returns contents of edStbFol as a double
  152 +
  153 +
  154 +% --- Executes during object creation, after setting all properties.
  155 +function edStbFol_CreateFcn(hObject, eventdata, handles)
  156 +% hObject handle to edStbFol (see GCBO)
  157 +% eventdata reserved - to be defined in a future version of MATLAB
  158 +% handles empty - handles not created until after all CreateFcns called
  159 +
  160 +% Hint: edit controls usually have a white background on Windows.
  161 +% See ISPC and COMPUTER.
  162 +if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  163 + set(hObject,'BackgroundColor','white');
  164 +end
  165 +
  166 +
  167 +% --- Executes on button press in btnStbFolChng.
  168 +function btnStbFolChng_Callback(hObject, eventdata, handles)
  169 +% hObject handle to btnStbFolChng (see GCBO)
  170 +% eventdata reserved - to be defined in a future version of MATLAB
  171 +% handles structure with handles and user data (see GUIDATA)
  172 +[refFile, newFolder] = uigetfile({'*.jpg;*.tif;*.png;*.gif','All Image Files';'*.*','All Files' },'Select one of the stabilized images');
  173 +set(handles.edStbFol,'String',newFolder)
  174 +[fmt, num, tot, maxi, mini] = extractFmtNum(refFile,newFolder);
  175 +set(handles.edStbFmt,'String',fmt)
  176 +handles.refFile = num;
  177 +set(handles.edNumImage,'String',num2str(num));
  178 +set(handles.txOfImage,'String',sprintf('in %d image files',tot))
  179 +
  180 +set(handles.sliImage,'Max',maxi)
  181 +set(handles.sliImage,'Value',num)
  182 +set(handles.sliImage,'Min',mini)
  183 +set(handles.sliImage, 'SliderStep', [1/tot , 10/tot ]);
  184 +handles.ImMode = 1;
  185 +set(handles.btnStbImage,'String','Show raw')
  186 +guidata(hObject,handles)
  187 +update_Imfig(handles,hObject);
  188 +
  189 +
  190 +function edStbFmt_Callback(hObject, eventdata, handles)
  191 +% hObject handle to edStbFmt (see GCBO)
  192 +% eventdata reserved - to be defined in a future version of MATLAB
  193 +% handles structure with handles and user data (see GUIDATA)
  194 +% Hints: get(hObject,'String') returns contents of edStbFmt as text
  195 +% str2double(get(hObject,'String')) returns contents of edStbFmt as a double
  196 +
  197 +
  198 +% --- Executes during object creation, after setting all properties.
  199 +function edStbFmt_CreateFcn(hObject, eventdata, handles)
  200 +% hObject handle to edStbFmt (see GCBO)
  201 +% eventdata reserved - to be defined in a future version of MATLAB
  202 +% handles empty - handles not created until after all CreateFcns called
  203 +% Hint: edit controls usually have a white background on Windows.
  204 +% See ISPC and COMPUTER.
  205 +if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  206 + set(hObject,'BackgroundColor','white');
  207 +end
  208 +
  209 +
  210 +
  211 +function edGPSfile_Callback(hObject, eventdata, handles)
  212 +% hObject handle to edGPSfile (see GCBO)
  213 +% eventdata reserved - to be defined in a future version of MATLAB
  214 +% handles structure with handles and user data (see GUIDATA)
  215 +% Hints: get(hObject,'String') returns contents of edGPSfile as text
  216 +% str2double(get(hObject,'String')) returns contents of edGPSfile as a double
  217 +
  218 +
  219 +% --- Executes during object creation, after setting all properties.
  220 +function edGPSfile_CreateFcn(hObject, eventdata, handles)
  221 +% hObject handle to edGPSfile (see GCBO)
  222 +% eventdata reserved - to be defined in a future version of MATLAB
  223 +% handles empty - handles not created until after all CreateFcns called
  224 +
  225 +% Hint: edit controls usually have a white background on Windows.
  226 +% See ISPC and COMPUTER.
  227 +if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  228 + set(hObject,'BackgroundColor','white');
  229 +end
  230 +
  231 +
  232 +% --- Executes on button press in btnLoadGPS.
  233 +function btnLoadGPS_Callback(hObject, eventdata, handles)
  234 +% hObject handle to btnLoadGPS (see GCBO)
  235 +% eventdata reserved - to be defined in a future version of MATLAB
  236 +% handles structure with handles and user data (see GUIDATA)
  237 +[gpsfile, newFolder] = uigetfile({'*.txt;*.mat','Text of mat files';'*.*','All files'},'Select the boat GPS log file (text or mat)');
  238 +try
  239 +if strcmp(gpsfile(end-3:end),'mat')
  240 + handles.Coord = load(fullfile(newFolder,gpsfile),'Coord');
  241 +else
  242 + f = fopen(fullfile(newFolder,gpsfile),'r');
  243 + data = textscan(f,'%n%n%s%s','delimiter',',','commentstyle','#');
  244 + fclose(f);
  245 + handles.Coord = [data{1} data{2} arrayfun(@(x,y) datenum([x{1} y{1}],'yyyymmddHHMMSS'),data{3},data{4})];
  246 +end
  247 +set(hObject,'String','GPS Loaded')
  248 +end
  249 +guidata(hObject,handles)
  250 +
  251 +% --- Executes on slider movement.
  252 +function sliImage_Callback(hObject, eventdata, handles)
  253 +% hObject handle to sliImage (see GCBO)
  254 +% eventdata reserved - to be defined in a future version of MATLAB
  255 +% handles structure with handles and user data (see GUIDATA)
  256 +% Hints: get(hObject,'Value') returns position of slider
  257 +% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
  258 +num = round(get(hObject,'Value'));
  259 +set(handles.edNumImage,'String',num2str(num))
  260 +guidata(hObject,handles)
  261 +update_Imfig(handles,hObject)
  262 +
  263 +% --- Executes during object creation, after setting all properties.
  264 +function sliImage_CreateFcn(hObject, eventdata, handles)
  265 +% hObject handle to sliImage (see GCBO)
  266 +% eventdata reserved - to be defined in a future version of MATLAB
  267 +% handles empty - handles not created until after all CreateFcns called
  268 +
  269 +% Hint: slider controls usually have a light gray background.
  270 +if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  271 + set(hObject,'BackgroundColor',[.9 .9 .9]);
  272 +end
  273 +
  274 +
  275 +
  276 +function edNumImage_Callback(hObject, eventdata, handles)
  277 +% hObject handle to edNumImage (see GCBO)
  278 +% eventdata reserved - to be defined in a future version of MATLAB
  279 +% handles structure with handles and user data (see GUIDATA)
  280 +% Hints: get(hObject,'String') returns contents of edNumImage as text
  281 +% str2double(get(hObject,'String')) returns contents of edNumImage as a double
  282 +try
  283 + set(handles.sliImage,'Value',str2double(get(hObject,'String')))
  284 +
  285 + guidata(hObject,handles)
  286 + update_Imfig(handles,hObject)
  287 +end
  288 +
  289 +% --- Executes during object creation, after setting all properties.
  290 +function edNumImage_CreateFcn(hObject, eventdata, handles)
  291 +% hObject handle to edNumImage (see GCBO)
  292 +% eventdata reserved - to be defined in a future version of MATLAB
  293 +% handles empty - handles not created until after all CreateFcns called
  294 +
  295 +% Hint: edit controls usually have a white background on Windows.
  296 +% See ISPC and COMPUTER.
  297 +if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  298 + set(hObject,'BackgroundColor','white');
  299 +end
  300 +
  301 +
  302 +% --- Executes on button press in btnStbImage.
  303 +function btnStbImage_Callback(hObject, eventdata, handles)
  304 +% hObject handle to btnStbImage (see GCBO)
  305 +% eventdata reserved - to be defined in a future version of MATLAB
  306 +% handles structure with handles and user data (see GUIDATA)
  307 +if handles.ImMode
  308 + set(hObject,'String','Show raw')
  309 + handles.ImMode = 0;
  310 +else
  311 + set(hObject,'String','Show stabilized')
  312 + handles.ImMode = 1;
  313 +end
  314 +guidata(hObject,handles)
  315 +update_Imfig(handles,hObject);
  316 +
  317 +% --- Executes on button press in btnAddBoat.
  318 +function btnAddBoat_Callback(hObject, eventdata, handles)
  319 +% hObject handle to btnAddBoat (see GCBO)
  320 +% eventdata reserved - to be defined in a future version of MATLAB
  321 +% handles structure with handles and user data (see GUIDATA)
  322 +if isfield(handles,'imFig') && isfield(handles,'CurDateTime') && isfield(handles,'Coord')
  323 + figure(handles.imFig)
  324 + [x, y] = ginput(1);
  325 + x = round(x); y = round(y);
  326 + iGps = near(handles.CurDateTime,handles.Coord(:,3));
  327 + Data = get(handles.tblPoints,'Data');
  328 + Data(end+1,:) = {str2double(get(handles.edNumImage,'String')),...
  329 + datestr(handles.CurDateTime,'yyyymmddTHHMMSS'),x,y,handles.Coord(iGps,1),handles.Coord(iGps,2)};
  330 + set(handles.tblPoints,'data',Data)
  331 + guidata(hObject,handles)
  332 +end
  333 +
  334 +% --- Executes on button press in btnAdd.
  335 +function btnAdd_Callback(hObject, eventdata, handles)
  336 +% hObject handle to btnAdd (see GCBO)
  337 +% eventdata reserved - to be defined in a future version of MATLAB
  338 +% handles structure with handles and user data (see GUIDATA)
  339 +if isfield(handles,'imFig')
  340 + figure(handles.imFig)
  341 + [x, y] = ginput(1);
  342 + x = round(x); y = round(y);
  343 + Data = get(handles.tblPoints,'Data');
  344 + try
  345 + das = datestr(handles.CurDateTime,'YYYYMMDDTHHMMSS');
  346 + catch
  347 + das = '';
  348 + end
  349 + Data(end+1,:) = {str2double(get(handles.edNumImage,'String')),das,x,y,0,0};
  350 + set(handles.tblPoints,'data',Data)
  351 + guidata(hObject,handles)
  352 +end
  353 +
  354 +
  355 +function edLatMax_Callback(hObject, eventdata, handles)
  356 +% hObject handle to edLatMax (see GCBO)
  357 +% eventdata reserved - to be defined in a future version of MATLAB
  358 +% handles structure with handles and user data (see GUIDATA)
  359 +% Hints: get(hObject,'String') returns contents of edLatMax as text
  360 +% str2double(get(hObject,'String')) returns contents of edLatMax as a double
  361 +
  362 +
  363 +% --- Executes during object creation, after setting all properties.
  364 +function edLatMax_CreateFcn(hObject, eventdata, handles)
  365 +% hObject handle to edLatMax (see GCBO)
  366 +% eventdata reserved - to be defined in a future version of MATLAB
  367 +% handles empty - handles not created until after all CreateFcns called
  368 +% Hint: edit controls usually have a white background on Windows.
  369 +% See ISPC and COMPUTER.
  370 +if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  371 + set(hObject,'BackgroundColor','white');
  372 +end
  373 +
  374 +
  375 +
  376 +function edLonMax_Callback(hObject, eventdata, handles)
  377 +% hObject handle to edLonMax (see GCBO)
  378 +% eventdata reserved - to be defined in a future version of MATLAB
  379 +% handles structure with handles and user data (see GUIDATA)
  380 +% Hints: get(hObject,'String') returns contents of edLonMax as text
  381 +% str2double(get(hObject,'String')) returns contents of edLonMax as a double
  382 +
  383 +
  384 +% --- Executes during object creation, after setting all properties.
  385 +function edLonMax_CreateFcn(hObject, eventdata, handles)
  386 +% hObject handle to edLonMax (see GCBO)
  387 +% eventdata reserved - to be defined in a future version of MATLAB
  388 +% handles empty - handles not created until after all CreateFcns called
  389 +% Hint: edit controls usually have a white background on Windows.
  390 +% See ISPC and COMPUTER.
  391 +if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  392 + set(hObject,'BackgroundColor','white');
  393 +end
  394 +
  395 +
  396 +
  397 +function edLonMin_Callback(hObject, eventdata, handles)
  398 +% hObject handle to edLonMin (see GCBO)
  399 +% eventdata reserved - to be defined in a future version of MATLAB
  400 +% handles structure with handles and user data (see GUIDATA)
  401 +% Hints: get(hObject,'String') returns contents of edLonMin as text
  402 +% str2double(get(hObject,'String')) returns contents of edLonMin as a double
  403 +
  404 +
  405 +% --- Executes during object creation, after setting all properties.
  406 +function edLonMin_CreateFcn(hObject, eventdata, handles)
  407 +% hObject handle to edLonMin (see GCBO)
  408 +% eventdata reserved - to be defined in a future version of MATLAB
  409 +% handles empty - handles not created until after all CreateFcns called
  410 +% Hint: edit controls usually have a white background on Windows.
  411 +% See ISPC and COMPUTER.
  412 +if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  413 + set(hObject,'BackgroundColor','white');
  414 +end
  415 +
  416 +
  417 +
  418 +function edLatMin_Callback(hObject, eventdata, handles)
  419 +% hObject handle to edLatMin (see GCBO)
  420 +% eventdata reserved - to be defined in a future version of MATLAB
  421 +% handles structure with handles and user data (see GUIDATA)
  422 +% Hints: get(hObject,'String') returns contents of edLatMin as text
  423 +% str2double(get(hObject,'String')) returns contents of edLatMin as a double
  424 +
  425 +
  426 +% --- Executes during object creation, after setting all properties.
  427 +function edLatMin_CreateFcn(hObject, eventdata, handles)
  428 +% hObject handle to edLatMin (see GCBO)
  429 +% eventdata reserved - to be defined in a future version of MATLAB
  430 +% handles empty - handles not created until after all CreateFcns called
  431 +% Hint: edit controls usually have a white background on Windows.
  432 +% See ISPC and COMPUTER.
  433 +if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  434 + set(hObject,'BackgroundColor','white');
  435 +end
  436 +
  437 +
  438 +% --- Executes on button press in btnMap.
  439 +function btnMap_Callback(hObject, eventdata, handles)
  440 +% hObject handle to btnMap (see GCBO)
  441 +% eventdata reserved - to be defined in a future version of MATLAB
  442 +% handles structure with handles and user data (see GUIDATA)
  443 +try
  444 + lat_min = str2double(get(handles.edLatMin,'String'));
  445 + lat_max = str2double(get(handles.edLatMax,'String'));
  446 + lon_min = str2double(get(handles.edLonMin,'String'));
  447 + lon_max = str2double(get(handles.edLonMax,'String'));
  448 +catch
  449 + return
  450 +end
  451 +handles.mapFig = figure;
  452 +m_proj('mercator','longitudes',[lon_min lon_max],'latitudes',[lat_min lat_max]);
  453 +hold on
  454 +
  455 +switch get(get(handles.panGshhs,'SelectedObject'),'tag')
  456 + case 'rbFull'
  457 + m_gshhs_f('patch',[210 180 140]/255)
  458 + case 'rbHigh'
  459 + m_gshhs_h('patch',[210 180 140]/255)
  460 +end
  461 +m_grid('box','fancy','fontsize',12);
  462 +guidata(hObject,handles)
  463 +update_pts(handles,hObject)
  464 +
  465 +
  466 +
  467 +
  468 +function update_Imfig(handles,hObject)
  469 +if handles.ImMode
  470 + ImFile = fullfile(get(handles.edStbFol,'String'),sprintf(get(handles.edStbFmt,'String'),str2double(get(handles.edNumImage,'String'))));
  471 +else
  472 + ImFile = fullfile(get(handles.edRawFol,'String'),sprintf(get(handles.edRawFmt,'String'),str2double(get(handles.edNumImage,'String'))));
  473 +end
  474 +if exist(ImFile,'file')
  475 + ImData = imread(ImFile);
  476 + handles.CurDateTime = getDateTime(ImFile);
  477 + if ~isfield(handles,'imFig')
  478 + handles.imFig = figure;
  479 + colormap(gray(256));
  480 + handles.imIm = imagesc(ImData);
  481 + handles.imTi = title(datestr(handles.CurDateTime,'dd mmm yyyy, HH:MM:SS'));
  482 + else
  483 + figure(handles.imFig)
  484 + set(handles.imIm,'CData',ImData)
  485 + set(handles.imTi,'String',datestr(handles.CurDateTime,'dd mmm yyyy, HH:MM:SS'))
  486 + end
  487 +else
  488 + set(handles.imIm,'CData',zeros(40,40))
  489 + set(handles.imTi,'String',sprintf('There is no image named %s',ImFile))
  490 +end
  491 +guidata(hObject,handles)
  492 +update_pts(handles,hObject)
  493 +
  494 +function datetime = getDateTime(ImFile)
  495 +info = imfinfo(ImFile);
  496 +if isfield(info,'DateTime')
  497 + datetime = datenum(info.DateTime,'yyyy:mm:dd HH:MM:SS');
  498 +elseif isfield(info,'Comment')
  499 + try
  500 + datetime = datenum(info.Comment,'yyyy:mm:dd HH:MM:SS');
  501 + catch
  502 + datetime = 0;
  503 + end
  504 +else
  505 + datetime = 0;
  506 +end
  507 +
  508 +
  509 +function [filefmt, num,tot,maxi, mini] = extractFmtNum(filename, foldername)
  510 +indsNum = regexp(filename,'[0-9]');
  511 +if diff(indsNum) == 1;
  512 + filefmt = [filename(1:indsNum(1)-1) '%0' num2str(length(indsNum)) '.0f' filename(indsNum(end)+1:end)];
  513 + num = str2double(filename(indsNum));
  514 + files = dir(foldername);
  515 + tot = 0;
  516 + maxi = 0;
  517 + mini = Inf;
  518 + for i=1:length(files)
  519 + try
  520 + if regexp(files(i).name,'[0-9]') == indsNum
  521 + if strcmp(files(i).name(indsNum(end)+1:end),filename(indsNum(end)+1:end))
  522 + if strcmp(files(i).name(1:indsNum(1)-1),filename(1:indsNum(1)-1))
  523 + tot = tot+1;
  524 + maxi = max([maxi str2double(files(i).name(indsNum))]);
  525 + mini = min([mini str2double(files(i).name(indsNum))]);
  526 + end
  527 + end
  528 + end
  529 + end
  530 + end
  531 +else
  532 + filefmt = filename;
  533 + num = 1;
  534 +end
  535 +
  536 +function update_pts(handles, hObject)
  537 +data = get(handles.tblPoints,'data');
  538 +if isfield(handles,'imFig')
  539 + figure(handles.imFig)
  540 + hold on
  541 + if isfield(handles,'imPtsHandles') && isfield(handles,'imTxtHandles')
  542 + try
  543 + delete(handles.imPtsHandles)
  544 + delete(handles.imTxtHandles)
  545 + end
  546 + handles.imPtsHandles = zeros(size(data,1),1);
  547 + handles.imTxtHandles = zeros(size(data,1),1);
  548 + end
  549 + for i=1:size(data,1)
  550 + handles.imPtsHandles(i) = plot(data{i,3},data{i,4},'ro');
  551 + handles.imTxtHandles(i) = text(data{i,3},data{i,4},num2str(i));
  552 + end
  553 +end
  554 +if isfield(handles,'mapFig')
  555 + figure(handles.mapFig)
  556 + hold on
  557 + if isfield(handles,'mapPtsHandles') && isfield(handles,'mapTxtHandles')
  558 + try
  559 + delete(handles.mapPtsHandles)
  560 + delete(handles.mapTxtHandles)
  561 + end
  562 + handles.mapPtsHandles = zeros(size(data,1),1);
  563 + handles.mapTxtHandles = zeros(size(data,1),1);
  564 + end
  565 + for i=1:size(data,1)
  566 + handles.mapPtsHandles(i) = m_plot(data{i,6},data{i,5},'ro');
  567 + handles.mapTxtHandles(i) = m_text(data{i,6},data{i,5},num2str(i));
  568 + end
  569 +end
  570 +guidata(hObject,handles)
  571 +
  572 +
  573 +% --- Executes on button press in btnRemove.
  574 +function btnRemove_Callback(hObject, eventdata, handles)
  575 +% hObject handle to btnRemove (see GCBO)
  576 +% eventdata reserved - to be defined in a future version of MATLAB
  577 +% handles structure with handles and user data (see GUIDATA)
  578 +if isfield(handles,'selected')
  579 + data = get(handles.tblPoints,'data');
  580 + reminds = handles.selected(:,1);
  581 + inds = setxor(1:size(data,1),reminds);
  582 + data = data(inds,:);
  583 + set(handles.tblPoints,'data',data)
  584 +end
  585 +guidata(hObject,handles)
  586 +update_pts(handles,hObject)
  587 +
  588 +function [ind valOut] = near(valIn, vecIn)
  589 + [~,ind] = min(abs(vecIn-valIn));
  590 + valOut = vecIn(ind);
  591 +
  592 +
  593 +% --- Executes when selected cell(s) is changed in tblPoints.
  594 +function tblPoints_CellSelectionCallback(hObject, eventdata, handles)
  595 +% hObject handle to tblPoints (see GCBO)
  596 +% eventdata structure with the following fields (see UITABLE)
  597 +% Indices: row and column indices of the cell(s) currently selecteds
  598 +% handles structure with handles and user data (see GUIDATA)
  599 +handles.selected = eventdata.Indices;
  600 +guidata(hObject,handles)
  601 +
  602 +
  603 +% --- Executes on button press in btnFinish.
  604 +function btnFinish_Callback(hObject, eventdata, handles)
  605 +% hObject handle to btnFinish (see GCBO)
  606 +% eventdata reserved - to be defined in a future version of MATLAB
  607 +% handles structure with handles and user data (see GUIDATA)
  608 +set(handles.mainWindow,'visible','off')
  609 +if handles.ImMode
  610 + files = {get(handles.edStbFol,'String'),get(handles.edStbFmt,'String')};
  611 +else
  612 + files = {get(handles.edRawFol,'String'),get(handles.edRawFmt,'String')};
  613 +end
  614 +handles.f = figure('Visible','off','Position',[360,500,400,436],'Name','Last metadata!');
  615 +
  616 +uicontrol('Style','text','String','imgFname: ','Position',[5 400 85 22],'HorizontalAlignment','right');
  617 +handles.imgFname = uicontrol('Style','edit','String',sprintf(['%s' files{2}],files{1},handles.refFile),'Position',[95 400 300 22],'HorizontalAlignment','right');
  618 +
  619 +uicontrol('Style','text','String','firstimgFname: ','Position',[5 372 85 22],'HorizontalAlignment','right');
  620 +handles.firstimgFname = uicontrol('Style','edit','String',sprintf(['%s' files{2}],files{1},get(handles.sliImage,'Min')),'Position',[95 372 300 22],'HorizontalAlignment','right');
  621 +
  622 +uicontrol('Style','text','String','lastimgFname: ','Position',[5 344 85 22],'HorizontalAlignment','right');
  623 +handles.lastimgFname = uicontrol('Style','edit','String',sprintf(['%s' files{2}],files{1},get(handles.sliImage,'Max')),'Position',[95 344 300 22],'HorizontalAlignment','right');
  624 +
  625 +uicontrol('Style','text','String','outputFname: ','Position',[5 316 85 22],'HorizontalAlignment','right');
  626 +handles.outputFname = uicontrol('Style','edit','String','IMG_rect.mat','Position',[95 316 300 22],'HorizontalAlignment','right');
  627 +
  628 +handles.field = uicontrol('Style','checkbox','String','field','Position',[175 288 150 22],'Value',1);
  629 +
  630 +uicontrol('Style','text','String','Camera position:','Position',[5 288 145 22],'HorizontalAlignment','left');
  631 +
  632 +uicontrol('Style','text','String','Lon: ','Position',[20 260 50 22],'HorizontalAlignment','right');
  633 +handles.LON0 = uicontrol('Style','edit','String','','Position',[75 260 100 22],'HorizontalAlignment','right');
  634 +uicontrol('Style','text','String','Lat: ','Position',[175 260 50 22],'HorizontalAlignment','right');
  635 +handles.LAT0 = uicontrol('Style','edit','String','','Position',[230 260 100 22],'HorizontalAlignment','right');
  636 +
  637 +uicontrol('Style','text','String','Offset ic: ','Position',[20 232 50 22],'HorizontalAlignment','right');
  638 +handles.ic = uicontrol('Style','edit','String','0','Position',[75 232 100 22],'HorizontalAlignment','right');
  639 +uicontrol('Style','text','String','Offset jc: ','Position',[175 232 50 22],'HorizontalAlignment','right');
  640 +handles.jc = uicontrol('Style','edit','String','0','Position',[230 232 100 22],'HorizontalAlignment','right');
  641 +
  642 +uicontrol('Style','text','String','hfov: ','Position',[20 204 50 22],'HorizontalAlignment','right');
  643 +handles.hfov = uicontrol('Style','edit','String','40','Position',[75 204 100 22],'HorizontalAlignment','right');
  644 +uicontrol('Style','text','String','dhfov: ','Position',[175 204 50 22],'HorizontalAlignment','right');
  645 +handles.dhfov = uicontrol('Style','edit','String','10','Position',[230 204 100 22],'HorizontalAlignment','right');
  646 +
  647 +uicontrol('Style','text','String','lambda: ','Position',[20 176 50 22],'HorizontalAlignment','right');
  648 +handles.lambda = uicontrol('Style','edit','String','5','Position',[75 176 100 22],'HorizontalAlignment','right');
  649 +uicontrol('Style','text','String','dlambda: ','Position',[175 176 50 22],'HorizontalAlignment','right');
  650 +handles.dlambda = uicontrol('Style','edit','String','5','Position',[230 176 100 22],'HorizontalAlignment','right');
  651 +
  652 +uicontrol('Style','text','String','phi: ','Position',[20 148 50 22],'HorizontalAlignment','right');
  653 +handles.phi = uicontrol('Style','edit','String','0','Position',[75 148 100 22],'HorizontalAlignment','right');
  654 +uicontrol('Style','text','String','dphi: ','Position',[175 148 50 22],'HorizontalAlignment','right');
  655 +handles.dphi = uicontrol('Style','edit','String','5','Position',[230 148 100 22],'HorizontalAlignment','right');
  656 +
  657 +uicontrol('Style','text','String','H: ','Position',[20 120 50 22],'HorizontalAlignment','right');
  658 +handles.H = uicontrol('Style','edit','String','155','Position',[75 120 100 22],'HorizontalAlignment','right');
  659 +uicontrol('Style','text','String','dH: ','Position',[175 120 50 22],'HorizontalAlignment','right');
  660 +handles.dH = uicontrol('Style','edit','String','20','Position',[230 120 100 22],'HorizontalAlignment','right');
  661 +
  662 +uicontrol('Style','text','String','theta: ','Position',[20 92 50 22],'HorizontalAlignment','right');
  663 +handles.theta = uicontrol('Style','edit','String','265','Position',[75 92 100 22],'HorizontalAlignment','right');
  664 +uicontrol('Style','text','String','dtheta: ','Position',[175 92 50 22],'HorizontalAlignment','right');
  665 +handles.dtheta = uicontrol('Style','edit','String','20','Position',[230 92 100 22],'HorizontalAlignment','right');
  666 +
  667 +uicontrol('Style','text','String','polyOrder: ','Position',[20 64 50 22],'HorizontalAlignment','right');
  668 +handles.polyOrder = uicontrol('Style','edit','String','0','Position',[75 64 100 22],'HorizontalAlignment','right');
  669 +uicontrol('Style','text','String','precision: ','Position',[175 64 50 22],'HorizontalAlignment','right');
  670 +handles.precision = uicontrol('Style','edit','String','double','Position',[230 64 100 22],'HorizontalAlignment','right');
  671 +
  672 +handles.btn = uicontrol('Style','pushbutton','String','Generate the paramters file','Position',[20 2 360 60],'Callback',{@finalstep,hObject});
  673 +
  674 +set(handles.f,'visible','on')
  675 +guidata(hObject,handles)
  676 +
  677 +function finalstep(hObject, eventdata, otherObject)
  678 +handles = guidata(otherObject);
  679 +set(handles.f,'visible','off')
  680 +[filename, pathname] = uiputfile({'*.dat;*.txt','All Text Files';'*.*','All Files' },'Find a place where to save the parameter file','parameters.dat');
  681 +f = fopen(fullfile(pathname,filename),'w');
  682 +fprintf(f,'%% I/O information\n');
  683 +fprintf(f,'imgFname = ''%s'';\n',get(handles.imgFname,'String'));
  684 +fprintf(f,'firstImgFname = ''%s'';\n',get(handles.firstimgFname,'String'));
  685 +fprintf(f,'lastImgFname = ''%s'';\n',get(handles.lastimgFname,'String'));
  686 +fprintf(f,'outputFname = ''%s'';\n',get(handles.outputFname,'String'));
  687 +fprintf(f,'\n%% Field or lab case situation. \n%% Set field = true for field situation and field = false for lab situation.\n');
  688 +if get(handles.field,'value')
  689 + fprintf(f,'field = true;\n');
  690 +else
  691 + fprintf(f,'field = false;\n');
  692 +end
  693 +fprintf(f,'\n%%Camera position\n%% lat/lon for field situation\n%% meter for lab situation\n');
  694 +fprintf(f,'LON0 = %s;\n',get(handles.LON0,'String'));
  695 +fprintf(f,'LAT0 = %s;\n',get(handles.LAT0,'String'));
  696 +
  697 +fprintf(f,'\n%% Offset from center of the principal point (generally zero)\n');
  698 +fprintf(f,'ic = %s;\njc = %s;\n',get(handles.ic,'String'),get(handles.jc,'String'));
  699 +fprintf(f,'\n%%Parameters\n');
  700 +fprintf(f,'hfov = %s; %% Field of view of the camera\n',get(handles.hfov,'String'));
  701 +fprintf(f,'lambda = %s; %% Dip angle below horizontal (e.g. straight down = 90, horizontal = 0) \n',get(handles.lambda,'String'));
  702 +fprintf(f,'phi = %s; %% Tilt angle (generally close to 0).\n',get(handles.phi,'String'));
  703 +fprintf(f,'H = %s; %% Camera altitude (m)\n',get(handles.H,'String'));
  704 +fprintf(f,'theta = %s; %% View angle anticlockwise from North (e.g. straight East = 270)\n',get(handles.theta,'String'));
  705 +
  706 +fprintf(f,'\n%% Uncertainty in parameters. Set the uncertainty to 0.0 for fixed parameters.\n');
  707 +fprintf(f,'dhfov = %s; \n',get(handles.dhfov,'String'));
  708 +fprintf(f,'dlambda = %s; \n',get(handles.dlambda,'String'));
  709 +fprintf(f,'dphi = %s; \n',get(handles.dphi,'String'));
  710 +fprintf(f,'dH = %s; \n',get(handles.dH,'String'));
  711 +fprintf(f,'dtheta = %s; \n',get(handles.dtheta,'String'));
  712 +
  713 +fprintf(f,'\n%% Order of the polynomial correction (0, 1 or 2)\n');
  714 +fprintf(f,'polyOrder = %s',get(handles.polyOrder,'String'));
  715 +fprintf(f,'\n%% To save memory calculation can be done in single precision.\n%% For higher precision set the variable ''precision'' to ''double''\n');
  716 +fprintf(f,'precision = ''%s'';\n',get(handles.precision,'String'));
  717 +fprintf(f,'\n%% Ground Control Points (GCP).\ngcpData = true;\n');
  718 +
  719 +data = get(handles.tblPoints,'data');
  720 +for i = 1:size(data,1)
  721 + fprintf(f,'%.0f %.0f %.8f %.8f\n',data{i,3},data{i,4},data{i,6},data{i,5});
  722 +end
  723 +fclose(f);
  724 +
  725 +close all
... ...
src/utilities/g_rgb2gray.m 0 → 100644
... ... @@ -0,0 +1,106 @@
  1 +function I = g_rgb2gray(X)
  2 +%G_RGB2GRAY Convert RGB image or colormap to grayscale.
  3 +% G_RGB2GRAY converts RGB images to grayscale by eliminating the
  4 +% hue and saturation information while retaining the
  5 +% luminance.
  6 +%
  7 +% If RGB2GRAY exists in the Matlab path, it overrides this function and
  8 +% uses the one from the toolbox instead.
  9 +%
  10 +% I = G_RGB2GRAY(RGB) converts the truecolor image RGB to the
  11 +% grayscale intensity image I.
  12 +%
  13 +% NEWMAP = G_RGB2GRAY(MAP) returns a grayscale colormap
  14 +% equivalent to MAP.
  15 +%
  16 +% Class Support
  17 +% -------------
  18 +% If the input is an RGB image, it can be uint8, uint16, double, or
  19 +% single. The output image I has the same class as the input image. If the
  20 +% input is a colormap, the input and output colormaps are both of class
  21 +% double.
  22 +%
  23 +% Example
  24 +% -------
  25 +% I = imread('board.tif');
  26 +% J = rgb2gray(I);
  27 +% figure, imshow(I), figure, imshow(J);
  28 +%
  29 +% [X,map] = imread('trees.tif');
  30 +% gmap = rgb2gray(map);
  31 +% figure, imshow(X,map), figure, imshow(X,gmap);
  32 +%
  33 +% See also IND2GRAY, NTSC2RGB, RGB2IND, RGB2NTSC, MAT2GRAY.
  34 +
  35 +% Original file: Copyright 1992-2013 The MathWorks, Inc.
  36 +% And some changes by me.
  37 +
  38 +if exist('rgb2gray','file')
  39 + I = rgb2gray(X);
  40 +else
  41 +X = parse_inputs(X);
  42 +origSize = size(X);
  43 +
  44 +% Determine if input includes a 3-D array
  45 +threeD = (ndims(X)==3);
  46 +
  47 +% Calculate transformation matrix
  48 +T = inv([1.0 0.956 0.621; 1.0 -0.272 -0.647; 1.0 -1.106 1.703]);
  49 +coef = T(1,:);
  50 +
  51 +if threeD
  52 + %RGB
  53 +
  54 + % Do transformation
  55 + if isa(X, 'double') || isa(X, 'single')
  56 +
  57 + % Shape input matrix so that it is a n x 3 array and initialize output matrix
  58 + X = reshape(X(:),origSize(1)*origSize(2),3);
  59 + sizeOutput = [origSize(1), origSize(2)];
  60 + I = X * coef';
  61 + I = min(max(I,0),1);
  62 +
  63 + %Make sure that the output matrix has the right size
  64 + I = reshape(I,sizeOutput);
  65 +
  66 + elseif isa(X,'uint8')
  67 + % Transforms to double to do the transformations as some functions are
  68 + % not available without the Image Processing toolbox.
  69 + I = uint8(g_rgb2gray(double(X)/255)*255);
  70 + elseif isa(X,'uint16')
  71 + I = uint16(g_rgb2gray(double(X)/255)*255);
  72 + end
  73 +
  74 +else
  75 + I = X * coef';
  76 + I = min(max(I,0),1);
  77 + I = [I,I,I];
  78 +end
  79 +
  80 +end
  81 +%%%
  82 +%Parse Inputs
  83 +%%%
  84 +function X = parse_inputs(X)
  85 +
  86 +
  87 +if ismatrix(X)
  88 + if (size(X,2) ~=3 || size(X,1) < 1)
  89 + error(' images:rgb2gray:invalidSizeForColormap')
  90 + end
  91 + if ~isa(X,'double')
  92 + error(' images:rgb2gray:notAValidColormap')
  93 + end
  94 +elseif (ndims(X)==3)
  95 + if ((size(X,3) ~= 3))
  96 + error(' images:rgb2gray:invalidInputSizeRGB')
  97 + end
  98 +else
  99 + error(' images:rgb2gray:invalidInputSize')
  100 +end
  101 +
  102 +
  103 +%no logical arrays
  104 +if islogical(X)
  105 + error(' images:rgb2gray:invalidType')
  106 +end
... ...