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

Last change on this file since 1149 was 1149, checked in by sommeria, 7 days ago

extract_rdvision improved by automatic production of the xml file from timestamps

File size: 10.2 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    PairString='';
94    if isfield(Param.IndexRange,'PairString'); PairString=Param.IndexRange.PairString; end
95    [i1,i2,j1,j2] = get_file_index(Param.IndexRange.first_i,first_j,PairString);
96    FirstFileName=fullfile_uvmat(Param.InputTable{1,1},Param.InputTable{1,2},Param.InputTable{1,3},...
97        Param.InputTable{1,5},Param.InputTable{1,4},i1,i2,j1,j2);
98    if ~exist(FirstFileName,'file')
99        msgbox_uvmat('WARNING',['the first input file ' FirstFileName ' does not exist'])
100    end
101    ParamOut.NbSlice=Param.IndexRange.MaxIndex_i;
102    %% check the validity of  input file types
103    FileInfo=get_file_info(FirstFileName);
104    if ~strcmp(FileInfo.FileType,'multimage')
105        msgbox_uvmat('ERROR',['invalid file type input: ' FileInfo.FileType ' not a tiff image series'])
106        return
107    end
108    ParamOut.ActionInput.XmlFile=uigetfile_uvmat('pick xml file for timing',fileparts(fileparts(FirstFileName)),'.xml'); 
109    return
110end
111%%%%%%%%%%%%%%%%%    STOP HERE FOR PAMETER INPUT MODE   %%%%%%%%%%%%%%%%%
112
113%% read input parameters from an xml file if input is a file name (batch mode)
114checkrun=1;
115RUNHandle=[];
116WaitbarHandle=[];
117if ischar(Param)
118    Param=xml2struct(Param);% read Param as input file (batch case)
119    checkrun=0;
120else
121    hseries=findobj(allchild(0),'Tag','series');
122    RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series
123    WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series
124end
125
126%% output directory
127OutputDir=fullfile(Param.InputTable{1,1},[Param.OutputSubDir Param.OutputDirExt]);
128
129%% Timing
130XmlInputFile=Param.ActionInput.XmlFile;
131[XmlInput,errormsg]=imadoc2struct(XmlInputFile,'Camera');
132if ~isempty(errormsg)
133    disp(['bad xml input file: ' errormsg])
134    return
135end
136ImagesPerLevel=size(XmlInput.Time,2)-1;%100;%use the xmlinformation to get the nbre of j indices
137
138%% create the xml file for timing if it does not exist : example to adapt
139TEST=0;
140if TEST
141    count0=14;
142    Dtj=0.05;% time interval between frames
143    ImagesPerLevel=455;% total number of images per position, ImagesPerLevel-Nbj images skiiped during motion between two positions
144    Nbj=390; %Nbre of images kept at a given position
145    Dti=Dtj*ImagesPerLevel;
146    NbLevel=11;
147    NbScan=3;
148    TimeReturn=268.5; %time needed to return back to the first position (in sec)
149    NbReturn=round(TimeReturn/Dtj);
150    NbSkipReturn=NbReturn+1-NbLevel*ImagesPerLevel;
151   
152    Newxml=fullfile(Param.InputTable{1,1},[Param.InputTable{1,2} '.xml']);
153    if ~exist(Newxml,'file')
154        XmlInput.Camera.CameraName='PCO';
155        XmlInput.Camera.TimeUnit='s';
156        XmlInput.Camera.BurstTiming.FrameFrequency=1;
157        XmlInput.Camera.BurstTiming.Time=0;% for 200
158        XmlInput.Camera.BurstTiming.Dtj=Dtj;
159        XmlInput.Camera.BurstTiming.NbDtj=Nbj-1;
160        XmlInput.Camera.BurstTiming.Dti=Dti;
161        XmlInput.Camera.BurstTiming.NbDti=NbLevel-1;
162        XmlInput.Camera.BurstTiming.Dtk=TimeReturn;
163        XmlInput.Camera.BurstTiming.NbDtk=NbScan-1;
164        t=struct2xml(XmlInput);
165        t=set(t,1,'name','ImaDoc');
166        save(t,Newxml);
167    end
168end
169
170%% loop on the files
171% include the first tiff file with no index in the first iteration
172if Param.IndexRange.first_i==1% first slice of processing
173    firstindex=0;
174   count=0;
175else
176    firstindex=Param.IndexRange.first_i;
177    ImageName=fullfile(Param.InputTable{1,1},Param.InputTable{1,2},'im.tif');
178    NbFrames=numel(imfinfo(ImageName));
179   count=Param.IndexRange.first_i*NbFrames;
180end
181for ifile=firstindex:Param.IndexRange.last_i
182    tic
183    if firstindex==0 && ifile==0% first slice of processing
184        ImageName=fullfile(Param.InputTable{1,1},Param.InputTable{1,2},'im.tif')
185    else
186        ImageName=fullfile(Param.InputTable{1,1},Param.InputTable{1,2},['im@' num2str(ifile,'%04d') '.tif'])
187    end
188    NbFrames=numel(imfinfo(ImageName));
189    for iframe=1:NbFrames
190        if isequal(ImagesPerLevel,1)% mode series
191            OutputFile=fullfile(OutputDir,['img_' num2str(count+1) '.png']);
192        else % indices i and j
193            i_index=fix(count/ImagesPerLevel)+1;
194            j_index=mod(count,ImagesPerLevel)+1;
195            OutputFile=fullfile(OutputDir,['img_' num2str(i_index) '_' num2str(j_index) '.png']);
196        end
197        if Param.CheckOverwrite ||~exist(OutputFile,'file')
198            A=imread(ImageName,iframe);
199            imwrite(A,OutputFile,'BitDepth',16);
200            disp([OutputFile ' written'])
201        else
202            disp([OutputFile ' already exists'])
203        end
204        count=count+1;
205    end
206    tt=toc;
207    disp(['elapsed time (in min.) for the file im@' num2str(ifile,'%04d')])
208    disp(num2str(tt/60))
209end
210
211
212
Note: See TracBrowser for help on using the repository browser.