source: trunk/src/series/ima2temperature.m @ 1143

Last change on this file since 1143 was 1127, checked in by g7moreau, 12 months ago

Update Joel email

File size: 10.5 KB
Line 
1%'ima2temperature': get velocity fields from LIF image series using two
2%reference images obtained at known temperature
3
4%------------------------------------------------------------------------
5% function GUI_input=ima_levels(Param)
6%
7%------------------------------------------------------------------------
8%%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%%
9%
10%OUTPUT
11% ParamOut: sets options in the GUI series.fig needed for the function
12%
13%INPUT:
14% In run mode, the input parameters are given as a Matlab structure Param copied from the GUI series.
15% In batch mode, Param is the name of the corresponding xml file containing the same information
16% when Param.Action.RUN=0 (as activated when the current Action is selected
17% in series), the function ouput paramOut set the activation of the needed GUI elements
18%
19% Param contains the elements:(use the menu bar command 'export/GUI config' in series to
20% see the current structure Param)
21%    .InputTable: cell of input file names, (several lines for multiple input)
22%                      each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension}
23%    .OutputSubDir: name of the subdirectory for data outputs
24%    .OutputDirExt: directory extension for data outputs
25%    .Action: .ActionName: name of the current activated function
26%             .ActionPath:   path of the current activated function
27%             .ActionExt: fct extension ('.m', Matlab fct, '.sh', compiled   Matlab fct
28%             .RUN =0 for GUI input, =1 for function activation
29%             .RunMode='local','background', 'cluster': type of function  use
30%             
31%    .IndexRange: set the file or frame indices on which the action must be performed
32%    .FieldTransform: .TransformName: name of the selected transform function
33%                     .TransformPath:   path  of the selected transform function
34%    .InputFields: sub structure describing the input fields withfields
35%              .FieldName: name(s) of the field
36%              .VelType: velocity type
37%              .FieldName_1: name of the second field in case of two input series
38%              .VelType_1: velocity type of the second field in case of two input series
39%              .Coord_y: name of y coordinate variable
40%              .Coord_x: name of x coordinate variable
41%    .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object)
42%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43
44%=======================================================================
45% Copyright 2008-2024, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
46%   http://www.legi.grenoble-inp.fr
47%   Joel.Sommeria - Joel.Sommeria (A) univ-grenoble-alpes.fr
48%
49%     This file is part of the toolbox UVMAT.
50%
51%     UVMAT is free software; you can redistribute it and/or modify
52%     it under the terms of the GNU General Public License as published
53%     by the Free Software Foundation; either version 2 of the license,
54%     or (at your option) any later version.
55%
56%     UVMAT is distributed in the hope that it will be useful,
57%     but WITHOUT ANY WARRANTY; without even the implied warranty of
58%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
59%     GNU General Public License (see LICENSE.txt) for more details.
60%=======================================================================
61
62function ParamOut=ima2temperature (Param)
63
64%% set the input elements needed on the GUI series when the action is selected in the menu ActionName or InputTable refreshed
65if isstruct(Param) && isequal(Param.Action.RUN,0)
66    ParamOut.NbViewMax=1;% max nbre of input file series (default , no limitation)
67    ParamOut.AllowInputSort='off';% allow alphabetic sorting of the list of input file SubDir (options 'off'/'on', 'off' by default)
68    ParamOut.WholeIndexRange='off';% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
69    ParamOut.NbSlice='off'; %nbre of slices ('off' by default)
70    ParamOut.VelType='off';% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
71    ParamOut.FieldName='one';% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
72    ParamOut.FieldTransform = 'on';%can use a transform function
73    ParamOut.ProjObject='off';%can use projection object(option 'off'/'on',
74    ParamOut.Mask='off';%can use mask option   (option 'off'/'on', 'off' by default)
75    ParamOut.OutputDirExt='.temperature';%set the output dir extension
76    ParamOut.OutputFileMode='NbInput';% ='=NbInput': 1 output file per input file index, '=NbInput_i': 1 file per input file index i, '=NbSlice': 1 file per slice
77    %check the type of the existence and type of the first input file:
78    Param.IndexRange.last_i=Param.IndexRange.first_i;%keep only the first index in the series
79    if isfield(Param.IndexRange,'first_j')
80    Param.IndexRange.last_j=Param.IndexRange.first_j;
81    end
82    filecell=get_file_series(Param);
83    if ~exist(filecell{1,1},'file')
84        msgbox_uvmat('WARNING','the first input file does not exist')
85    else
86        FileInfo=get_file_info(filecell{1,1});
87        FileType=FileInfo.FileType;
88        if isempty(find(strcmp(FileType,{'image','multimage','mmreader','video'})));% =1 for images
89            msgbox_uvmat('ERROR',['bad input file type for ' mfilename ': an image is needed'])
90        end
91    end
92return
93end
94
95%%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%%
96%% read input parameters from an xml file if input is a file name (batch mode)
97ParamOut=[];
98RUNHandle=[];
99WaitbarHandle=[];
100checkrun=1;
101if ischar(Param)
102    Param=xml2struct(Param);% read Param as input file (batch case)
103    checkrun=0;
104else% interactive mode in Matlab
105    hseries=findobj(allchild(0),'Tag','series');
106    RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series
107    WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series
108end
109
110%% subdirectory for output files
111SubdirOut=[Param.OutputSubDir Param.OutputDirExt];
112
113%% root input file names and nomenclature type (cell arrays with one element)
114RootPath=Param.InputTable(:,1);
115RootFile=Param.InputTable(:,3);
116SubDir=Param.InputTable(:,2);
117NomType=Param.InputTable(:,4);
118FileExt=Param.InputTable(:,5);
119
120
121%% get the set of input file names (cell array filecell), and file indices
122[filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
123% filecell{iview,fileindex}: cell array representing the list of file names
124%        iview: line in the table corresponding to a given file series
125%        fileindex: file index within  the file series,
126% i1_series(iview,ref_j,ref_i)... are the corresponding arrays of indices i1,i2,j1,j2, depending on the input line iview and the two reference indices ref_i,ref_j
127% i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices
128nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
129nbfield_i=size(i1_series{1},2); %nb of fields for the i index
130nbfield=nbfield_j*nbfield_i; %total number of fields
131[FileInfo{1},VideoObject{1}]=get_file_info(filecell{1,1});% type of input file
132FileType{1}=FileInfo{1}.FileType;
133
134%% frame index for movie or multimage file input 
135if ~isempty(j1_series{1})
136    frame_index{1}=j1_series{1};
137else
138    frame_index{1}=i1_series{1};
139end
140
141%% calibration data and timing: read the ImaDoc files
142%not relevant for this function
143
144%% check coincidence in time for several input file series
145%not relevant for this function
146
147%% coordinate transform or other user defined transform
148%not relevant for this function
149
150%%%%%%%%%%%% END STANDARD PART  %%%%%%%%%%%%
151 % EDIT FROM HERE
152
153 %% Extension and indexing nomenclature for output file
154 FileExtOut='.png'; % write result as .png images for image inputs
155 if strcmpi(NomType{1}(end),'a')
156     NomTypeOut=NomType{1};
157 else
158     NomTypeOut='_1_1';
159 end
160
161%% Set field names and velocity types
162%not relevant for this function
163
164%% Initiate output fields
165%not relevant for this function
166
167%% set processing parameters
168% not needed for this function
169
170%% coordinate transform or other user defined transform:introduce the transform function phys
171transform_fct='';%default fct handle
172if isfield(Param,'FieldTransform')&&~isempty(Param.FieldTransform.TransformName)
173        currentdir=pwd;
174        cd(Param.FieldTransform.TransformPath)
175        transform_fct=str2func(Param.FieldTransform.TransformName);
176        cd (currentdir)
177%         if isfield(Param,'TransformInput')
178%             for iview=1:NbView
179%             XmlData{iview}.TransformInput=Param.TransformInput;
180%             end
181%         end       
182end
183[XmlData,NbSlice_calib,time,errormsg]=read_multimadoc(RootPath,SubDir,RootFile,FileExt,i1_series,i2_series,j1_series,j2_series);
184
185%% open the reference images
186ImHiName=fullfile(RootPath{1},'H2mean','ref.png')%reference LIF image obtained at low uniform temperature
187ImLowName=fullfile(RootPath{1},'H1mean','ref.png')%reference LIF image obtained at high uniform temperature
188
189AHi=double(imread(ImHiName));
190ALow=double(imread(ImLowName));
191Adiff=AHi-ALow;
192Adiff(Adiff==0)=1;
193
194%% prepare the output netcdf files
195DataOut.ListGlobalAttribute={'Conventions'};
196DataOut.Conventions='uvmat';
197DataOut.ListVarName={'Coord_x','Coord_y','Temperature'};
198DataOut.VarDimName={'Coord_x','Coord_y',{'Coord_y','Coord_x'}};
199
200%% main loop on images,
201j1=[];%default
202for ifile=1:nbfield
203            update_waitbar(WaitbarHandle,ifile/nbfield)
204    if ~isempty(RUNHandle) && ~strcmp(get(RUNHandle,'BusyAction'),'queue')
205        disp('program stopped by user')
206        return
207    end
208    if ~isempty(j1_series)&&~isequal(j1_series,{[]})
209        j1=j1_series{1}(ifile);
210    end
211    filename=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},NomType{1},i1_series{1}(ifile),[],j1);
212    %A=read_image(filename,FileType{1},VideoObject{1},frame_index{1}(ifile));
213    [Data,tild,errormsg] = read_field(filename,'image');
214      % operation on images
215    Data.A=double(Data.A);
216    Data.A=(Data.A-ALow)./Adiff;
217    Data=transform_fct(Data,XmlData{1});%transform to phys coordinates
218   
219    % write output file
220    filename_new=fullfile_uvmat(RootPath{1},SubdirOut,RootFile{1},'.nc',NomTypeOut,i1_series{1}(ifile),[],j1);
221    %imwrite(A,filename_new)
222    errormsg=struct2nc(filename_new,Data );
223    if ~isempty(errormsg)
224        disp(errormsg)
225    else
226    disp([filename_new ' written'])
227    end
228end
229%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
230
Note: See TracBrowser for help on using the repository browser.