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

Last change on this file since 1086 was 1071, checked in by g7moreau, 4 years ago
  • Update COPYRIGHT
File size: 8.5 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-2020, 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    ParamOut.CPUTime=7;% expected time for writting one image ( in minute)
77    %% root input file(s) and type
78    % check the existence of the first file in the series
79        first_j=[];% note that the function will propose to cover the whole range of indices
80    if isfield(Param.IndexRange,'MinIndex_j'); first_j=Param.IndexRange.MinIndex_j; end
81    last_j=[];
82    if isfield(Param.IndexRange,'MaxIndex_j'); last_j=Param.IndexRange.MaxIndex_j; end
83    PairString='';
84    if isfield(Param.IndexRange,'PairString'); PairString=Param.IndexRange.PairString; end
85    [i1,i2,j1,j2] = get_file_index(Param.IndexRange.first_i,first_j,PairString);
86    FirstFileName=fullfile_uvmat(Param.InputTable{1,1},Param.InputTable{1,2},Param.InputTable{1,3},...
87        Param.InputTable{1,5},Param.InputTable{1,4},i1,i2,j1,j2);
88    if ~exist(FirstFileName,'file')
89        msgbox_uvmat('WARNING',['the first input file ' FirstFileName ' does not exist'])
90    end
91
92    %% check the validity of  input file types
93    FileInfo=get_file_info(FirstFileName);
94    if ~strcmp(FileInfo.FileType,'multimage')
95        msgbox_uvmat('ERROR',['invalid file type input: ' FileInfo.FileType ' not an image'])
96        return
97    end
98    ParamOut.ActionInput.XmlFile=uigetfile_uvmat('pick xml file for timing',fileparts(fileparts(FirstFileName)),'.xml'); 
99    return
100end
101%%%%%%%%%%%%%%%%%    STOP HERE FOR PAMETER INPUT MODE   %%%%%%%%%%%%%%%%%
102
103%% read input parameters from an xml file if input is a file name (batch mode)
104checkrun=1;
105RUNHandle=[];
106WaitbarHandle=[];
107if ischar(Param)
108    Param=xml2struct(Param);% read Param as input file (batch case)
109    checkrun=0;
110else
111    hseries=findobj(allchild(0),'Tag','series');
112    RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series
113    WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series
114end
115
116%% output directory
117OutputDir=fullfile(Param.InputTable{1,1},[Param.OutputSubDir Param.OutputDirExt]);
118
119%% Timing
120XmlInputFile=Param.ActionInput.XmlFile;
121[XmlInput,errormsg]=imadoc2struct(XmlInputFile,'Camera');
122if ~isempty(errormsg)
123    disp(['bad xml input file: ' errormsg])
124    return
125end
126ImagesPerLevel=size(XmlInput.Time,2)-1;%100;%use the xmlinformation to get the nbre of j indices
127
128%% create the xml file of PCO camera if it does not exist
129Newxml=fullfile(Param.InputTable{1,1},[Param.InputTable{1,2} '.xml']);
130if ~exist(Newxml,'file')
131XmlInput.Camera.CameraName='PCO';
132XmlInput=rmfield(XmlInput,'Time');
133XmlInput=rmfield(XmlInput,'TimeUnit');
134t=struct2xml(XmlInput);
135t=set(t,1,'name','ImaDoc');
136save(t,Newxml);
137end
138
139%% loop on the files
140% include the first tiff file with no index in the first iteration
141if Param.IndexRange.first_i==1% first slice of processing
142    firstindex=0;
143   count=0;
144else
145    firstindex=Param.IndexRange.first_i;
146    ImageName=fullfile(Param.InputTable{1,1},Param.InputTable{1,2},'im.tif');
147    NbFrames=numel(imfinfo(ImageName));
148   count=Param.IndexRange.first_i*NbFrames;
149end
150for ifile=firstindex:Param.IndexRange.last_i
151    tic
152    if firstindex==0 && ifile==0% first slice of processing
153        ImageName=fullfile(Param.InputTable{1,1},Param.InputTable{1,2},'im.tif')
154    else
155        ImageName=fullfile(Param.InputTable{1,1},Param.InputTable{1,2},['im@' num2str(ifile,'%04d') '.tif'])
156    end
157    NbFrames=numel(imfinfo(ImageName));
158    for iframe=1:NbFrames
159        if isequal(ImagesPerLevel,1)% mode series
160            OutputFile=fullfile(OutputDir,['img_' num2str(count+1) '.png']);
161        else % indices i and j
162            i_index=fix(count/ImagesPerLevel)+1;
163            j_index=mod(count,ImagesPerLevel)+1;
164            OutputFile=fullfile(OutputDir,['img_' num2str(i_index) '_' num2str(j_index) '.png']);
165        end
166        if Param.CheckOverwrite ||~exist(OutputFile,'file')
167            A=imread(ImageName,iframe);
168            imwrite(A,OutputFile,'BitDepth',16);
169            disp([OutputFile ' written'])
170        else
171            disp([OutputFile ' already exists'])
172        end
173        count=count+1;
174    end
175    tt=toc;
176    disp(['elapsed time (in min.) for the file im@' num2str(ifile,'%04d')])
177    disp(num2str(tt/60))
178end
179
180
181
Note: See TracBrowser for help on using the repository browser.