source: trunk/src/series/extract_multitif_special.m @ 1049

Last change on this file since 1049 was 1049, checked in by sommeria, 3 years ago

LIF clib corrected + histo velocity repaired

File size: 11.0 KB
Line 
1%'ima2netcdf': read image series and transform to netcdf
2%------------------------------------------------------------------------
3
4   
5% function ParamOut=ima2netcdf(Param)
6%
7%%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%%
8%
9%OUTPUT
10% ParamOut: sets options in the GUI series.fig needed for the function
11%
12%INPUT:
13% In run mode, the input parameters are given as a Matlab structure Param copied from the GUI series.
14% In batch mode, Param is the name of the corresponding xml file containing the same information
15% when Param.Action.RUN=0 (as activated when the current Action is selected
16% in series), the function ouput paramOut set the activation of the needed GUI elements
17%
18% Param contains the elements:(use the menu bar command 'export/GUI config' in series to
19% see the current structure Param)
20%    .InputTable: cell of input file names, (several lines for multiple input)
21%                      each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension}
22%    .OutputSubDir: name of the subdirectory for data outputs
23%    .OutputDirExt: directory extension for data outputs
24%    .Action: .ActionName: name of the current activated function
25%             .ActionPath:   path of the current activated function
26%             .ActionExt: fct extension ('.m', Matlab fct, '.sh', compiled   Matlab fct
27%             .RUN =0 for GUI input, =1 for function activation
28%             .RunMode='local','background', 'cluster': type of function  use
29%             
30%    .IndexRange: set the file or frame indices on which the action must be performed
31%    .FieldTransform: .TransformName: name of the selected transform function
32%                     .TransformPath:   path  of the selected transform function
33%    .InputFields: sub structure describing the input fields withfields
34%              .FieldName: name(s) of the field
35%              .VelType: velocity type
36%              .FieldName_1: name of the second field in case of two input series
37%              .VelType_1: velocity type of the second field in case of two input series
38%              .Coord_y: name of y coordinate variable
39%              .Coord_x: name of x coordinate variable
40%    .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object)
41%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42
43%=======================================================================
44% Copyright 2008-2018, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
45%   http://www.legi.grenoble-inp.fr
46%   Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
47%
48%     This file is part of the toolbox UVMAT.
49%
50%     UVMAT is free software; you can redistribute it and/or modify
51%     it under the terms of the GNU General Public License as published
52%     by the Free Software Foundation; either version 2 of the license,
53%     or (at your option) any later version.
54%
55%     UVMAT is distributed in the hope that it will be useful,
56%     but WITHOUT ANY WARRANTY; without even the implied warranty of
57%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
58%     GNU General Public License (see LICENSE.txt) for more details.
59%=======================================================================
60
61function ParamOut=extract_multitif_parallel(Param)
62
63%%%%%%%%%%%%%%%%%    INPUT PREPARATION MODE (no RUN)    %%%%%%%%%%%%%%%%%
64if isstruct(Param) && isequal(Param.Action.RUN,0)
65    ParamOut.AllowInputSort='off';% allow alphabetic sorting of the list of input file SubDir (options 'off'/'on', 'off' by default)
66    ParamOut.WholeIndexRange='on';% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
67    ParamOut.NbSlice='off'; % impose calculation in a single process (no parallel processing to avoid 'holes'))
68    ParamOut.VelType='off';% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
69    ParamOut.FieldName='off';% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
70    ParamOut.FieldTransform = 'off';%can use a transform function
71    ParamOut.ProjObject='off';%can use projection object(option 'off'/'on',
72    ParamOut.Mask='off';%can use mask option   (option 'off'/'on', 'off' by default)
73    ParamOut.OutputDirExt='.png';%set the output dir extension
74    ParamOut.OutputFileMode='NbSlice';% '=NbInput': 1 output file per input file index, '=NbInput_i': 1 file per input file index i, '=NbSlice': 1 file per slice
75      ParamOut.CheckOverwriteVisible='on'; % manage the overwrite of existing files (default=1)
76    %% root input file(s) and type
77    % check the existence of the first file in the series
78        first_j=[];% note that the function will propose to cover the whole range of indices
79    if isfield(Param.IndexRange,'MinIndex_j'); first_j=Param.IndexRange.MinIndex_j; end
80    last_j=[];
81    if isfield(Param.IndexRange,'MaxIndex_j'); last_j=Param.IndexRange.MaxIndex_j; end
82    PairString='';
83    if isfield(Param.IndexRange,'PairString'); PairString=Param.IndexRange.PairString; end
84    [i1,i2,j1,j2] = get_file_index(Param.IndexRange.first_i,first_j,PairString);
85    FirstFileName=fullfile_uvmat(Param.InputTable{1,1},Param.InputTable{1,2},Param.InputTable{1,3},...
86        Param.InputTable{1,5},Param.InputTable{1,4},i1,i2,j1,j2);
87    if ~exist(FirstFileName,'file')
88        msgbox_uvmat('WARNING',['the first input file ' FirstFileName ' does not exist'])
89    end
90
91    %% check the validity of  input file types
92    FileInfo=get_file_info(FirstFileName);
93    if ~strcmp(FileInfo.FileType,'multimage')
94        msgbox_uvmat('ERROR',['invalid file type input: ' FileInfo.FileType ' not an image'])
95        return
96    end
97    %ParamOut.ActionInput.XmlFile=uigetfile_uvmat('pick xml file for timing',fileparts(fileparts(FirstFileName)),'.xml'); 
98    return
99end
100%%%%%%%%%%%%%%%%%    STOP HERE FOR PAMETER INPUT MODE   %%%%%%%%%%%%%%%%%
101
102%% read input parameters from an xml file if input is a file name (batch mode)
103checkrun=1;
104RUNHandle=[];
105WaitbarHandle=[];
106if ischar(Param)
107    Param=xml2struct(Param);% read Param as input file (batch case)
108    checkrun=0;
109else
110    hseries=findobj(allchild(0),'Tag','series');
111    RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series
112    WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series
113end
114
115%% list of input images
116% DirImages=fullfile(Param.InputTable{1,1},Param.InputTable{1,2});
117% ListStruct=dir(DirImages);
118% ListCells=struct2cell(ListStruct);% transform dir struct to a cell arrray
119% check_bad=strcmp('.',ListCells(1,:))|strcmp('..',ListCells(1,:));%detect the dir '.' to exclude it
120% check_dir=cell2mat(ListCells(4,:));% =1 for directories, =0 for files
121% ListFile=ListCells(1,find(~check_dir & ~check_bad));
122
123%% check file names
124% RootName=regexprep(ListFile{1},'.tif$','')
125% rank(1)=1;
126% for ilist=2:numel(ListFile)
127%     rank_str=regexprep(ListFile{ilist},'.tif$','');
128%     rank(ilist)=regexprep(rank_str,['^' RootName '@'],'');
129% %     if ~isequal(str2num(rank),ilist-1)
130% %         disp(['error in the list of input file # ' num2str(ilist-1)])
131% %         return
132% %     end
133% end
134
135%% output directory
136OutputDir=fullfile(Param.InputTable{1,1},[Param.OutputSubDir Param.OutputDirExt]);
137
138%% Timing
139% XmlInputFile=Param.ActionInput.XmlFile;
140% [XmlInput,errormsg]=imadoc2struct(XmlInputFile,'Camera');
141% if ~isempty(errormsg)
142%     disp(['bad xml input file: ' errormsg])
143%     return
144% end
145%ImagesPerLevel=size(XmlInput.Time,2)-1;%100;%use the xmlinformation to get the nbre of j indices
146Dtj=0.05;% time interval between frames
147ImagesPerLevel=450;% total number of images per position, ImagesPerLevel-Nbj images skiiped during motion between two positions
148Nbj=400; %Nbre of images kept at a given position
149Dti=Dtj*ImagesPerLevel;
150NbLevel=11;
151NbScan=3;
152TimeReturn=20; %time needed to return back to the first position (in sec)
153NbSkippedReturn=round(TimeReturn/Dtj);
154%% create the xml file of PCO camera if it does not exist
155Newxml=fullfile(Param.InputTable{1,1},[Param.InputTable{1,2} '.xml']);
156if ~exist(Newxml,'file')
157    XmlInput.Camera.CameraName='PCO';
158    XmlInput.Camera.TimeUnit='s';
159    XmlInput.Camera.BurstTiming.FrameFrequency=1;
160   % XmlInput.Camera.BurstTiming.Time=-1;% for 180
161   XmlInput.Camera.BurstTiming.Time=0;% for 200
162    XmlInput.Camera.BurstTiming.Dtj=Dtj;
163    XmlInput.Camera.BurstTiming.NbDtj=Nbj-1;
164    XmlInput.Camera.BurstTiming.Dti=Dti;
165    XmlInput.Camera.BurstTiming.NbDti=NbLevel-1;
166    XmlInput.Camera.BurstTiming.Dtk=Dti*Nb
167    Level+TimeReturn;
168    XmlInput.Camera.BurstTiming.NbDtk=NbScan-1;
169    %XmlInput=rmfield(XmlInput,'Time');
170    %XmlInput=rmfield(XmlInput,'TimeUnit');
171    t=struct2xml(XmlInput);
172    t=set(t,1,'name','ImaDoc');
173    save(t,Newxml);
174end
175
176%% Main loop
177
178
179% count=0;
180%count=316;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%CORRECTION EXP08: 4684 images -> start at 316 start 67->_11_1
181%count=1934%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%CORRECTION EXP07: 3066 images
182%% loop on the files
183% include the first tiff file with no index in the first iteration
184if Param.IndexRange.first_i==1% first slice of processing
185    firstindex=0;
186    count=0;
187else
188    firstindex=Param.IndexRange.first_i;
189    ImageName=fullfile(Param.InputTable{1,1},Param.InputTable{1,2},'im.tif');
190    NbFrames=numel(imfinfo(ImageName));
191    count=Param.IndexRange.first_i*NbFrames;
192end
193for ifile=firstindex:Param.IndexRange.last_i
194    if firstindex==0 && ifile==0% first slice of processing
195        ImageName=fullfile(Param.InputTable{1,1},Param.InputTable{1,2},'im.tif')
196    else
197        ImageName=fullfile(Param.InputTable{1,1},Param.InputTable{1,2},['im@' num2str(ifile,'%04d') '.tif'])
198    end
199    NbFrames=numel(imfinfo(ImageName));
200    for iframe=1:NbFrames
201        iframe% = frame number inside a tif multimage
202        checkkeep=1;
203        count=count+1;
204        if count<=ImagesPerLevel*11 % first scan of 11 levels
205            i_index=fix((count-1)/ImagesPerLevel)+1;
206            j_index=mod(count-1,ImagesPerLevel)+1;
207        elseif count<=ImagesPerLevel*NbLevel+400 %skip 400 images during return
208            checkkeep=0;
209        elseif count<=ImagesPerLevel*2*NbLevel+400 % =5930 second scan
210            i_index=fix((count-401)/ImagesPerLevel)+1;
211            j_index=mod(count-401,ImagesPerLevel)+1;
212        elseif count<=ImagesPerLevel*2*NbLevel+800 %skip images during second return, from 2763 to 3167
213            checkkeep=0;
214        elseif count<=ImagesPerLevel*3*NbLevel+800 % =5930 third scan
215            i_index=fix((count-801)/ImagesPerLevel)+1;
216            j_index=mod(count-801,ImagesPerLevel)+1;
217        end
218        if checkkeep
219            if j_index>Nbj
220                OutputFile='';
221            else
222                OutputFile=fullfile(OutputDir,['img_' num2str(i_index) '_' num2str(j_index) '.png']);
223            end
224            if ~isempty(OutputFile)
225                if Param.CheckOverwrite ||~exist(OutputFile,'file')
226                    A=imread(ImageName,iframe);
227                    imwrite(A,OutputFile,'BitDepth',16);
228                    disp([OutputFile ' written'])
229                else
230                    disp([OutputFile ' already exists'])
231                end
232            end
233        end
234    end
235end
236
237
238
Note: See TracBrowser for help on using the repository browser.