source: trunk/src/series/extract_multitif.m @ 1144

Last change on this file since 1144 was 1144, checked in by sommeria, 6 months ago

false flags modified in civ_series with new conventions, low pass filter adde to transform_field

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