Changeset 454 for trunk


Ignore:
Timestamp:
Jun 13, 2012, 5:04:14 PM (12 years ago)
Author:
sommeria
Message:

aver_stat, ima_levels , sub_background now adapted to the new settings
merge_proj, time_series still need to be modified

Location:
trunk/src/series
Files:
3 edited

Legend:

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

    r451 r454  
    6363% get the set of input file names (cell array filecell), and the lists of
    6464% input file or frame indices i1_series,i2_series,j1_series,j2_series
     65
    6566[filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
     67
    6668% filecell{iview,fileindex}: cell array representing the list of file names
    6769%        iview: line in the table corresponding to a given file series
     
    7072% i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices
    7173% set of frame indices used for movie or multimage input
    72 if ~isempty(j1_series)
    73     frame_index=j1_series;
    74 else
    75     frame_index=i1_series;
    76 end
     74
    7775
    7876%% root input file(s) and type
     
    8886    NbSlice=Param.IndexRange.NbSlice;
    8987end
    90 nbview=size(i1_series,1);%number of input file series (lines in InputTable)
    91 nbfield_j=size(i1_series,2); %nb of consecutive fields at each level(burst
    92 nbfield=nbfield_j*size(i1_series,3); %total number of files or frames
    93 nbfield_i=floor(nbfield/NbSlice);%total number of i indexes (adjusted to an integer number of slices)
    94 nbfield=nbfield_i*nbfield_j; %total number of fields after adjustement
     88nbview=numel(i1_series);%number of input file series (lines in InputTable)
     89nbfield_j=size(i1_series{1},1); %nb of consecutive fields for the j index (bursts or volume slices)
     90nbfield_i=size(i1_series{1},2); %nb of consecutive fields for the i index
     91nbfield=nbfield_j*nbfield_i; %total number of files or frames
     92nbfield_i=floor(nbfield/NbSlice);%total number of  indexes in a slice (adjusted to an integer number of slices)
     93nbfield=nbfield_i*NbSlice; %total number of fields after adjustement
    9594
    9695%determine the file type on each line from the first input file
     
    106105    CheckImage{iview}=~isempty(find(strcmp(FileType{iview},ImageTypeOptions)));% =1 for images
    107106    CheckNc{iview}=~isempty(find(strcmp(FileType{iview},NcTypeOptions)));% =1 for netcdf files
     107    if ~isempty(j1_series{iview})
     108        frame_index{iview}=j1_series{iview};
     109    else
     110        frame_index{iview}=i1_series{iview};
     111    end
    108112end
    109113
     
    178182    end   
    179183end
    180 if size(time,2) < i2_series(1,end) || size(time,3) < j2_series(1,end)% time array absent or too short in ImaDoc xml file'
     184if size(time,2) < i2_series{1}(end) || size(time,3) < j2_series{1}(end)% time array absent or too short in ImaDoc xml file'
    181185    time=[];
    182186end
     
    279283       
    280284        %%%%%%%%%%%%%%%% loop on views (input lines) %%%%%%%%%%%%%%%%
     285        index
    281286        for iview=1:nbview
    282287            % reading input file(s)
    283             [Data{iview},ParamOut,errormsg] = read_field(filecell{iview,index},FileType{iview},InputFields{iview},frame_index(iview,index));
     288            [Data{iview},ParamOut,errormsg] = read_field(filecell{iview,index},FileType{iview},InputFields{iview},frame_index{iview}(index));
    284289            if ~isempty(errormsg)
    285290                errormsg=['error of input reading: ' errormsg];
     
    287292            end
    288293            if ~isempty(NbSlice_calib)
    289                 Data{iview}.ZIndex=mod(i1_series(iview,index)-1,NbSlice_calib{1})+1;%Zindex for phys transform
     294                Data{iview}.ZIndex=mod(i1_series{iview}(index)-1,NbSlice_calib{iview})+1;%Zindex for phys transform
    290295            end
    291296        end
     
    373378        end
    374379    else  % time from ImaDoc prevails
    375         DataOut.Time=time(1,i1_series(1,1),j1_series(1,1));
    376         DataOut.Time_end=time(end,i1_series(end,end),j1_series(end,end));
     380        DataOut.Time=time(1,i1_series{1}(1),j1_series{1}(1));
     381        DataOut.Time_end=time(end,i1_series{end}(end),j1_series{end}(end));
    377382    end
    378383   
    379384    %writing the result file
    380     OutputFile=fullfile_uvmat(RootPath{1},Param.OutputSubDir,RootFile{1},FileExtOut,NomTypeOut,i1_series(1,1),i1_series(1,end),i_slice,[]);
     385    OutputFile=fullfile_uvmat(RootPath{1},Param.OutputSubDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(1),i1_series{1}(end),i_slice,[]);
    381386    if CheckImage{1} %case of images
    382387        if isequal(FileInfo{1}.BitDepth,16)||(numel(FileInfo)==2 &&isequal(FileInfo{2}.BitDepth,16))
  • trunk/src/series/ima_levels.m

    r447 r454  
    1 %'ima_levels': rescale the image intensity to reduce strong luminosity peaks
     1%'ima_levels': rescale the image intensity to reduce strong luminosity peaks (their blinking effects often perturbs PIV))
     2% this function can be used as a template for applying a transform (here 'levels.m') on each image of a series
    23%------------------------------------------------------------------------
    3 % function GUI_input=ima_levels(num_i1,num_i2,num_j1,num_j2,Series)
     4% function GUI_input=ima_levels(Param)
    45%
     6%%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%%
    57%OUTPUT
    68% GUI_input=list of options in the GUI series.fig needed for the function
    79%
    810%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% relabel_i_j: relabel an image series with two indices, according to the time matrix given by ImaDoc
    14 %----------------------------------------------------------------------
    15 function GUI_input=ima_levels(Param)
    16 %requests for the visibility of input windows in the GUI series  (activated directly by the selection in the menu ACTION)
    17 if ~exist('Param','var')
    18     GUI_input={'OutputDirExt';'.lev'};
    19     return %exit the function
     11% In run mode, the input parameters are given as a Matlab structure Param copied from the GUI series.
     12% In batch mode, Param is the name of the corresponding xml file containing the same information
     13% In the absence of input (as activated when the current Action is selected
     14% in series), the function ouput GUI_input set the activation of the needed GUI elements
     15%
     16% Param contains the elements:(use the menu bar command 'export/GUI config' in series to see the current structure Param)
     17%    .InputTable: cell of input file names, (several lines for multiple input)
     18%                      each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension}
     19%    .OutputSubDir: name of the subdirectory for data outputs
     20%    .OutputDir: directory for data outputs, including path
     21%    .Action: .ActionName: name of the current activated function
     22%             .ActionPath:   path of the current activated function
     23%    .IndexRange: set the file or frame indices on which the action must be performed
     24%    .FieldTransform: .TransformName: name of the selected transform function
     25%                     .TransformPath:   path  of the selected transform function
     26%                     .TransformHandle: corresponding function handle
     27%    .InputFields: sub structure describing the input fields withfields
     28%              .FieldName: name of the field
     29%              .VelType: velocity type
     30%              .FieldName_1: name of the second field in case of two input series
     31%              .VelType_1: velocity type of the second field in case of two input series
     32%    .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object)
     33%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     34 
     35function GUI_input=ima_levels (Param)
     36
     37%% set the input elements needed on the GUI series when the action is selected in the menu ActionName
     38if ~exist('Param','var') % case with no input parameter
     39    GUI_input={'NbViewMax';1;...% max nbre of input file series (default='' , no limitation)
     40        'AllowInputSort';'off';...% allow alphabetic sorting of the list of input files (options 'off'/'on', 'off' by default)
     41        'NbSlice';'off'; ...%nbre of slices ('off' by default)
     42        'VelType';'off';...% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
     43        'FieldName';'off';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
     44        'FieldTransform'; 'off';...%can use a transform function
     45        'ProjObject';'off';...%can use projection object(option 'off'/'on',
     46        'Mask';'off';...%can use mask option   (option 'off'/'on', 'off' by default)
     47        'OutputDirExt';'.lev';...%set the output dir extension
     48               ''};
     49        return
    2050end
    2151
    22 %% input parameters
    23 % read the xml file for batch case
    24 if ischar(Param) && ~isempty(find(regexp('Param','.xml$')))
     52%% get input parameters, file names and indices
     53% BATCH  case: read the xml file for batch case
     54if ischar(Param) && ~isempty(find(regexp(Param,'.xml$')))
    2555    Param=xml2struct(Param);
    2656    checkrun=0;
    27 else %  RUN case: parameters introduced as the input structure Param
     57% RUN case: parameters introduced as the input structure Param 
     58else
    2859    hseries=guidata(Param.hseries);%handles of the GUI series
    29     WaitbarPos=get(hseries.waitbar_frame,'Position');
    30     checkrun=1;
     60    WaitbarPos=get(hseries.waitbar_frame,'Position');%position of the waitbar on the GUI series
     61    checkrun=1; % indicate the RUN option is used
    3162end
    32 %filebase=fullfile(Param.InputTable{1,1},Param.InputTable{1,3});
    33 RootPath=Param.InputTable{1,1};
    34 Subdir=Param.InputTable{1,2};
    35 RootFile=Param.InputTable{1,3};
    36 NomType=Param.InputTable{1,4};
    37 FileExt=Param.InputTable{1,5};
    38 [filecell,i1_series,i2_series,j1_series]=get_file_series(Param);% list of input files and indices
    39 if size(filecell,1)>1
    40     msgbox_uvmat('WARNING','This function uses only the first input image series')
     63
     64% get the set of input file names (cell array filecell), and the lists of
     65[filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
     66
     67%% root input file(s) and type
     68RootPath=Param.InputTable(:,1);
     69RootFile=Param.InputTable(:,3);
     70SubDir=Param.InputTable(:,2);
     71NomType=Param.InputTable(:,4);
     72FileExt=Param.InputTable(:,5);
     73
     74% numbers of slices and file indices
     75NbSlice=1;%default
     76if isfield(Param.IndexRange,'NbSlice')
     77    NbSlice=Param.IndexRange.NbSlice;
     78end
     79nbview=numel(i1_series);%number of input file series (lines in InputTable)
     80nbfield_j=size(i1_series{1},1); %nb of consecutive fields for the j index (bursts or volume slices)
     81nbfield_i=size(i1_series{1},2); %nb of consecutive fields for the i index
     82nbfield=nbfield_j*nbfield_i; %total number of files or frames
     83nbfield_i=floor(nbfield/NbSlice);%total number of  indexes in a slice (adjusted to an integer number of slices)
     84nbfield=nbfield_i*NbSlice; %total number of fields after adjustement
     85
     86%determine the file type on each line from the first input file
     87ImageTypeOptions={'image','multimage','mmreader','video'};%allowed input file types(images)
     88[FileType{1},FileInfo{1},MovieObject{1}]=get_file_type(filecell{1,1});
     89CheckImage{1}=~isempty(find(strcmp(FileType,ImageTypeOptions)));% =1 for images
     90if ~isempty(j1_series{1})
     91    frame_index{1}=j1_series{1};
     92else
     93    frame_index{1}=i1_series{1};
     94end
     95
     96%% calibration data and timing: read the ImaDoc files
     97%not relevant for this function
     98
     99%% check coincidence in time for several input file series
     100%not relevant for this function
     101
     102%% coordinate transform or other user defined transform
     103%not relevant for this function
     104
     105%%%%%%%%%%%% END STANDARD PART  %%%%%%%%%%%%
     106 % EDIT FROM HERE
     107
     108 %% check the validity of  input file types
     109if CheckImage{1}
     110    FileExtOut='.png'; % write result as .png images for image inputs
     111    if strcmp(lower(NomType{1}(end)),'a')
     112        NomTypeOut=NomType{1};
     113    else
     114        NomTypeOut='_1_1';
     115    end
     116else
     117    msgbox_uvmat('ERROR',['invalid file type input: ' FileType{1} ' not an image'])
    41118    return
    42119end
    43120
    44 %% determine input image type
    45 [FileType,FileInfo,MovieObject]=get_file_type(filecell{1,1});
    46 ListTypes={'image','multimage','mmreader','video'};
     121%% Set field names and velocity types
     122%not relevant for this function
    47123
    48 if isempty(strcmp(FileType,ListTypes))% if the detected FileType is not in the list for images
    49     msgbox_uvmat('ERROR',['invalid file extension ' FileExt ': this function only accepts image or movie input'])
    50     return
    51 end
     124%% Initiate output fields
     125%not relevant for this function
    52126
    53 %% create dir of the new images
    54 SubdirResult=[Param.InputTable{1,2} '.lev'];% add the suffix '.lev' to the name of the image folder
    55 try
    56     mkdir(fullfile(Param.InputTable{1,1},SubdirResult));
    57 catch ME
    58     msgbox_uvmat('ERROR',['error in creating result directory: ' ME.message]);%display error msg for directory creation if fails
    59     return
    60 end
    61 [xx,msg2] = fileattrib(fullfile(Param.InputTable{1,1},SubdirResult),'+w','g'); %yield writing access (+w) to user group (g)
    62 if ~strcmp(msg2,'')
    63     msgbox_uvmat('ERROR',['pb of permission for ' fullfile(Param.InputTable{1,1},SubdirResult) ': ' msg2])%error message for directory creation
    64     return
    65 end
    66 msgbox_uvmat('CONFIRMATION','apply image rescaling function levels.m ');
     127%% set processing parameters
     128% not needed for this function
    67129
    68 %copy the xml file
    69 % if exist([basename '.xml'],'file')
    70 %     copyfile([basename '.xml'],[basename_new '.xml']);% copy the .civ file
    71 % end
     130%% update the xml file
     131% not needed for this function
    72132
    73 %% main loop
    74 nbfield=size(i1_series{1},2);
    75 nbfield2=size(i1_series{1},1);
     133%% main loop on images
     134j1=[];%default
    76135for ifile=1:nbfield
    77136    if checkrun
    78 %         update_waitbar(hseries.waitbar,WaitbarPos,ifile/nbfield)
    79137        update_waitbar(hseries.waitbar_frame,WaitbarPos,ifile/nbfield)
    80138        stopstate=get(hseries.RUN,'BusyAction');
     
    83141    end
    84142    if isequal(stopstate,'queue') % enable STOP command
    85         for jfile=1:nbfield2
    86             %filename=name_generator(basename,num_i1(jfile,ifile),num_j1(jfile,ifile),Series.FileExt,Series.NomType);
    87             %filename_new=name_generator(basename_new,num_i1(jfile,ifile),num_j1(jfile,ifile),'.png',Series.NomType);
    88             filename=fullfile_uvmat(RootPath,Subdir,RootFile,FileExt,NomType,i1_series{1}(jfile,ifile),[],j1_series{1}(jfile,ifile));
    89             switch FileType
    90                 case {'video','mmreader'}
    91                     A=read(MovieObject,i1_series{1}(jfile,ifile));
    92                     if strcmp(NomType,'*')
    93                         A=read(MovieObject,i1_series{1}(jfile,ifile));
    94                         NomType_out='_1';
    95                     else
    96                         A=imread(filename,j1_series{1}(jfile,ifile));
    97                         NomType_out='_1_1';
    98                     end
    99                 case {'vol','image'}
    100                     A=imread(filename);
    101                     NomType_out='_1';
    102                 case 'multimage'
    103                     if strcmp(NomType,'*')
    104                         A=imread(filename,i1_series{1}(jfile,ifile));
    105                         NomType_out='_1';
    106                     else
    107                         A=imread(filename,j1_series{1}(jfile,ifile));
    108                         NomType_out='_1_1';
    109                     end
    110             end
    111             C=levels(A);
    112             filename_new=fullfile_uvmat(RootPath,SubdirResult,RootFile,'.png',NomType_out,i1_series{1}(jfile,ifile),[],j1_series{1}(jfile,ifile));
    113             imwrite(C,filename_new)
    114             display([filename_new ' written'])
     143        if ~isempty(j1_series)
     144            j1=j1_series{1}(ifile);
    115145        end
     146        filename=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},NomType{1},i1_series{1}(ifile),[],j1);
     147        A=read_image(filename,FileType{1},MovieObject{1},frame_index{1}(ifile));
     148        if ndims(A)==3;%color images
     149            A=sum(double(Aread),3);% take the sum of color components
     150        end
     151        % operation on images
     152        A=levels(A);
     153        filename_new=fullfile_uvmat(RootPath{1},Param.OutputSubDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(ifile),[],j1);
     154        imwrite(A,filename_new)
     155        display([filename_new ' written'])
    116156    end
    117157end
    118158%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     159
    119160
    120161function C=levels(A)
  • trunk/src/series/sub_background.m

    r451 r454  
    99    % luminosity, but it can be polluted by noise.
    1010% Organization of image indices:
    11     % The program is working on a series of images, labelled by two indices i and j, given
    12     % by the input matlab vectors num_i1 and num_j1 respectively. In the list, j is the fastest increasing index.
    13     % The processing can be done in slices (number nbslice), with bursts of
    14     % nbfield2 successive images for a given slice (mode 'multilevel')
    15     % In the mode 'volume', nbfield2=1 (1 image at each level)
    16    
    17 % function GUI_input=sub_background(Param)
     11    % The program is working on a series of images,
     12    % The processing can be done over groups of nbfield2 consecutive files in slices (parameter NbSlice)
     13    % In the mode 'volume', nbfield2=1 (1 image at each level)and NbSlice (=nbfield_j)
     14    % Else nbfield2=nbfield_j =nbre of images in a burst (j index)
     15   
     16% function GUI_series_config=sub_background(Param)
    1817%
    1918%%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%%
    2019%OUTPUT
    21 % GUI_input=list of options in the GUI series.fig needed for the function
     20% GUI_series_config=list of options in the GUI series.fig needed for the function
    2221%
    2322%INPUT:
     
    2524% In batch mode, Param is the name of the corresponding xml file containing the same information
    2625% In the absence of input (as activated when the current Action is selected
    27 % in series), the function ouput GUI_input set the activation of the needed GUI elements
     26% in series), the function ouput GUI_series_config set the activation of the needed GUI elements
    2827%
    2928% Param contains the elements:(use the menu bar command 'export/GUI config' in series to see the current structure Param)
     
    4746
    4847   
    49 function GUI_input=sub_background (Param)
     48function GUI_config=sub_background (Param,get_param)
    5049
    5150%% set the input elements needed on the GUI series when the action is selected in the menu ActionName
    5251if ~exist('Param','var') % case with no input parameter
    53     GUI_input={'NbViewMax';1;...% max nbre of input file series (default='' , no limitation)
     52    GUI_config={'NbViewMax';1;...% max nbre of input file series (default='' , no limitation)
    5453        'AllowInputSort';'off';...% allow alphabetic sorting of the list of input files (options 'off'/'on', 'off' by default)
    5554        'NbSlice';'on'; ...%nbre of slices ('off' by default)
     
    5958        'ProjObject';'off';...%can use projection object(option 'off'/'on',
    6059        'Mask';'off';...%can use mask option   (option 'off'/'on', 'off' by default)
    61         'OutputDirExt';'.sbk';...%set the output dir extension
     60        'OutputDirExt';'.sback';...%set the output dir extension
    6261               ''};
    6362        return
     
    6766%% get input parameters, file names and indices
    6867% BATCH  case: read the xml file for batch case
    69 if ischar(Param) && ~isempty(find(regexp(Param,'.xml$')))
    70     Param=xml2struct(Param);
    71     checkrun=0;
    72 % RUN case: parameters introduced as the input structure Param 
    73 else
     68if exist('get_param','var') && isequal(get_param,0)
     69    checkrun=-1; %the function is just used to define to complement the input parameters
     70elseif ischar(Param) && ~isempty(find(regexp(Param,'.xml$'))) %batch mode
     71        Param=xml2struct(Param);
     72        checkrun=0;
     73    % RUN case: parameters introduced as the input structure Param
     74else
    7475    hseries=guidata(Param.hseries);%handles of the GUI series
    7576    WaitbarPos=get(hseries.waitbar_frame,'Position');%position of the waitbar on the GUI series
     
    8586% i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices
    8687% set of frame indices used for movie or multimage input
    87 if ~isempty(j1_series)
    88     frame_index=j1_series;
    89 else
    90     frame_index=i1_series;
    91 end
     88
    9289
    9390%% root input file(s) and type
     
    103100    NbSlice=Param.IndexRange.NbSlice;
    104101end
    105 nbview=size(i1_series,1);%number of input file series (lines in InputTable)
    106 nbfield_j=size(i1_series,2); %nb of consecutive fields at each level(burst
    107 nbfield=nbfield_j*size(i1_series,3); %total number of files or frames
    108 nbfield_i=floor(nbfield/NbSlice);%total number of i indexes (adjusted to an integer number of slices)
    109 nbfield=nbfield_i*nbfield_j; %total number of fields after adjustement
     102nbview=numel(i1_series);%number of input file series (lines in InputTable)
     103nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
     104nbfield_i=size(i1_series{1},2); %nb of fields for the i index
     105nbfield=nbfield_j*nbfield_i; %total number of fields
     106nbfield_i=floor(nbfield/NbSlice);%total number of  indexes in a slice (adjusted to an integer number of slices)
     107nbfield=nbfield_i*NbSlice; %total number of fields after adjustement
    110108
    111109%determine the file type on each line from the first input file
    112 ImageTypeOptions={'image','multimage','mmreader','video'};
    113 NcTypeOptions={'netcdf','civx','civdata'};
    114    
    115 % % for iview=1:nbview
    116 %     if ~exist(filecell{iview,1}','file')
    117 %         msgbox_uvmat('ERROR',['the first input file ' filecell{iview,1} ' does not exist'])
    118 %         return
    119 %     end
    120 %     [FileType{iview},FileInfo{iview},Object{iview}]=get_file_type(filecell{iview,1});
    121 %     CheckImage{iview}=~isempty(find(strcmp(FileType{iview},ImageTypeOptions)));% =1 for images
    122 %     CheckNc{iview}=~isempty(find(strcmp(FileType{iview},NcTypeOptions)));% =1 for netcdf files
    123 % end
    124 
    125 [FileType,FileInfo,MovieObject]=get_file_type(filecell{1,1});
    126 CheckImage=~isempty(find(strcmp(FileType,ImageTypeOptions)));% =1 for images
     110ImageTypeOptions={'image','multimage','mmreader','video'};%allowed input file types(images)
     111
     112[FileType{1},FileInfo{1},MovieObject{1}]=get_file_type(filecell{1,1});
     113CheckImage{1}=~isempty(find(strcmp(FileType,ImageTypeOptions)));% =1 for images
     114if ~isempty(j1_series{1})
     115    frame_index{1}=j1_series{1};
     116else
     117    frame_index{1}=i1_series{1};
     118end
    127119
    128120%% calibration data and timing: read the ImaDoc files
     
    139131
    140132 %% check the validity of  input file types
    141 if CheckImage
     133if CheckImage{1}
    142134    FileExtOut='.png'; % write result as .png images for image inputs
    143     NomTypeOut='_1_1';
     135    if strcmp(lower(NomType{1}(end)),'a')
     136        NomTypeOut=NomType{1};%case of letter appendix
     137    else
     138        NomTypeOut='_1_1';% caseof purely numerical indexing
     139    end
    144140else
    145141    msgbox_uvmat('ERROR',['invalid file type input: ' FileType{1} ' not an image'])
    146142    return
    147143end
    148 %
    149 % NomTypeOut='_1-2_1';% output file index will indicate the first and last ref index in the series
    150 % if NbSlice~=nbfield_j
    151 %     answer=msgbox_uvmat('INPUT_Y-N',['will not average slice by slice: for so cancel and set NbSlice= ' num2str(nbfield_j)]);
    152 %     if ~strcmp(answer,'Yes')
    153 %         return
    154 %     end
    155 % end
    156144
    157145%% Set field names and velocity types
    158146%not relevant here
    159 
    160147
    161148%% Initiate output fields
     
    164151%%% SPECIFIC PART BEGINS HERE
    165152NbSlice=Param.IndexRange.NbSlice; %number of slices
    166 siz=size(i1_series);
     153%siz=size(i1_series);
    167154nbaver_init=23;%approximate number of images used for the sliding background: to be adjusted later to include an integer number of bursts
    168155j1=[];%default
    169156
    170 %% apply the image rescaling function 'level' (avoid the blinking effects of bright particles)
    171 answer=msgbox_uvmat('INPUT_Y-N','apply image rescaling function levels.m after sub_background');
    172 test_level=isequal(answer,'Yes');
    173 
    174157%% adjust the proposed number of images in the sliding average to include an integer number of bursts
    175 if siz(3)~=1
    176     nbaver=floor(nbaver_init/siz(2)); % number of bursts used for the sliding background,
     158if nbfield_i~=1
     159    nbaver=floor(nbaver_init/nbfield_j); % number of bursts used for the sliding background,
    177160    if isequal(floor(nbaver/2),nbaver)
    178161        nbaver=nbaver+1;%put the number of burst to an odd number (so the middle burst is defined)
    179162    end
    180     nbaver_init=nbaver*siz(2);%propose by default an integer number of bursts
     163    nbaver_init=nbaver*nbfield_j;%propose by default an integer number of bursts
    181164end
    182165
    183166%% set processing parameters
    184 prompt = {'Number of images for the sliding background (MUST FIT IN COMPUETER MEMORY)';'The number of positions (laser slices)';'volume scan mode (Yes/No)';...
    185     'the luminosity rank chosen to define the background (0.1=for dense particle seeding, 0.5 (median) for sparse particles'};
    186 dlg_title = ['get (slice by slice) a sliding background and substract to each image, result in subdir ' Param.OutputDir];
    187 num_lines= 3;
    188 def     = { num2str(nbaver_init);num2str(NbSlice);'No';'0.1'};
    189 answer = inputdlg(prompt,dlg_title,num_lines,def);
    190 set(hseries.ParamVal,'String',answer([1 [3:4]]))
    191 set(hseries.ParamVal,'Visible','on')
    192 
    193 nbaver_ima=str2num(answer{1});%number of images for the sliding background
    194 nbaver=ceil(nbaver_ima/siz(2));%number of bursts for the sliding background
    195 if isequal(floor(nbaver/2),nbaver)
    196     nbaver=nbaver+1;%put the number of burst to an odd number (so the middle burst is defined)
    197 end
    198 step=siz(2);%case of bursts: the sliding background is shifted by one burst
    199 vol_test=answer{3};
    200 if isequal(vol_test,'Yes')
    201     nbfield2=1;%case of volume: no consecutive series at a given level
    202     NbSlice=siz(2);%number of slices
     167if checkrun ==-1
     168    prompt = {'volume scan mode (Yes/No)';'Number of images for the sliding background (MUST FIT IN COMPUTER MEMORY)';...
     169        'the luminosity rank chosen to define the background (0.1=for dense particle seeding, 0.5 (median) for sparse particles'};
     170    dlg_title = ['get (slice by slice) a sliding background and substract to each image, result in subdir ' Param.OutputDir];
     171    num_lines= 3;
     172    def     = { 'No';num2str(nbaver_init);'0.1'};
     173    answer = inputdlg(prompt,dlg_title,num_lines,def);
     174   
     175    %check input consistency
     176    if strcmp(answer{1},'No') && ~isequal(NbSlice,1)
     177        check=msgbox_uvmat('INPUT_Y-N',['confirm the multi-level splitting into ' num2str(NbSlice) ' slices']);
     178        if ~strcmp(check,'Yes')
     179            return
     180        end
     181    end
     182    if strcmp(answer{1},'Yes')
     183        step=1;
     184    else
     185        step=nbfield_j;%case of bursts: the sliding background is shifted by the length of one burst
     186    end
     187    nbaver_ima=str2num(answer{2});%number of images for the sliding background
     188    nbaver=ceil(nbaver_ima/step);%number of bursts for the sliding background
     189    if isequal(floor(nbaver/2),nbaver)
     190        nbaver=nbaver+1;%set the number of bursts to an odd number (so the middle burst is defined)
     191    end
     192    nbaver_ima=nbaver*step;
     193    if nbaver_ima > nbfield
     194        msgbox_uvmat('ERROR','number of images in a slice smaller than the proposed number of images for the sliding average')
     195        return
     196    end
     197    GUI_config.CheckVolume=strcmp(answer{1},'Yes');
     198    GUI_config.SlidingSequenceSize=nbaver_ima;
     199    GUI_config.BrightnessRankThreshold=str2num(answer{3});
     200   
     201    % apply the image rescaling function 'level' (avoid the blinking effects of bright particles)
     202    answer=msgbox_uvmat('INPUT_Y-N','apply image rescaling function levels.m after sub_background');
     203    GUI_config.CheckLevelTransform=strcmp(answer,'Yes');
     204   
     205    % return to BATCH mode
     206    if checkrun==-1
     207        return %transfer to BATCH mode
     208    end
    203209else
    204     nbfield2=siz(2); %nb of consecutive images at each level(burst)
    205     if siz(3)>1
    206         % NbSlice=str2num(answer{2})/(num_i1(1,2)-num_i1(1,1));% number of slices
    207         NbSlice=str2num(answer{2})/(i1_series(1,1,2)-i1_series(1,1,1));% number of slices
     210    GUI_config=Param.Specific;
     211    if isequal(GUI_config.CheckVolume,1)
     212        step=1;
    208213    else
    209         NbSlice=1;
    210     end
    211     if ~isequal(floor(NbSlice),NbSlice)
    212         msgbox_uvmat('ERROR','the number of slices must be a multiple of the i increment')
     214        step=nbfield_j;%case of bursts: the sliding background is shifted by the length of one burst
     215    end
     216    nbaver_ima=GUI_config.SlidingSequenceSize;%number of images for the sliding background
     217    nbaver=ceil(nbaver_ima/step);%number of bursts for the sliding background
     218    if isequal(floor(nbaver/2),nbaver)
     219        nbaver=nbaver+1;%set the number of bursts to an odd number (so the middle burst is defined)
     220    end
     221    nbaver_ima=nbaver*step;
     222    if nbaver_ima > nbfield
     223        msgbox_uvmat('ERROR','number of images in a slice smaller than the proposed number of images for the sliding average')
    213224        return
    214225    end
    215226end
    216 rank=floor(str2num(answer{4})*nbaver_ima);
     227
     228% calculate absolute brightness rank
     229rank=floor(GUI_config.BrightnessRankThreshold*nbaver_ima);
    217230if rank==0
    218231    rank=1;%rank selected in the sorted image series
    219232end
    220 lengthtot=siz(2)*siz(3);
    221 nbfield=floor(lengthtot/(nbfield2*NbSlice));%total number of i indexes (adjusted to an integer number of slices)
    222 nbfield_slice=nbfield*nbfield2;% number of fields per slice
    223 if nbaver_ima > nbfield*nbfield2
    224     msgbox_uvmat('ERROR','number of images in a slice smaller than the proposed number of images for the sliding average')
    225     return
    226 end
    227 nbfirst=(ceil(nbaver/2))*step;
    228 if nbfirst>nbaver_ima
    229     nbfirst=ceil(nbaver_ima/2);
    230     step=1;
    231     nbaver=nbaver_ima;
    232 end
    233233
    234234%% prealocate memory for the sliding background
    235 Afirst=read_image(filecell{1,1},FileType{1},MovieObject,i1_series(1,1));
    236 [npy,npx]=size(Afirst);
    237235try
    238     Ak=zeros(npy,npx,nbaver_ima,'uint16'); %prealocate memory
    239     Asort=zeros(npy,npx,nbaver_ima,'uint16'); %prealocate memory
     236    Afirst=read_image(filecell{1,1},FileType{1},MovieObject{1},frame_index{1}(1));
     237    [npy,npx]=size(Afirst);
     238    if strcmp(class(Afirst),'uint8') % case of 8bit images
     239        Ak=zeros(npy,npx,nbaver_ima,'uint8'); %prealocate memory
     240        Asort=zeros(npy,npx,nbaver_ima,'uint8'); %prealocate memory
     241    else
     242        Ak=zeros(npy,npx,nbaver_ima,'uint16'); %prealocate memory
     243        Asort=zeros(npy,npx,nbaver_ima,'uint16'); %prealocate memory
     244    end
    240245catch ME
    241246    msgbox_uvmat('ERROR',ME.message)
     
    244249
    245250%% update the xml file
    246 SubDirBase=regexprep(Param.InputTable{1,2},'\..*','');%take the root part of SubDir, before the first dot '.'
    247 filexml=fullfile(RootPath{1},[SubDirBase '.xml']);
    248 if ~exist(filexml,'file') && exist([filebase '.xml'],'file')% xml inside the image directory
    249     copyfile([filebase '.xml'],filexml);% copy the .xml file
    250 end
    251 if exist(filexml,'file')
    252     t=xmltree(filexml); 
    253     %update information on the first image name in the series
    254     uid_Heading=find(t,'ImaDoc/Heading');
    255     if isempty(uid_Heading)
    256         [t,uid_Heading]=add(t,1,'element','Heading');
    257     end
    258     uid_ImageName=find(t,'ImaDoc/Heading/ImageName');
    259     if ~isempty(j1_series{1})
    260         j1=j1_series{1}(1);
    261     end
    262     ImageName=fullfile_uvmat([dir_images term],'',RootFile{1},'.png',NomType,i1_series(1,1),[],j1);
    263     [pth,ImageName]=fileparts(ImageName);
    264     ImageName=[ImageName '.png'];
    265     if isempty(uid_ImageName)
    266         [t,uid_ImageName]=add(t,uid_Heading,'element','ImageName');
    267     end
    268     uid_value=children(t,uid_ImageName);
    269     if isempty(uid_value)
    270         t=add(t,uid_ImageName,'chardata',ImageName);%indicate  name of the first image, with ;png extension
    271     else
    272         t=set(t,uid_value(1),'value',ImageName);%indicate  name of the first image, with ;png extension
    273     end
    274    
    275     %add information about image transform
    276     [t,new_uid]=add(t,1,'element','ImageTransform');
    277     [t,NameFunction_uid]=add(t,new_uid,'element','NameFunction');
    278     [t]=add(t,NameFunction_uid,'chardata','sub_background');
    279     if test_level
    280         [t,NameFunction_uid]=add(t,new_uid,'element','NameFunction');
    281         [t]=add(t,NameFunction_uid,'chardata','levels');
    282     end
    283     [t,NbSlice_uid]=add(t,new_uid,'element','NbSlice');
    284     [t]=add(t,new_uid,'chardata',num2str(NbSlice));
    285     [t,NbSlidingImages_uid]=add(t,new_uid,'element','NbSlidingImages');
    286     [t]=add(t,NbSlidingImages_uid,'chardata',num2str(nbaver));
    287     [t,LuminosityRank_uid]=add(t,new_uid,'element','RankBackground');
    288     [t]=add(t,LuminosityRank_uid,'chardata',num2str(rank));% luminosity rank almong the nbaver sliding images
    289     save(t,filexml)
    290 end
     251% SubDirBase=regexprep(Param.InputTable{1,2},'\..*','');%take the root part of SubDir, before the first dot '.'
     252% filexml=fullfile(RootPath{1},[SubDirBase '.xml']);
     253% if ~exist(filexml,'file') && exist([fullfile(RootPath{1},SubDir{1},RootFile{1}) '.xml'],'file')% xml inside the image directory
     254%     copyfile([filebase '.xml'],filexml);% copy the .xml file
     255% end
     256% if exist(filexml,'file')
     257%     t=xmltree(filexml); 
     258%     %update information on the first image name in the series
     259%     uid_Heading=find(t,'ImaDoc/Heading');
     260%     if isempty(uid_Heading)
     261%         [t,uid_Heading]=add(t,1,'element','Heading');
     262%     end
     263%     uid_ImageName=find(t,'ImaDoc/Heading/ImageName');
     264%     if ~isempty(j1_series{1})
     265%         j1=j1_series{1}(1);
     266%     end
     267%     ImageName=fullfile_uvmat([dir_images term],'',RootFile{1},'.png',NomType,i1_series(1,1),[],j1);
     268%     [pth,ImageName]=fileparts(ImageName);
     269%     ImageName=[ImageName '.png'];
     270%     if isempty(uid_ImageName)
     271%         [t,uid_ImageName]=add(t,uid_Heading,'element','ImageName');
     272%     end
     273%     uid_value=children(t,uid_ImageName);
     274%     if isempty(uid_value)
     275%         t=add(t,uid_ImageName,'chardata',ImageName);%indicate  name of the first image, with ;png extension
     276%     else
     277%         t=set(t,uid_value(1),'value',ImageName);%indicate  name of the first image, with ;png extension
     278%     end
     279%    
     280%     %add information about image transform
     281%     [t,new_uid]=add(t,1,'element','ImageTransform');
     282%     [t,NameFunction_uid]=add(t,new_uid,'element','NameFunction');
     283%     [t]=add(t,NameFunction_uid,'chardata','sub_background');
     284%     if GUI_config.CheckLevel
     285%         [t,NameFunction_uid]=add(t,new_uid,'element','NameFunction');
     286%         [t]=add(t,NameFunction_uid,'chardata','levels');
     287%     end
     288%     [t,NbSlice_uid]=add(t,new_uid,'element','NbSlice');
     289%     [t]=add(t,new_uid,'chardata',num2str(NbSlice));
     290%     [t,NbSlidingImages_uid]=add(t,new_uid,'element','NbSlidingImages');
     291%     [t]=add(t,NbSlidingImages_uid,'chardata',num2str(nbaver));
     292%     [t,LuminosityRank_uid]=add(t,new_uid,'element','RankBackground');
     293%     [t]=add(t,LuminosityRank_uid,'chardata',num2str(rank));% luminosity rank almong the nbaver sliding images
     294%     save(t,filexml)
     295% end
    291296%copy the mask
    292297% if exist([filebase '_1mask_1'],'file')
     
    297302for islice=1:NbSlice
    298303    %% select the series of image indices at the level islice
    299     for ifield=1:nbfield
    300         for iburst=1:nbfield2
    301             indselect(iburst,ifield)=((ifield-1)*NbSlice+(islice-1))*nbfield2+iburst;
    302         end
     304    indselect=islice:NbSlice*step:nbfield;% select file indices of the slice
     305    for ifield=1:step-1
     306        indselect=[indselect;indselect(end,:)+1];
    303307    end
    304308   
     
    307311        ifile=indselect(ifield);
    308312        filename=filecell{1,ifile};
    309         Aread=read_image(filename,FileType,MovieObject,i1_series{1}(ifile));
     313        Aread=read_image(filename,FileType{1},MovieObject{1},frame_index{1}(ifile));
     314        if ndims(Aread)==3;%color images
     315            Aread=sum(double(Aread),3);% take the sum of color components
     316        end
    310317        Ak(:,:,ifield)=Aread;
    311318    end
     
    313320    B=Asort(:,:,rank);%background image
    314321    display( 'first background image will be substracted')
     322    nbfirst=(ceil(nbaver/2))*step;
    315323    for ifield=1:nbfirst
    316324        Acor=double(Ak(:,:,ifield))-double(B);%substract background to the current image
    317325        Acor=(Acor>0).*Acor; % put to 0 the negative elements in Acor
    318         C=uint16(Acor);% set to integer 16 bits
    319326        ifile=indselect(ifield);
    320         %             newname=name_generator(filebase_b,num_i1(ifile),num_j1(ifile),'.png',NomType)% makes the new file name
    321327        if ~isempty(j1_series{1})
    322328            j1=j1_series{1}(ifile);
    323329        end
    324         newname=fullfile_uvmat(RootPath{1},Param.OutputSubDir,RootFile{1},FileExtOut,NomTypeOut,i1_series(1,ifile),[],i_slice,[]);
    325 %         newname=fullfile_uvmat(RootPath{1},SubdirResult,RootFile{1},'.png',NomType,i1_series{1}(ifile),[],j1);
    326         %newname=name_generator(filebase_b,i1_series{1}(ifile),j1_series{1}(ifile),'.png',NomType);% makes the new file name
    327         if test_level
    328             C=levels(C);
     330        newname=fullfile_uvmat(RootPath{1},Param.OutputSubDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(ifile),[],j1);
     331       
     332        %write result file
     333        if GUI_config.CheckLevelTransform
     334            C=levels(Acor);
    329335            imwrite(C,newname,'BitDepth',8); % save the new image
    330336        else
    331             imwrite(C,newname,'BitDepth',16); % save the new image
    332         end
    333     end
    334    
    335     %% repeat the operation on a sliding series of nbaver*nbfield2 images
     337            if isequal(FileInfo{1}.BitDepth,16)
     338                C=uint16(Acor);
     339                imwrite(C,newname,'BitDepth',16); % save the new image
     340            else
     341                C=uint8(Acor);
     342                imwrite(C,newname,'BitDepth',8); % save the new image
     343            end
     344        end
     345        display([newname ' written'])
     346    end
     347   
     348    %% repeat the operation on a sliding series of images
    336349    display('sliding background image will be substracted')
    337     if nbfield_slice > nbaver_ima
    338         for ifield = step*ceil(nbaver/2)+1:step:nbfield_slice-step*floor(nbaver/2)
     350    if nbfield_i > nbaver_ima
     351        for ifield = step*ceil(nbaver/2)+1:step:nbfield_i-step*floor(nbaver/2)
    339352            if checkrun
    340353                stopstate=get(hseries.RUN,'BusyAction');
    341                 update_waitbar(hseries.waitbar_frame,WaitbarPos,(ifield+(islice-1)*nbfield_slice)/(nbfield_slice*NbSlice))
     354                update_waitbar(hseries.waitbar_frame,WaitbarPos,(ifield+(islice-1)*nbfield_i)/(nbfield_i*NbSlice))
    342355            else
    343356                stopstate='queue';
     
    348361                for iburst=1:step
    349362                    ifile=indselect(ifield+step*floor(nbaver/2)+iburst-1);
    350                     filename=fullfile_uvmat(RootPath{1},SubDir,RootFile{1},FileExt,NomType,i1_series(1,ifile),[],j1_series(1,ifile));
    351                     %filename=name_generator(filebase,num_i1(ifile),num_j1(ifile),FileExt,NomType);
    352                     Aread=read_image(filename,FileType,MovieObject,i1_series(1,ifile));
     363                    filename=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},NomType{1},i1_series{1}(ifile),[],j1_series{1}(ifile));
     364                    Aread=read_image(filename,FileType{1},MovieObject{1},i1_series{1}(ifile));
     365                    if ndims(Aread)==3;%color images
     366                        Aread=sum(double(Aread),3);% take the sum of color components
     367                    end
    353368                    Ak(:,:,nbaver_ima-step+iburst)=Aread;
    354369                end
     
    359374                    Acor=double(Ak(:,:,index))-double(B);
    360375                    Acor=(Acor>0).*Acor; % put to 0 the negative elements in Acor
    361                     C=uint16(Acor);
    362376                    ifile=indselect(ifield+iburst-1);
    363377                    if ~isempty(j1_series{1})
    364378                        j1=j1_series{1}(ifile);
    365379                    end
    366                     newname=fullfile_uvmat(RootPath{1},Param.OutputSubDir,RootFile{1},FileExtOut,NomTypeOut,i1_series(1,1),[],i_slice,[]);
    367                    % newname=fullfile_uvmat(Param.InputTable{1,1},SubdirResult,Param.InputTable{1,3},'.png',NomType,i1_series{1}(ifile),[],j1);
    368                     %[newname]=name_generator(filebase_b,num_i1(ifile),num_j1(ifile),'.png',NomType) % makes the new file name
    369                     if test_level
    370                         C=levels(C);
     380                    newname=fullfile_uvmat(RootPath{1},Param.OutputSubDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(ifile),[],j1);
     381                    %write result file
     382                    if GUI_config.CheckLevelTransform
     383                        C=levels(Acor);
    371384                        imwrite(C,newname,'BitDepth',8); % save the new image
    372385                    else
    373                         imwrite(C,newname,'BitDepth',16); % save the new image
     386                        if isequal(FileInfo{1}.BitDepth,16)
     387                            C=uint16(Acor);
     388                            imwrite(C,newname,'BitDepth',16); % save the new image
     389                        else
     390                            C=uint8(Acor);
     391                            imwrite(C,newname,'BitDepth',8); % save the new image
     392                        end
    374393                    end
     394                    display([newname ' written'])
     395                   
    375396                end
    376397            else
     
    382403    %% substract the background from the last images
    383404    display('last background image will be substracted')
    384     ifield=nbfield_slice-(step*ceil(nbaver/2))+1:nbfield_slice;
    385     for ifield=nbfield_slice-(step*floor(nbaver/2))+1:nbfield_slice
    386         index=ifield-nbfield_slice+step*(2*floor(nbaver/2)+1);
     405    ifield=nbfield_i-(step*ceil(nbaver/2))+1:nbfield_i;
     406    for ifield=nbfield_i-(step*floor(nbaver/2))+1:nbfield_i
     407        index=ifield-nbfield_i+step*(2*floor(nbaver/2)+1);
    387408        Acor=double(Ak(:,:,index))-double(B);
    388409        Acor=(Acor>0).*Acor; % put to 0 the negative elements in Acor
    389         C=uint16(Acor);
    390410        ifile=indselect(ifield);
    391411        if ~isempty(j1_series{1})
    392412            j1=j1_series{1}(ifile);
    393413        end
    394         newname=fullfile_uvmat(RootPath{1},Param.OutputSubDir,RootFile{1},FileExtOut,NomTypeOut,i1_series(1,ifile),[],j1);
    395 %         newname=fullfile_uvmat(Param.InputTable{1,1},SubdirResult,Param.InputTable{1,3},'.png',NomType,i1_series{1}(ifile),[],j1);
    396         if test_level
    397             C=levels(C);
     414        newname=fullfile_uvmat(RootPath{1},Param.OutputSubDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(ifile),[],j1);
     415       
     416        %write result file
     417        if GUI_config.CheckLevelTransform
     418            C=levels(Acor);
    398419            imwrite(C,newname,'BitDepth',8); % save the new image
    399420        else
    400             imwrite(C,newname,'BitDepth',16); % save the new image
    401         end
     421            if isequal(FileInfo{1}.BitDepth,16)
     422                C=uint16(Acor);
     423                imwrite(C,newname,'BitDepth',16); % save the new image
     424            else
     425                C=uint8(Acor);
     426                imwrite(C,newname,'BitDepth',8); % save the new image
     427            end
     428        end
     429        display([newname ' written'])
    402430    end
    403431end
     
    406434if checkrun
    407435    update_waitbar(hseries.waitbar,WaitbarPos,1)
    408 end
    409 
    410 %------------------------------------------------------------------------
    411 %--read images and convert them to the uint16 format used for PIV
    412 function A=read_image(FileName,FileType,VideoObject,num)
    413 %------------------------------------------------------------------------
    414 %num is the view number needed for an avi movie
    415 switch FileType
    416     case {'video','mmreader'}
    417         A=read(VideoObject,num);
    418     case 'multimage'
    419         A=imread(FileName,num);
    420     case 'image'   
    421         A=imread(FileName);
    422 end
    423 siz=size(A);
    424 if length(siz)==3;%color images
    425     A=sum(double(A),3);% take the sum of color components
    426436end
    427437   
Note: See TracChangeset for help on using the changeset viewer.