Ignore:
Timestamp:
Apr 4, 2013, 10:54:25 PM (11 years ago)
Author:
sommeria
Message:

bugs corrected in series, ima_levels cleaned as exemple

File:
1 edited

Legend:

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

    r602 r604  
    44% function GUI_input=ima_levels(Param)
    55%
     6%------------------------------------------------------------------------
    67%%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%%
    78%
    8 % This function is used in four modes by the GUI series:
    9 %           1) config GUI: with no input argument, the function determine the suitable GUI configuration
    10 %           2) interactive input: the function is used to interactively introduce input parameters, and then stops
    11 %           3) RUN: the function itself runs, when an appropriate input  structure Param has been introduced.
    12 %           4) BATCH: the function itself proceeds in BATCH mode, using an xml file 'Param' as input.
    13 %
    149%OUTPUT
    15 % GUI_input=list of options in the GUI series.fig needed for the function
     10% ParamOut: sets options in the GUI series.fig needed for the function
    1611%
    1712%INPUT:
    1813% In run mode, the input parameters are given as a Matlab structure Param copied from the GUI series.
    1914% In batch mode, Param is the name of the corresponding xml file containing the same information
    20 % In the absence of input (as activated when the current Action is selected
    21 % in series), the function ouput GUI_input set the activation of the needed GUI elements
    22 %
    23 % Param contains the elements:(use the menu bar command 'export/GUI config' in series to see the current structure Param)
     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)
    2420%    .InputTable: cell of input file names, (several lines for multiple input)
    2521%                      each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension}
    2622%    .OutputSubDir: name of the subdirectory for data outputs
    27 %    .OutputDir: directory for data outputs, including path
     23%    .OutputDirExt: directory extension for data outputs
    2824%    .Action: .ActionName: name of the current activated function
    2925%             .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%             
    3030%    .IndexRange: set the file or frame indices on which the action must be performed
    3131%    .FieldTransform: .TransformName: name of the selected transform function
    3232%                     .TransformPath:   path  of the selected transform function
    33 %                     .TransformHandle: corresponding function handle
    3433%    .InputFields: sub structure describing the input fields withfields
    35 %              .FieldName: name of the field
     34%              .FieldName: name(s) of the field
    3635%              .VelType: velocity type
    3736%              .FieldName_1: name of the second field in case of two input series
    3837%              .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
    3940%    .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object)
    4041%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     
    4445%% set the input elements needed on the GUI series when the action is selected in the menu ActionName
    4546if isstruct(Param) && isequal(Param.Action.RUN,0)
    46     ParamOut.NbViewMax=1;% max nbre of input file series (default='' , no limitation)
     47    ParamOut.NbViewMax=1;% max nbre of input file series (default , no limitation)
    4748    ParamOut.AllowInputSort='off';% allow alphabetic sorting of the list of input file SubDir (options 'off'/'on', 'off' by default)
    4849    ParamOut.WholeIndexRange='off';% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
     
    5455    ParamOut.Mask='off';%can use mask option   (option 'off'/'on', 'off' by default)
    5556    ParamOut.OutputDirExt='.lev';%set the output dir extension
    56     ParamOut.OutputFileMode='NbInput';%NbInput= 1 output file per input file index, NbInput_i=1 fileper input file index i,NbSlice= 1 file per slice
     57    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
     58    %check the type of the existence and type of the first input file:
     59    Param.IndexRange.last_i=Param.IndexRange.first_i;%keep only the first index in the series
     60    Param.IndexRange.last_j=Param.IndexRange.first_j;
     61    filecell=get_file_series(Param);
     62    if ~exist(filecell{1,1},'file')
     63        msgbox_uvmat('WARNING','the first input file does not exist')
     64    else
     65        FileType=get_file_type(filecell{1,1});
     66        if isempty(find(strcmp(FileType,{'image','multimage','mmreader','video'})));% =1 for images
     67            msgbox_uvmat('ERROR',['bad input file type for ' mfilename ': an image is needed'])
     68        end
     69    end
    5770return
    5871end
     
    6679end
    6780
    68 ParamOut=Param; %default output
    69 if ~isfield(Param,'InputFields')
    70     Param.InputFields.FieldName='';
    71 end
    72 OutputSubDir=[Param.OutputSubDir Param.OutputDirExt];% subdirectory for output files
    73 
    74 %% root input file(s) and type
     81%% root input file names and nomenclature type (cell arrays with one element)
    7582RootPath=Param.InputTable(:,1);
    7683RootFile=Param.InputTable(:,3);
     
    7885NomType=Param.InputTable(:,4);
    7986FileExt=Param.InputTable(:,5);
    80 OutputSubDir=[Param.OutputSubDir Param.OutputDirExt];% subdirectory for output files
    81 
    82 % get the set of input file names (cell array filecell), and the lists of
    83 % input file or frame indices i1_series,i2_series,j1_series,j2_series
     87
     88%% subdirectory for output files
     89SubdirOut=[Param.OutputSubDir Param.OutputDirExt];
     90
     91%% get the set of input file names (cell array filecell), and file indices
    8492[filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
    8593% filecell{iview,fileindex}: cell array representing the list of file names
     
    8896% 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
    8997% i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices
    90 % set of frame indices used for movie or multimage input
    91 % numbers of slices and file indices
    92 
    93 NbSlice=1;%default
    94 if isfield(Param.IndexRange,'NbSlice')
    95     NbSlice=Param.IndexRange.NbSlice;
    96 end
    97 nbview=numel(i1_series);%number of input file series (lines in InputTable)
    98 nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
     98nbfield_j=size(j1_series{1},1); %nb of fields for the j index (bursts or volume slices)
    9999nbfield_i=size(i1_series{1},2); %nb of fields for the i index
    100100nbfield=nbfield_j*nbfield_i; %total number of fields
    101 nbfield_i=floor(nbfield/NbSlice);%total number of  indexes in a slice (adjusted to an integer number of slices)
    102 nbfield=nbfield_i*NbSlice; %total number of fields after adjustement
    103 
    104 %determine the file type on each line from the first input file
    105 ImageTypeOptions={'image','multimage','mmreader','video'};%allowed input file types(images)
    106 
    107 [FileType{1},FileInfo{1},MovieObject{1}]=get_file_type(filecell{1,1});
    108 CheckImage{1}=~isempty(find(strcmp(FileType,ImageTypeOptions)));% =1 for images
     101[FileType{1},FileInfo{1},VideoObject{1}]=get_file_type(filecell{1,1});% type of input file
     102
     103%% frame index for movie or multimage file input 
    109104if ~isempty(j1_series{1})
    110105    frame_index{1}=j1_series{1};
     
    125120 % EDIT FROM HERE
    126121
    127  %% check the validity of  input file types
    128 if CheckImage{1}
    129     FileExtOut='.png'; % write result as .png images for image inputs
    130     if strcmp(lower(NomType{1}(end)),'a')
    131         NomTypeOut=NomType{1};
    132     else
    133         NomTypeOut='_1_1';
    134     end
    135 else
    136     msgbox_uvmat('ERROR',['invalid file type input: ' FileType{1} ' not an image'])
    137     return
    138 end
     122 %% Extension and indexing nomenclature for output file
     123 FileExtOut='.png'; % write result as .png images for image inputs
     124 if strcmpi(NomType{1}(end),'a')
     125     NomTypeOut=NomType{1};
     126 else
     127     NomTypeOut='_1_1';
     128 end
    139129
    140130%% Set field names and velocity types
     
    153143j1=[];%default
    154144for ifile=1:nbfield
    155           if checkrun
    156                 stopstate=get(Param.RUNHandle,'BusyAction');
    157                 update_waitbar(Param.WaitbarHandle,ifile/nbfield)
    158           else
    159                 stopstate='queue';
    160           end
    161     if isequal(stopstate,'queue') % enable STOP command
    162         if ~isempty(j1_series)&&~isequal(j1_series,{[]})
    163             j1=j1_series{1}(ifile);
    164         end
    165         filename=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},NomType{1},i1_series{1}(ifile),[],j1);
    166         A=read_image(filename,FileType{1},MovieObject{1},frame_index{1}(ifile));
    167         if ndims(A)==3;%color images
    168             A=sum(double(Aread),3);% take the sum of color components
    169         end
    170         % operation on images
    171         A=levels(A);
    172         filename_new=fullfile_uvmat(RootPath{1},OutputSubDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(ifile),[],j1);
    173         imwrite(A,filename_new)
    174         display([filename_new ' written'])
    175     end
     145    if checkrun
     146        stopstate=get(Param.RUNHandle,'BusyAction');
     147        update_waitbar(Param.WaitbarHandle,ifile/nbfield)
     148    else
     149        stopstate='queue';
     150    end
     151    if ~isequal(stopstate,'queue') % enable STOP command
     152        break
     153    end
     154    if ~isempty(j1_series)&&~isequal(j1_series,{[]})
     155        j1=j1_series{1}(ifile);
     156    end
     157    filename=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},NomType{1},i1_series{1}(ifile),[],j1);
     158    A=read_image(filename,FileType{1},VideoObject{1},frame_index{1}(ifile));
     159    if ndims(A)==3;%color images
     160        A=sum(double(Aread),3);% take the sum of color components
     161    end
     162    % operation on images
     163    A=levels(A);
     164    % write output file
     165    filename_new=fullfile_uvmat(RootPath{1},SubdirOut,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(ifile),[],j1);
     166    imwrite(A,filename_new)
     167    display([filename_new ' written'])
    176168end
    177169%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Note: See TracChangeset for help on using the changeset viewer.