Changeset 442


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

functions updated in series for the new file configuration

Location:
trunk/src/series
Files:
4 edited

Legend:

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

    r420 r442  
    4545if ischar(Param) && ~isempty(find(regexp('Param','.xml$')))
    4646    Param=xml2struct(Param);
     47    checkrun=0;
    4748else %  RUN case: parameters introduced as the input structure Param
    4849    hseries=guidata(Param.hseries);%handles of the GUI series
    4950    WaitbarPos=get(hseries.waitbar_frame,'Position');
     51    checkrun=1;
    5052end
    5153[filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
     
    250252    ext_out='.nc';
    251253end
    252 subdir_result='aver_stat';%subdirectory for the results
    253 pathdir=fullfile(RootPath{1},subdir_result);% full subdirectory name, including path
    254 testexist=1;
    255 while testexist
    256     pathdir=fullfile(RootPath{1},subdir_result);% full subdirectory name, including path
    257     if NbSlice==1% keep track of the first and lsat indices of the input files
    258         %NomTypeOut=nomtype2pair(Param.InputTable{1,4},i2_series{end}(end)-i1_series{1}(1),j2_series{end}(end)-j1_series{1}(1));
    259         NomTypeOut='_1-2';
    260         fileresult{1}=fullfile_uvmat(RootPath{1},subdir_result,RootFile{1},ext_out,NomTypeOut,i1_series{1}(1),i1_series{1}(end),[],[]);
    261         testexist=exist(fileresult{1},'file');
    262     else % simplified indexing with i_slice for multiple slices
    263         testexist=0;
    264         for i_slice=1:NbSlice
    265             fileresult{1}=fullfile_uvmat(RootPath{1},subdir_result,RootFile{1},ext_out,NomTypeOut,i_slice,[],[],[]);
    266             if exist(fileresult{i_slice},'file')
    267                 testexist=1;
    268                 break
    269             end
    270         end
    271     end
    272     if testexist
    273         subdir_result=[subdir_result '.0'];
    274     end
    275 end
     254subdir_result=[SubDir{1} '.stat'];%subdirectory for the results
     255pathdir=RootPath{1};% full subdirectory name, including path
     256checkdetect=1;
     257while checkdetect %create a new subdir if the netcdf files already exist
     258    checkdetect=exist(fullfile(pathdir,subdir_result));
     259    if checkdetect% if a nesult dir already exists
     260        r=regexp(subdir_result,'(?<root>.*\D)(?<num1>\d+)$','names');%detect whether name ends by a number
     261        if isempty(r)
     262            r(1).root=[subdir_result '_'];
     263            r(1).num1='0';
     264        end
     265        subdir_result=[r(1).root num2str(str2num(r(1).num1)+1)];%increment the index by 1 or put 1
     266    end
     267end
     268NomTypeOut='_1-2';
     269fileresult{1}=fullfile_uvmat(RootPath{1},subdir_result,RootFile{1},ext_out,NomTypeOut,i1_series{1}(1),i1_series{1}(end),[],[]);
     270
     271% A REPRNDRE CAS MULTI-NIVEAU:
     272%     pathdir=fullfile(RootPath{1},subdir_result);% full subdirectory name, including path
     273%     if NbSlice==1% keep track of the first and lsat indices of the input files
     274%         %NomTypeOut=nomtype2pair(Param.InputTable{1,4},i2_series{end}(end)-i1_series{1}(1),j2_series{end}(end)-j1_series{1}(1));
     275%         NomTypeOut='_1-2';
     276%         fileresult{1}=fullfile_uvmat(RootPath{1},subdir_result,RootFile{1},ext_out,NomTypeOut,i1_series{1}(1),i1_series{1}(end),[],[]);
     277%         testexist=exist(fileresult{1},'file');
     278%     else % simplified indexing with i_slice for multiple slices
     279%         testexist=0;
     280%         for i_slice=1:NbSlice
     281%             fileresult{1}=fullfile_uvmat(RootPath{1},subdir_result,RootFile{1},ext_out,NomTypeOut,i_slice,[],[],[]);
     282%             if exist(fileresult{i_slice},'file')
     283%                 testexist=1;
     284%                 break
     285%             end
     286%         end
     287%     end
     288%     if testexist
     289%         subdir_result=[subdir_result '.0'];
     290%     end
     291% end
    276292% create result directory if needed
    277 if ~exist(pathdir,'dir')
    278     [m1,m2,m3]=mkdir(pathdir);
     293if ~exist(fullfile(RootPath{1},subdir_result),'dir')
     294    [m1,m2,m3]=mkdir(fullfile(RootPath{1},subdir_result));
    279295    if ~isequal(m2,'')
    280296        msgbox_uvmat('CONFIRMATION',m2);%error message for directory creation
    281297    end
    282298end
    283 [xx,msg2] = fileattrib(pathdir,'+w','g'); %yield writing access (+w) to user group (g)
     299[xx,msg2] = fileattrib(fullfile(RootPath{1},subdir_result),'+w','g'); %yield writing access (+w) to user group (g)
    284300if ~strcmp(msg2,'')
    285     msgbox_uvmat('ERROR',['pb of permission for ' pathdir ': ' msg2])%error message for writting access
     301    msgbox_uvmat('ERROR',['pb of permission for ' fullfile(RootPath{1},subdir_result) ': ' msg2])%error message for writting access
    286302    return
    287303end
     
    312328 %       if isequal(stopstate,'queue') % enable STOP command
    313329         %   update_waitbar(hseries.waitbar,WaitbarPos,index/(nbfield*nbfield2))
     330         if checkrun
     331             update_waitbar(hseries.waitbar_frame,WaitbarPos,index/(nbfield*nbfield2))
     332             stopstate=get(hseries.RUN,'BusyAction');
     333         else
     334             stopstate='queue';
     335         end
    314336            ifile=indselect(index);
    315337            % reading input file(s)
  • 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)
  • trunk/src/series/sub_background.m

    r394 r442  
    6161if ischar(Param) && ~isempty(find(regexp('Param','.xml$')))
    6262    Param=xml2struct(Param);
     63    checkrun=0;
    6364else %  RUN case: parameters introduced as the input structure Param
    6465    hseries=guidata(Param.hseries);%handles of the GUI series
    6566    WaitbarPos=get(hseries.waitbar_frame,'Position');
    66 end
    67 filebase=fullfile(Param.InputTable{1,1},Param.InputTable{1,3});
     67    checkrun=1;
     68end
     69filebase=fullfile(Param.InputTable{1,1},Param.InputTable{1,2},Param.InputTable{1,3});
    6870dir_images=Param.InputTable{1,1};
    6971NomType=Param.InputTable{1,4};
    7072FileExt=Param.InputTable{1,5};
    71 [filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
     73[filecell,i1_series,tild,j1_series]=get_file_series(Param);%generates the set
     74of input file names
    7275if size(filecell,1)>1
    7376    msgbox_uvmat('WARNING','This function uses only the first input image series')
     
    7578end
    7679
    77 %%% TODO: update with the new conventions%%%%%%%%%%%%%%%%%
    7880%% determine input image type
    7981FileType=[];%default
     
    8486    hhh=which('mmreader');
    8587    if ~isequal(hhh,'')&& mmreader.isPlatformSupported()
    86         MovieObject=mmreader(fullfile(RootPath,[RootFile FileExt]));
     88        MovieObject=mmreader(fullfile(RootPath,SubDir,[RootFile FileExt]));
    8789        FileType='movie';
    8890    else
     
    125127
    126128%% create dir of the new images
    127 % [dir_images,namebase]=fileparts(filebase);
    128129if test_level
    129     term='_b_levels';
     130    term='.sbk.lev';
    130131else
    131     term='_b';
    132 end
    133 [pp,subdir_ima]=fileparts(Param.InputTable{1,1});
     132    term='.sbk';
     133end
     134SubdirResult=[Param.InputTable{1,2} term];
    134135try
    135     mkdir([dir_images term]);
     136    mkdir(fullfile(Param.InputTable{1,1},SubdirResult));
    136137catch ME
    137     msgbox_uvmat('ERROR',ME.message);
    138     return
    139 end
    140 [xx,msg2] = fileattrib([dir_images term],'+w','g'); %yield writing access (+w) to user group (g)
     138    msgbox_uvmat('ERROR',['error in creating result directory: ' ME.message]);
     139    return
     140end
     141[xx,msg2] = fileattrib(fullfile(Param.InputTable{1,1},SubdirResult),'+w','g'); %yield writing access (+w) to user group (g)
    141142if ~strcmp(msg2,'')
    142     msgbox_uvmat('ERROR',['pb of permission for ' subdir_ima term ': ' msg2])%error message for directory creation
    143     return
    144 end
    145 filebase_b=fullfile([dir_images term],Param.InputTable{1,3});
     143    msgbox_uvmat('ERROR',['pb of permission for ' fullfile(Param.InputTable{1,1},SubdirResult) ': ' msg2])%error message for directory creation
     144    return
     145end
    146146
    147147%% set processing parameters
    148148prompt = {'Number of images for the sliding background (MUST FIT IN COMPUETER MEMORY)';'The number of positions (laser slices)';'volume scan mode (Yes/No)';...
    149149    'the luminosity rank chosen to define the background (0.1=for dense particle seeding, 0.5 (median) for sparse particles'};
    150 dlg_title = ['get (slice by slice) a sliding background and substract to each image, result in subdir ' subdir_ima term];
     150dlg_title = ['get (slice by slice) a sliding background and substract to each image, result in subdir ' SubdirResult];
    151151num_lines= 3;
    152152def     = { num2str(nbaver_init);num2str(nbslice_i);'No';'0.1'};
     
    209209end
    210210
    211 %% copy the xml file
    212 if exist([filebase '.xml'],'file')
    213     copyfile([filebase '.xml'],[filebase_b '.xml']);% copy the .civ file
    214     t=xmltree([filebase_b '.xml']);
    215    
     211%% update the xml file
     212SubDirBase=regexprep(Param.InputTable{1,2},'\..*','');%take the root part of SubDir, before the first dot '.'
     213filexml=fulfille(Param.InputTable{1,1},[SubDirBase '.xml']);
     214if ~exist(filexml,'file') && exist([filebase '.xml'],'file')% xml inside the image directory
     215    copyfile([filebase '.xml'],filexml);% copy the .xml file
     216end
     217if exist(filexml,'file')
     218    t=xmltree([filexml '.xml']); 
    216219    %update information on the first image name in the series
    217220    uid_Heading=find(t,'ImaDoc/Heading');
     
    251254    [t,LuminosityRank_uid]=add(t,new_uid,'element','RankBackground');
    252255    [t]=add(t,LuminosityRank_uid,'chardata',num2str(rank));% luminosity rank almong the nbaver sliding images
    253     save(t,[filebase_b '.xml'])
    254 elseif exist([filebase '.civ'],'file')
    255     copyfile([filebase '.civ'],[filebase_b '.civ']);% copy the .civ file
     256    save(t,filexml)
    256257end
    257258%copy the mask
    258 if exist([filebase '_1mask_1'],'file')
    259     copyfile([filebase '_1mask_1'],[filebase_b '_1mask_1']);% copy the mask file
    260 end
     259% if exist([filebase '_1mask_1'],'file')
     260%     copyfile([filebase '_1mask_1'],[filebase_b '_1mask_1']);% copy the mask file
     261% end
    261262
    262263%MAIN LOOP ON SLICES
    263 
    264264for islice=1:nbslice_i
    265265    %% select the series of image indices at the level islice
     
    290290            j1=j1_series{1}(ifile);
    291291        end
    292         newname=fullfile_uvmat([dir_images term],'',Param.InputTable{1,3},'.png',NomType,i1_series{1}(ifile),[],j1);
     292        newname=fullfile_uvmat(Param.InputTable{1,1},SubdirResult,Param.InputTable{1,3},'.png',NomType,i1_series{1}(ifile),[],j1);
    293293        %newname=name_generator(filebase_b,i1_series{1}(ifile),j1_series{1}(ifile),'.png',NomType);% makes the new file name
    294294        if test_level
     
    304304    if nbfield_slice > nbaver_ima
    305305        for ifield = step*ceil(nbaver/2)+1:step:nbfield_slice-step*floor(nbaver/2)
    306             stopstate=get(hseries.RUN,'BusyAction');
    307             if isequal(stopstate,'queue')% enable STOP command
     306            if checkrun
     307                stopstate=get(hseries.RUN,'BusyAction');
    308308                update_waitbar(hseries.waitbar,WaitbarPos,(ifield+(islice-1)*nbfield_slice)/(nbfield_slice*nbslice_i))
    309309                display((ifield+(islice-1)*nbfield_slice)/(nbfield_slice*nbslice_i))
     310            else
     311                stopstate='queue';
     312            end
     313            if isequal(stopstate,'queue')% enable STOP command
    310314                Ak(:,:,1:nbaver_ima-step)=Ak(:,:,1+step:nbaver_ima);% shift the current image series by one burst (step)
    311315                %incorporate next burst in the current image series
    312316                for iburst=1:step
    313317                    ifile=indselect(ifield+step*floor(nbaver/2)+iburst-1);
    314                     filename=name_generator(filebase,num_i1(ifile),num_j1(ifile),FileExt,NomType);
     318                    filename=fullfile_uvmat(Param.InputTable{1,1},Subdir,Param.InputTable{1,3},FileExt,NomType,num_i1(ifile),[],num_j1(ifile));
     319                    %filename=name_generator(filebase,num_i1(ifile),num_j1(ifile),FileExt,NomType);
    315320                    Aread=read_image(filename,FileType,num_i1(ifile),MovieObject);
    316321                    Ak(:,:,nbaver_ima-step+iburst)=Aread;
     
    327332                        j1=j1_series{1}(ifile);
    328333                    end
    329                     newname=fullfile_uvmat([dir_images term],'',Param.InputTable{1,3},'.png',NomType,i1_series{1}(ifile),[],j1);
     334                    newname=fullfile_uvmat(Param.InputTable{1,1},SubdirResult,Param.InputTable{1,3},'.png',NomType,i1_series{1}(ifile),[],j1);
    330335                    %[newname]=name_generator(filebase_b,num_i1(ifile),num_j1(ifile),'.png',NomType) % makes the new file name
    331336                    if test_level
     
    354359            j1=j1_series{1}(ifile);
    355360        end
    356         newname=fullfile_uvmat([dir_images term],'',Param.InputTable{1,3},'.png',NomType,i1_series{1}(ifile),[],j1);
    357         %newname=name_generator(filebase_b,num_i1(ifile),num_j1(ifile),'.png',NomType);% makes the new file name
     361        newname=fullfile_uvmat(Param.InputTable{1,1},SubdirResult,Param.InputTable{1,3},'.png',NomType,i1_series{1}(ifile),[],j1);
    358362        if test_level
    359363            C=levels(C);
     
    366370
    367371%finish the waitbar
    368 update_waitbar(hseries.waitbar,WaitbarPos,1)
    369 
     372if checkrun
     373    update_waitbar(hseries.waitbar,WaitbarPos,1)
     374end
    370375
    371376%------------------------------------------------------------------------
  • trunk/src/series/time_series.m

    r422 r442  
    3737if ischar(Param) && ~isempty(find(regexp('Param','.xml$')))
    3838    Param=xml2struct(Param);
     39    checkrun=0;
    3940else %  RUN case: parameters introduced as the input structure Param
    4041    hseries=guidata(Param.hseries);%handles of the GUI series
    4142    WaitbarPos=get(hseries.waitbar_frame,'Position');
     43    checkrun=1;
    4244end
    4345[filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
     
    273275    filecounter=0;
    274276    for ifile=i_slice:NbSlice:nbfield
    275         stopstate=get(hseries.RUN,'BusyAction');
     277        if checkrun
     278            update_waitbar(hseries.waitbar_frame,WaitbarPos,ifile/nbfield)
     279            stopstate=get(hseries.RUN,'BusyAction');
     280        else
     281            stopstate='queue';
     282        end
    276283        errormsg='';
    277284        if isequal(stopstate,'queue')% enable STOP command
    278             update_waitbar(hseries.waitbar,WaitbarPos,ifile/nbfield) % update the waitbar
    279285            % loop on views (in case of multiple input series)
    280286            for iview=1:nbview
Note: See TracChangeset for help on using the changeset viewer.