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

Last change on this file since 1118 was 1107, checked in by g7moreau, 3 years ago

Update Copyright to 2022

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