[953] | 1 | %'ima2vol': concatene image series to form a 'volume' image, make vertical cuts along x and y
|
---|
[171] | 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 | %
|
---|
[41] | 15 | %----------------------------------------------------------------------
|
---|
[810] | 16 |
|
---|
| 17 | %=======================================================================
|
---|
[924] | 18 | % Copyright 2008-2016, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
|
---|
[810] | 19 | % http://www.legi.grenoble-inp.fr
|
---|
| 20 | % Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.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 |
|
---|
[953] | 35 | function 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
|
---|
| 38 | if 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='.vertical_cut';%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
|
---|
[41] | 60 | end
|
---|
| 61 |
|
---|
[953] | 62 | %%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%%
|
---|
| 63 | %% read input parameters from an xml file if input is a file name (batch mode)
|
---|
| 64 | ParamOut=[];
|
---|
| 65 | RUNHandle=[];
|
---|
| 66 | WaitbarHandle=[];
|
---|
| 67 | checkrun=1;
|
---|
| 68 | if ischar(Param)
|
---|
| 69 | Param=xml2struct(Param);% read Param as input file (batch case)
|
---|
| 70 | checkrun=0;
|
---|
| 71 | else% 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
|
---|
| 75 | end
|
---|
[41] | 76 |
|
---|
[953] | 77 | %% subdirectory for output files
|
---|
| 78 | SubdirOut=[Param.OutputSubDir Param.OutputDirExt];
|
---|
[41] | 79 |
|
---|
[953] | 80 | %% root input file names and nomenclature type (cell arrays with one element)
|
---|
| 81 | RootPath=Param.InputTable(:,1);
|
---|
| 82 | RootFile=Param.InputTable(:,3);
|
---|
| 83 | SubDir=Param.InputTable(:,2);
|
---|
| 84 | NomType=Param.InputTable(:,4);
|
---|
| 85 | FileExt=Param.InputTable(:,5);
|
---|
[41] | 86 |
|
---|
| 87 |
|
---|
[953] | 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
|
---|
| 95 | nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
|
---|
| 96 | nbfield_i=size(i1_series{1},2); %nb of fields for the i index
|
---|
| 97 | nbfield=nbfield_j*nbfield_i; %total number of fields
|
---|
| 98 | [FileInfo{1},VideoObject{1}]=get_file_info(filecell{1,1});% type of input file
|
---|
| 99 | FileType{1}=FileInfo{1}.FileType;
|
---|
[41] | 100 |
|
---|
[953] | 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);
|
---|
| 103 | if ~isempty(errormsg)
|
---|
| 104 | disp_uvmat('WARNING',errormsg,checkrun)
|
---|
| 105 | end
|
---|
| 106 |
|
---|
| 107 | %% coordinate transform or other user defined transform
|
---|
| 108 | transform_fct='';%default fct handle
|
---|
| 109 | if 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)
|
---|
| 114 | end
|
---|
| 115 |
|
---|
| 116 | %% main loop
|
---|
| 117 | for 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 | vol=zeros(nbfield_j,size(Data.A,1),size(Data.A,2));
|
---|
| 136 | Z=1:nbfield_j;%default Z values
|
---|
| 137 | end
|
---|
| 138 | vol(jfile,:,:)=double(Data.A);%concacene along y
|
---|
| 139 | Z(jfile)=Data.PlaneCoord(3);
|
---|
| 140 | end
|
---|
| 141 | if ifile==1
|
---|
| 142 | npx=size(Data.A,2);
|
---|
| 143 | npy=size(Data.A,1);
|
---|
| 144 | npz=256;
|
---|
| 145 | ind_x=round(npx/2)-10:round(npx/2)+10;%image index at the mid x position
|
---|
| 146 | ind_y=round(npy/2)-10:round(npy/2)+10;;%image index at the mid y position
|
---|
| 147 |
|
---|
| 148 | %write xml calibration file, using the first file
|
---|
| 149 | Rangx=Data.Coord_x;
|
---|
| 150 | Rangy=Data.Coord_y;
|
---|
| 151 | Rangz=[Z(end) Z(1)];
|
---|
[41] | 152 |
|
---|
[953] | 153 | GeometryCal.CalibrationType='rescale';
|
---|
| 154 | GeometryCal.CoordUnit=Data.CoordUnit;
|
---|
| 155 | GeometryCal.focal=1;
|
---|
| 156 | %scaling along x, y and z
|
---|
| 157 | pxcmx=(npx-1)/(Rangx(2)-Rangx(1));
|
---|
| 158 | pxcmy=(npy-1)/(Rangy(1)-Rangy(2));
|
---|
| 159 | pxcmz=(npz-1)/(Rangz(2)-Rangz(1));
|
---|
| 160 | T_x=-pxcmx*Rangx(1)+0.5;
|
---|
| 161 | T_y=-pxcmy*Rangy(2)+0.5;
|
---|
| 162 | T_z=-pxcmz*Rangz(2)+0.5;
|
---|
| 163 | % xml file for x cut
|
---|
| 164 | GeometryCal.R=[pxcmx,0,0;0,pxcmz,0;0,0,1];
|
---|
| 165 | GeometryCal.Tx_Ty_Tz=[T_x T_z 1];
|
---|
| 166 | ImaDoc.GeometryCalib=GeometryCal;
|
---|
| 167 | t=struct2xml(ImaDoc);
|
---|
| 168 | t=set(t,1,'name','ImaDoc');
|
---|
| 169 | save(t,fullfile(RootPath{1},SubdirOut,'cut_x.xml'))
|
---|
| 170 | % xml file for y cut
|
---|
| 171 | GeometryCal.R=[pxcmy,0,0;0,pxcmz,0;0,0,1];
|
---|
| 172 | GeometryCal.Tx_Ty_Tz=[T_y T_z 1];
|
---|
| 173 | ImaDoc.GeometryCalib=GeometryCal;
|
---|
| 174 | t=struct2xml(ImaDoc);
|
---|
| 175 | t=set(t,1,'name','ImaDoc');
|
---|
| 176 | save(t,fullfile(RootPath{1},SubdirOut,'cut_y.xml'))
|
---|
[41] | 177 | end
|
---|
[953] | 178 | cut_y=squeeze(mean(vol(:,:,ind_x),3));
|
---|
| 179 | cut_y=interp1(Z,cut_y,linspace(Z(1),Z(end),npz));
|
---|
| 180 | cut_x=squeeze(mean(vol(:,ind_y,:),2));
|
---|
| 181 | cut_x=interp1(Z,cut_x,linspace(Z(1),Z(end),npz));
|
---|
| 182 |
|
---|
| 183 | filename_x=fullfile_uvmat(RootPath{1},SubdirOut,'cut_x','.png','_1',i1_series{1}(jfile,ifile),[],j1);
|
---|
| 184 | filename_y=fullfile_uvmat(RootPath{1},SubdirOut,'cut_y','.png','_1',i1_series{1}(jfile,ifile),[],j1);
|
---|
| 185 | % filename_new=name_generator(basename_new,num_i,1,'.vol','_i');
|
---|
| 186 | imwrite(uint8(vol),filename_x,'png','BitDepth',8)%
|
---|
| 187 | display([filename_x 'written (8bits image)'])
|
---|
| 188 | imwrite(uint8(vol),filename_y,'png','BitDepth',8)%
|
---|
| 189 | display([filename_y 'written (8bits image)'])
|
---|
[41] | 190 | end
|
---|
| 191 |
|
---|
| 192 |
|
---|
| 193 |
|
---|