Ignore:
Timestamp:
Jun 6, 2012, 2:46:15 PM (12 years ago)
Author:
sommeria
Message:

functions updated in series for the new file configuration

File:
1 edited

Legend:

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

    r349 r442  
    1313%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
    1414%----------------------------------------------------------------------
    15 function GUI_input=ima_levels(num_i1,num_i2,num_j1,num_j2,Series)
     15function GUI_input=ima_levels(Param)
    1616%requests for the visibility of input windows in the GUI series  (activated directly by the selection in the menu ACTION)
    17 if ~exist('num_i1','var')
     17if ~exist('Param','var')
    1818    GUI_input={};
    1919    return %exit the function
    2020end
    2121
    22 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%enable waitbar
    23 hseries=guidata(Series.hseries);%handles of the GUI series
    24 WaitbarPos=get(hseries.waitbar_frame,'Position');
    25 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    26 
    27 basename=fullfile(Series.RootPath,Series.RootFile) ;
    28 
    29 %create dir of the new images
    30 [dir_images,namebase]=fileparts(basename);
    31 [path,subdir_ima]=fileparts(dir_images);
    32 dircur=pwd;
    33 cd(path);
    34 mkdir([subdir_ima '_levels']);
    35   [xx,msg2] = fileattrib([subdir_ima '_levels'],'+w','g') %yield writing access (+w) to user group (g)
    36 if ~strcmp(msg2,'')
    37     msgbox_uvmat('ERROR',['pb of permission for ' subdir_ima ': ' msg2])%error message for directory creation
    38     cd(dircur)
     22%% input parameters
     23% read the xml file for batch case
     24if ischar(Param) && ~isempty(find(regexp('Param','.xml$')))
     25    Param=xml2struct(Param);
     26    checkrun=0;
     27else %  RUN case: parameters introduced as the input structure Param
     28    hseries=guidata(Param.hseries);%handles of the GUI series
     29    WaitbarPos=get(hseries.waitbar_frame,'Position');
     30    checkrun=1;
     31end
     32%filebase=fullfile(Param.InputTable{1,1},Param.InputTable{1,3});
     33RootPath=Param.InputTable{1,1};
     34Subdir=Param.InputTable{1,2};
     35RootFile=Param.InputTable{1,3};
     36NomType=Param.InputTable{1,4};
     37FileExt=Param.InputTable{1,5};
     38[filecell,i1_series,i2_series,j1_series]=get_file_series(Param);% list of input files and indices
     39if size(filecell,1)>1
     40    msgbox_uvmat('WARNING','This function uses only the first input image series')
    3941    return
    4042end
    41 cd(dircur);
    42 basename_new=fullfile(path,[subdir_ima '_levels'],namebase);
    4343
    44 % read imadoc
    45 %[XmlData,warntext]=imadoc2struct([basename '.xml']);
    46 % nbfield1=size(XmlData.Time,1);
    47 % nbfield2=size(XmlData.Time,2);
     44%% determine input image type
     45[FileType,FileInfo,MovieObject]=get_file_type(filecell{1,1});
     46ListTypes={'image','multimage','mmreader','video'};
    4847
     48if 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
     51end
     52
     53%% create dir of the new images
     54SubdirResult=[Param.InputTable{1,2} '.lev'];% add the suffix '.lev' to the name of the image folder
     55try
     56    mkdir(fullfile(Param.InputTable{1,1},SubdirResult));
     57catch ME
     58    msgbox_uvmat('ERROR',['error in creating result directory: ' ME.message]);%display error msg for directory creation if fails
     59    return
     60end
     61[xx,msg2] = fileattrib(fullfile(Param.InputTable{1,1},SubdirResult),'+w','g'); %yield writing access (+w) to user group (g)
     62if ~strcmp(msg2,'')
     63    msgbox_uvmat('ERROR',['pb of permission for ' fullfile(Param.InputTable{1,1},SubdirResult) ': ' msg2])%error message for directory creation
     64    return
     65end
    4966msgbox_uvmat('CONFIRMATION','apply image rescaling function levels.m ');
    5067
    5168%copy the xml file
    52 if exist([basename '.xml'],'file')
    53     copyfile([basename '.xml'],[basename_new '.xml']);% copy the .civ file
    54 end
     69% if exist([basename '.xml'],'file')
     70%     copyfile([basename '.xml'],[basename_new '.xml']);% copy the .civ file
     71% end
    5572
    56 %main loop
    57 nbfield=size(num_i1,2);
    58 nbfield2=size(num_i1,1);
     73%% main loop
     74nbfield=size(i1_series{1},2);
     75nbfield2=size(i1_series{1},1);
    5976for ifile=1:nbfield
    60     update_waitbar(hseries.waitbar,WaitbarPos,ifile/nbfield)
    61     stopstate=get(hseries.RUN,'BusyAction');
     77    if checkrun
     78%         update_waitbar(hseries.waitbar,WaitbarPos,ifile/nbfield)
     79        update_waitbar(hseries.waitbar_frame,WaitbarPos,ifile/nbfield)
     80        stopstate=get(hseries.RUN,'BusyAction');
     81    else
     82        stopstate='queue';
     83    end
    6284    if isequal(stopstate,'queue') % enable STOP command
    6385        for jfile=1:nbfield2
    64             filename=name_generator(basename,num_i1(jfile,ifile),num_j1(jfile,ifile),Series.FileExt,Series.NomType);
    65             filename_new=name_generator(basename_new,num_i1(jfile,ifile),num_j1(jfile,ifile),'.png',Series.NomType);
    66             A=imread(filename);
     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                case {'vol','image'}
     93                    A=imread(filename);
     94                case 'multimage'
     95                    A=imread(filename,i1_series{1}(jfile,ifile));
     96            end
    6797            C=levels(A);
     98            filename_new=fullfile_uvmat(RootPath,SubdirResult,RootFile,'.png',NomType,i1_series{1}(jfile,ifile),[],j1_series{1}(jfile,ifile));
    6899            imwrite(C,filename_new)
     100            display([filename_new ' written'])
    69101        end
    70102    end
    71103end
    72 
    73 
     104%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    74105
    75106function C=levels(A)
Note: See TracChangeset for help on using the changeset viewer.