source: trunk/src/series/ima2vol.m @ 1139

Last change on this file since 1139 was 1127, checked in by g7moreau, 12 months ago

Update Joel email

File size: 9.1 KB
Line 
1%'ima2vol': concatene  image series to form a 'volume' image, make vertical cuts along x and y
2%------------------------------------------------------------------------
3% function GUI_input=ima2vol(num_i1,num_i2,num_j1,num_j2,Series)
4%
5%OUTPUT
6% GUI_input=list of options in the GUI series.fig needed for the function
7%
8%INPUT:
9%num_i1: series of first indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
10%num_i2:  series of second indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
11%num_j1:  series of first indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ )
12%num_j2:  series of second indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ)
13%Series: Matlab structure containing information set by the series interface
14%
15%----------------------------------------------------------------------
16
17%=======================================================================
18% Copyright 2008-2024, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
19%   http://www.legi.grenoble-inp.fr
20%   Joel.Sommeria - Joel.Sommeria (A) univ-grenoble-alpes.fr
21%
22%     This file is part of the toolbox UVMAT.
23%
24%     UVMAT is free software; you can redistribute it and/or modify
25%     it under the terms of the GNU General Public License as published
26%     by the Free Software Foundation; either version 2 of the license,
27%     or (at your option) any later version.
28%
29%     UVMAT is distributed in the hope that it will be useful,
30%     but WITHOUT ANY WARRANTY; without even the implied warranty of
31%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
32%     GNU General Public License (see LICENSE.txt) for more details.
33%=======================================================================
34
35function ParamOut=ima2vol(Param)
36
37%% set the input elements needed on the GUI series when the function is selected in the menu ActionName or InputTable refreshed
38if isstruct(Param) && isequal(Param.Action.RUN,0)
39    ParamOut.AllowInputSort='off';% allow alphabetic sorting of the list of input file SubDir (options 'off'/'on', 'off' by default)
40    ParamOut.WholeIndexRange='off';% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
41    ParamOut.NbSlice='off'; %nbre of slices ('off' by default)
42    ParamOut.VelType='one';% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
43    ParamOut.FieldName='one';% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
44    ParamOut.FieldTransform = 'on';%can use a transform function
45    ParamOut.TransformPath=fullfile(fileparts(which('uvmat')),'transform_field');% path to transform functions (needed for compilation only)
46    ParamOut.ProjObject='on';%can use projection object(option 'off'/'on',
47    ParamOut.Mask='on';%can use mask option   (option 'off'/'on', 'off' by default)
48    ParamOut.OutputDirExt='.vol';%set the output dir extension
49    ParamOut.OutputFileMode='NbInput';% '=NbInput': 1 output file per input file index, '=NbInput_i': 1 file per input file index i, '=NbSlice': 1 file per slice
50      %check the input files
51    ParamOut.CheckOverwriteVisible='on'; % manage the overwrite of existing files (default=1)
52    first_j=[];
53    if isfield(Param.IndexRange,'first_j'); first_j=Param.IndexRange.first_j; end
54    PairString='';
55    if isfield(Param.IndexRange,'PairString'); PairString=Param.IndexRange.PairString; end
56    [i1,i2,j1,j2] = get_file_index(Param.IndexRange.first_i,first_j,PairString);
57    FirstFileName=fullfile_uvmat(Param.InputTable{1,1},Param.InputTable{1,2},Param.InputTable{1,3},...
58        Param.InputTable{1,5},Param.InputTable{1,4},i1,i2,j1,j2);
59    return
60end
61
62%%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%%
63%% read input parameters from an xml file if input is a file name (batch mode)
64ParamOut=[];
65RUNHandle=[];
66WaitbarHandle=[];
67checkrun=1;
68if ischar(Param)
69    Param=xml2struct(Param);% read Param as input file (batch case)
70    checkrun=0;
71else% interactive mode in Matlab
72    hseries=findobj(allchild(0),'Tag','series');
73    RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series
74    WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series
75end
76
77%% subdirectory for output files
78SubdirOut=[Param.OutputSubDir Param.OutputDirExt];
79
80%% root input file names and nomenclature type (cell arrays with one element)
81RootPath=Param.InputTable(:,1);
82RootFile=Param.InputTable(:,3);
83SubDir=Param.InputTable(:,2);
84NomType=Param.InputTable(:,4);
85FileExt=Param.InputTable(:,5);
86
87
88%% get the set of input file names (cell array filecell), and file indices
89[filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
90% filecell{iview,fileindex}: cell array representing the list of file names
91%        iview: line in the table corresponding to a given file series
92%        fileindex: file index within  the file series,
93% i1_series(iview,ref_j,ref_i)... are the corresponding arrays of indices i1,i2,j1,j2, depending on the input line iview and the two reference indices ref_i,ref_j
94% i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices
95nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
96nbfield_i=size(i1_series{1},2); %nb of fields for the i index
97nbfield=nbfield_j*nbfield_i; %total number of fields
98[FileInfo{1},VideoObject{1}]=get_file_info(filecell{1,1});% type of input file
99FileType{1}=FileInfo{1}.FileType;
100
101%% calibration data and timing: read the ImaDoc files
102[XmlData,NbSlice_calib,time,errormsg]=read_multimadoc(RootPath,SubDir,RootFile,FileExt,i1_series,i2_series,j1_series,j2_series);
103if ~isempty(errormsg)
104    disp_uvmat('WARNING',errormsg,checkrun)
105end
106
107%% coordinate transform or other user defined transform
108transform_fct='';%default fct handle
109if isfield(Param,'FieldTransform')&&~isempty(Param.FieldTransform.TransformName)
110        currentdir=pwd;
111        cd(Param.FieldTransform.TransformPath)
112        transform_fct=str2func(Param.FieldTransform.TransformName);
113        cd (currentdir)     
114end
115
116%% main loop
117for ifile=1:nbfield_i
118    update_waitbar(WaitbarHandle,ifile/nbfield)
119    if ~isempty(RUNHandle) && ~strcmp(get(RUNHandle,'BusyAction'),'queue')
120        disp('program stopped by user')
121        return
122    end
123    for jfile=1:nbfield_j
124        if ~isempty(j1_series)&&~isequal(j1_series,{[]})
125            j1=j1_series{1}(jfile,ifile);
126        end
127        filename=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},NomType{1},i1_series{1}(jfile,ifile),[],j1)
128        [Data,tild,errormsg] = read_field(filename,'image');
129        % transform the input field (e.g; phys) if requested (no transform involving two input fields)
130        if ~isempty(transform_fct)
131            Data.ZIndex=jfile;
132            Data=transform_fct(Data,XmlData{1});
133        end
134        if jfile==1
135            VolData.A=zeros(nbfield_j,size(Data.A,1),size(Data.A,2));
136            VolData.Coord_z=1:nbfield_j;%default Z values
137        end
138        VolData.A(jfile,:,:)=Data.A;%concacene along y
139        VolData.Coord_z(jfile)=XmlData{1}.GeometryCalib.SliceCoord(jfile,3);
140    end
141%         npx=size(Data.A,2);
142%         npy=size(Data.A,1);
143%         npz=256;
144%         ind_x=round(npx/2)-10:round(npx/2)+10;%image index at the mid x position
145%         ind_y=round(npy/2)-10:round(npy/2)+10;%image index at the mid y position
146%         ind_y=ind_y-100;% shift to avoid the injector
147%         %write xml calibration file, using the first file
148%             Rangx=Data.Coord_x;
149%             Rangy=Data.Coord_y;
150%             Rangz=[Z(end) Z(1)];
151%     
152%         GeometryCal.CalibrationType='rescale';
153%         GeometryCal.CoordUnit=Data.CoordUnit;
154%         GeometryCal.focal=1;
155%         %scaling along x, y and z
156%         pxcmx=(npx-1)/(Rangx(2)-Rangx(1));
157%         pxcmy=(npy-1)/(Rangy(1)-Rangy(2));
158%         pxcmz=(npz-1)/(Rangz(2)-Rangz(1));
159%         T_x=-pxcmx*Rangx(1)+0.5;
160%         T_y=-pxcmy*Rangy(2)+0.5;
161%         T_z=-pxcmz*Rangz(2)+0.5;
162%         % xml file for x cut
163%         GeometryCal.R=[pxcmx,0,0;0,pxcmz,0;0,0,1];
164%         GeometryCal.Tx_Ty_Tz=[T_x T_z 1];
165%         ImaDoc.GeometryCalib=GeometryCal;
166%         t=struct2xml(ImaDoc);
167%         t=set(t,1,'name','ImaDoc');
168%         save(t,fullfile(RootPath{1},SubdirOut,'cut_x.xml'))
169%                    % xml file for y cut
170%         GeometryCal.R=[pxcmy,0,0;0,pxcmz,0;0,0,1];
171%         GeometryCal.Tx_Ty_Tz=[T_y T_z 1];
172%         ImaDoc.GeometryCalib=GeometryCal;
173%         t=struct2xml(ImaDoc);
174%         t=set(t,1,'name','ImaDoc');
175%         save(t,fullfile(RootPath{1},SubdirOut,'cut_y.xml'))
176%     end
177   
178    filename=fullfile_uvmat(RootPath{1},SubdirOut,RootFile{1},'.nc','_1',i1_series{1}(jfile,ifile),[],j1);
179    VolData.ListVarName={'Coord_z','Coord_y','Coord_x','A'};
180    VolData.VarDimName={'Coord_z','Coord_y','Coord_x',{'Coord_z','Coord_y','Coord_x'}};
181    VolData.Coord_x=Data.Coord_x;
182    VolData.Coord_y=Data.Coord_y;
183    struct2nc(filename,VolData)
184    disp([filename ' written'])
185end
186
187
188
Note: See TracBrowser for help on using the repository browser.