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/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%------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.