[1099] | 1 | %'extract_multitif': read image series from PCO cameras (tiff image series) and write .png images |
---|
[1129] | 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 | |
---|
[1099] | 17 | % function ParamOut=extract_multitif(Param) |
---|
[930] | 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 | %======================================================================= |
---|
[1126] | 56 | % Copyright 2008-2024, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France |
---|
[930] | 57 | % http://www.legi.grenoble-inp.fr |
---|
[1127] | 58 | % Joel.Sommeria - Joel.Sommeria (A) univ-grenoble-alpes.fr |
---|
[930] | 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 | |
---|
[1099] | 73 | function ParamOut=extract_multitif(Param) |
---|
[930] | 74 | |
---|
| 75 | %%%%%%%%%%%%%%%%% INPUT PREPARATION MODE (no RUN) %%%%%%%%%%%%%%%%% |
---|
| 76 | if 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) |
---|
[1144] | 79 | ParamOut.NbSlice='on'; % |
---|
[930] | 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 |
---|
[1068] | 87 | ParamOut.CheckOverwriteVisible='on'; % manage the overwrite of existing files (default=1) |
---|
[1099] | 88 | ParamOut.CPUTime=10;% expected time for writting the output of one source image ( in minute) |
---|
[930] | 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 |
---|
[1144] | 101 | ParamOut.NbSlice=Param.IndexRange.MaxIndex_i; |
---|
[930] | 102 | %% check the validity of input file types |
---|
| 103 | FileInfo=get_file_info(FirstFileName); |
---|
[939] | 104 | if ~strcmp(FileInfo.FileType,'multimage') |
---|
[1144] | 105 | msgbox_uvmat('ERROR',['invalid file type input: ' FileInfo.FileType ' not a tiff image series']) |
---|
[930] | 106 | return |
---|
| 107 | end |
---|
[1002] | 108 | ParamOut.ActionInput.XmlFile=uigetfile_uvmat('pick xml file for timing',fileparts(fileparts(FirstFileName)),'.xml'); |
---|
[930] | 109 | return |
---|
| 110 | end |
---|
| 111 | %%%%%%%%%%%%%%%%% STOP HERE FOR PAMETER INPUT MODE %%%%%%%%%%%%%%%%% |
---|
| 112 | |
---|
| 113 | %% read input parameters from an xml file if input is a file name (batch mode) |
---|
| 114 | checkrun=1; |
---|
| 115 | RUNHandle=[]; |
---|
| 116 | WaitbarHandle=[]; |
---|
| 117 | if ischar(Param) |
---|
| 118 | Param=xml2struct(Param);% read Param as input file (batch case) |
---|
| 119 | checkrun=0; |
---|
| 120 | else |
---|
[1002] | 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 |
---|
[930] | 124 | end |
---|
| 125 | |
---|
[939] | 126 | %% output directory |
---|
[1002] | 127 | OutputDir=fullfile(Param.InputTable{1,1},[Param.OutputSubDir Param.OutputDirExt]); |
---|
[930] | 128 | |
---|
[1002] | 129 | %% Timing |
---|
| 130 | XmlInputFile=Param.ActionInput.XmlFile; |
---|
| 131 | [XmlInput,errormsg]=imadoc2struct(XmlInputFile,'Camera'); |
---|
| 132 | if ~isempty(errormsg) |
---|
| 133 | disp(['bad xml input file: ' errormsg]) |
---|
| 134 | return |
---|
| 135 | end |
---|
| 136 | ImagesPerLevel=size(XmlInput.Time,2)-1;%100;%use the xmlinformation to get the nbre of j indices |
---|
| 137 | |
---|
[1099] | 138 | %% create the xml file for timing if it does not exist : example to adapt |
---|
| 139 | TEST=0; |
---|
| 140 | if 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 |
---|
[1002] | 168 | end |
---|
| 169 | |
---|
| 170 | %% loop on the files |
---|
| 171 | % include the first tiff file with no index in the first iteration |
---|
| 172 | if Param.IndexRange.first_i==1% first slice of processing |
---|
| 173 | firstindex=0; |
---|
| 174 | count=0; |
---|
| 175 | else |
---|
| 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; |
---|
| 180 | end |
---|
| 181 | for ifile=firstindex:Param.IndexRange.last_i |
---|
[1068] | 182 | tic |
---|
[1002] | 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']) |
---|
[930] | 187 | end |
---|
| 188 | NbFrames=numel(imfinfo(ImageName)); |
---|
[1002] | 189 | for iframe=1:NbFrames |
---|
[972] | 190 | if isequal(ImagesPerLevel,1)% mode series |
---|
[931] | 191 | OutputFile=fullfile(OutputDir,['img_' num2str(count+1) '.png']); |
---|
[972] | 192 | else % indices i and j |
---|
[930] | 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 |
---|
[972] | 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 |
---|
[931] | 204 | count=count+1; |
---|
[930] | 205 | end |
---|
[1068] | 206 | tt=toc; |
---|
| 207 | disp(['elapsed time (in min.) for the file im@' num2str(ifile,'%04d')]) |
---|
| 208 | disp(num2str(tt/60)) |
---|
[930] | 209 | end |
---|
| 210 | |
---|
[972] | 211 | |
---|
[930] | 212 | |
---|