Changeset 673 for trunk


Ignore:
Timestamp:
Aug 6, 2013, 3:47:29 PM (11 years ago)
Author:
sommeria
Message:

various bugs corrected

Location:
trunk/src/series
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/series/aver_stat.m

    r668 r673  
    9090% i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices
    9191%%%%%%%%%%%%
    92 nbview=numel(i1_series);%number of input file series (lines in InputTable)
    93 nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
    94 nbfield_i=size(i1_series{1},2); %nb of fields for the i index
    95 nbfield=nbfield_j*nbfield_i; %total number of fields
     92NbView=numel(i1_series);%number of input file series (lines in InputTable)
     93NbField_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
     94NbField_i=size(i1_series{1},2); %nb of fields for the i index
     95NbField=NbField_j*NbField_i; %total number of fields
    9696
    9797%% determine the file type on each line from the first input file
    9898ImageTypeOptions={'image','multimage','mmreader','video'};
    9999NcTypeOptions={'netcdf','civx','civdata'};
    100 for iview=1:nbview
     100for iview=1:NbView
    101101    if ~exist(filecell{iview,1}','file')
    102102        msgbox_uvmat('ERROR',['the first input file ' filecell{iview,1} ' does not exist'])
     
    142142    return
    143143end
    144 if nbview==2 && ~isequal(CheckImage{1},CheckImage{2})
     144if NbView==2 && ~isequal(CheckImage{1},CheckImage{2})
    145145    msgbox_uvmat('ERROR','input must be two image series or two netcdf file series')
    146146    return
     
    163163    InputFields{1}=Param.InputFields;
    164164end
    165 if nbview==2
     165if NbView==2
    166166    InputFields{2}=[];%default (case of images)
    167167    if isfield(Param,'InputFields')
     
    182182
    183183%%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%%
    184 for index=1:nbfield
    185     update_waitbar(WaitbarHandle,index/nbfield)
     184for index=1:NbField
     185    update_waitbar(WaitbarHandle,index/NbField)
    186186    if ~isempty(RUNHandle)&& ~strcmp(get(RUNHandle,'BusyAction'),'queue')
    187187        disp('program stopped by user')
     
    190190   
    191191    %%%%%%%%%%%%%%%% loop on views (input lines) %%%%%%%%%%%%%%%%
    192     for iview=1:nbview
     192    for iview=1:NbView
    193193        % reading input file(s)
    194194        [Data{iview},tild,errormsg] = read_field(filecell{iview,index},FileType{iview},InputFields{iview},frame_index{iview}(index));
  • trunk/src/series/merge_proj.m

    r670 r673  
    106106NbField=NbField_j*NbField_i; %total number of fields
    107107
    108 %determine the file type on each line from the first input file
     108%% determine the file type on each line from the first input file
    109109ImageTypeOptions={'image','multimage','mmreader','video'};
    110110NcTypeOptions={'netcdf','civx','civdata'};
     
    145145
    146146%% check the validity of  input file types
    147 if CheckImage{1}
    148     FileExtOut='.png'; % write result as .png images for image inputs
    149 elseif CheckNc{1}
    150     FileExtOut='.nc';% write result as .nc files for netcdf inputs
    151 else
    152     disp_uvmat('ERROR',['invalid file type input ' FileType{1}],checkrun)
    153     return
    154 end
    155147for iview=1:NbView
    156     if ~isequal(CheckImage{iview},CheckImage{1})||~isequal(CheckNc{iview},CheckNc{1})
     148    if ~isequal(CheckImage{iview},1)&&~isequal(CheckNc{iview},1)
    157149        disp_uvmat('ERROR','input set of input series: need  either netcdf either image series',checkrun)
    158150        return
    159151    end
    160152end
     153
     154%% output file type
     155if min(cell2mat(CheckImage))==1 && (~Param.CheckObject || strcmp(Param.ProjObject.Type,'plane'))
     156    FileExtOut='.png'; %image output (input and proj result = image)
     157    for iview=1:NbView
     158        BitDepth(iview)=FileInfo{iview}.BitDepth;
     159    end
     160    BitDepth=max(BitDepth);
     161else
     162    FileExtOut='.nc'; %netcdf output
     163end
    161164NomTypeOut=NomType;% output file index will indicate the first and last ref index in the series
     165RootFileOut=RootFile{1};
     166for iview=2:NbView
     167    if ~strcmp(RootFile{iview},RootFile{1})
     168        RootFileOut='mproj';
     169        break
     170    end
     171end
    162172
    163173%% mask (TODO: case of multilevels)
     
    165175if Param.CheckMask
    166176    for iview=1:numel(Param.MaskTable)
    167 %     MaskData=cell(NbView,1);
    168 %     MaskSubDir=regexprep(Param.InputTable{iview,2},'\..*','');%take the root part of SubDir, before the first dot '.'
    169 %     MaskName=fullfile(Param.InputTable{iview,1},[MaskSubDir '.mask'],'mask_1.png');
    170 %     if exist(MaskName,'file')
    171         [MaskData{iview},tild,errormsg] = read_field(Param.MaskTable{iview},'image');
    172         if ~isempty(transform_fct) && nargin(transform_fct)>=2
    173             MaskData{iview}=transform_fct(MaskData{iview},XmlData{iview});
     177        if exist(Param.MaskTable{iview},'file')
     178            [MaskData{iview},tild,errormsg] = read_field(Param.MaskTable{iview},'image');
     179            if ~isempty(transform_fct) && nargin(transform_fct)>=2
     180                MaskData{iview}=transform_fct(MaskData{iview},XmlData{iview});
     181            end
    174182        end
    175183    end
     
    193201        return
    194202    end
     203   
    195204    %%%%%%%%%%%%%%%% loop on views (input lines) %%%%%%%%%%%%%%%%
    196205    Data=cell(1,NbView);%initiate the set Data
     
    239248        end
    240249    end
    241     %----------END LOOP ON VIEWS----------------------
     250    %%%%%%%%%%%%%%%% END LOOP ON VIEWS %%%%%%%%%%%%%%%%
    242251
    243252    %% merge the NbView fields
     
    248257    end
    249258
    250     % time of the merged field:
     259    %% time of the merged field: take the average of the different views
    251260    if ~isempty(time)% time defined from ImaDoc
    252261        timeread=time(:,index);
     
    254263    timeread=mean(timeread);
    255264
    256     % generating the name of the merged field
    257     i1=i1_series{iview}(index);
    258     if ~isempty(i2_series{iview})
    259         i2=i2_series{iview}(index);
     265    %% generating the name of the merged field
     266    i1=i1_series{1}(index);
     267    if ~isempty(i2_series{end})
     268        i2=i2_series{end}(index);
    260269    else
    261270        i2=i1;
     
    263272    j1=1;
    264273    j2=1;
    265     if ~isempty(j1_series{iview})
    266         j1=j1_series{iview}(index);
    267         if ~isempty(j2_series{iview})
    268             j2=j2_series{iview}(index);
     274    if ~isempty(j1_series{1})
     275        j1=j1_series{1}(index);
     276        if ~isempty(j2_series{end})
     277            j2=j2_series{end}(index);
    269278        else
    270279            j2=j1;
    271280        end
    272281    end
    273     OutputFile=fullfile_uvmat(RootPath{1},OutputDir,RootFile{1},FileExtOut,NomType{1},i1,i2,j1,j2);
    274 
    275     % recording the merged field
    276     if CheckImage{1}    %in case of input images an image is produced
    277         if isa(MergeData.A,'uint8')
    278             bitdepth=8;
    279         elseif isa(MergeData.A,'uint16')
    280             bitdepth=16;
    281         end
    282         imwrite(MergeData.A,OutputFile,'BitDepth',bitdepth);
    283         %write xml calibration file
    284         siz=size(MergeData.A);
    285         npy=siz(1);
    286         npx=siz(2);
    287         if isfield(MergeData,'VarAttribute')&&isfield(MergeData.VarAttribute{1},'Coord_2')&&isfield(MergeData.VarAttribute{1},'Coord_1')
    288             Rangx=MergeData.VarAttribute{1}.Coord_2;
    289             Rangy=MergeData.VarAttribute{1}.Coord_1;
    290         elseif isfield(MergeData,'AX')&& isfield(MergeData,'AY')
    291             Rangx=[MergeData.AX(1) MergeData.AX(end)];
    292             Rangy=[MergeData.AY(1) MergeData.AY(end)];
     282    OutputFile=fullfile_uvmat(RootPath{1},OutputDir,RootFileOut,FileExtOut,NomType{1},i1,i2,j1,j2);
     283
     284    %% recording the merged field
     285    if strcmp(FileExtOut,'.png')    %output as image
     286        if BitDepth==8
     287            imwrite(uint8(MergeData.A),OutputFile,'BitDepth',8)
    293288        else
    294             Rangx=[0.5 npx-0.5];
    295             Rangy=[npy-0.5 0.5];%default
    296         end
    297         pxcmx=(npx-1)/(Rangx(2)-Rangx(1));
    298         pxcmy=(npy-1)/(Rangy(1)-Rangy(2));
    299         T_x=-pxcmx*Rangx(1)+0.5;
    300         T_y=-pxcmy*Rangy(2)+0.5;
    301         GeometryCal.focal=1;
    302         GeometryCal.R=[pxcmx,0,0;0,pxcmy,0;0,0,1];
    303         GeometryCal.Tx_Ty_Tz=[T_x T_y 1];
    304         ImaDoc.GeometryCalib=GeometryCal;
     289            imwrite(uint16(MergeData.A),OutputFile,'BitDepth',16)
     290        end
     291        if index==1
     292            %write xml calibration file, using the first file
     293            siz=size(MergeData.A);
     294            npy=siz(1);
     295            npx=siz(2);
     296            if isfield(MergeData,'coord_x') && isfield(MergeData,'coord_y')
     297                Rangx=MergeData.coord_x;
     298                Rangy=MergeData.coord_y;
     299            elseif isfield(MergeData,'AX')&& isfield(MergeData,'AY')
     300                Rangx=[MergeData.AX(1) MergeData.AX(end)];
     301                Rangy=[MergeData.AY(1) MergeData.AY(end)];
     302            else
     303                Rangx=[0.5 npx-0.5];
     304                Rangy=[npy-0.5 0.5];%default
     305            end
     306            pxcmx=(npx-1)/(Rangx(2)-Rangx(1));
     307            pxcmy=(npy-1)/(Rangy(1)-Rangy(2));
     308            T_x=-pxcmx*Rangx(1)+0.5;
     309            T_y=-pxcmy*Rangy(2)+0.5;
     310            GeometryCal.CalibrationType='rescale';
     311            GeometryCal.CoordUnit=MergeData.CoordUnit;
     312            GeometryCal.focal=1;
     313            GeometryCal.R=[pxcmx,0,0;0,pxcmy,0;0,0,1];
     314            GeometryCal.Tx_Ty_Tz=[T_x T_y 1];
     315            ImaDoc.GeometryCalib=GeometryCal;
     316            t=struct2xml(ImaDoc);
     317            t=set(t,1,'name','ImaDoc');
     318            save(t,[fileparts(OutputFile) '.xml'])
     319        end
     320       
    305321    else
    306322        MergeData.ListGlobalAttribute={'Conventions','Project','InputFile_1','InputFile_end','nb_coord','nb_dim','dt','Time','civ'};
     
    342358end
    343359error=0;
     360MergeData=Data{1};% merged field= first field by default, reproduces the glabal attributes of the first field
    344361NbView=length(Data);
    345362if NbView==1
    346363    return
    347364end
    348 MergeData=Data{1};% merged field= first field by default, reproduces the glabal attributes of the first field
    349365
    350366%% group the variables (fields of 'Data') in cells of variables with the same dimensions
Note: See TracChangeset for help on using the changeset viewer.