source: trunk/src/series/ima_levels_batch.m @ 348

Last change on this file since 348 was 348, checked in by gostiaux, 9 years ago

Now launches jobs using oar-parexec

File size: 4.6 KB
Line 
1%'ima_levels': rescale the image intensity to reduce strong luminosity peaks
2%------------------------------------------------------------------------
3% function GUI_input=ima_levels(num_i1,num_i2,num_j1,num_j2,Series)
4%
5%OUTPUT
6% GUI_input=list of options in the GUI series.fig needed for the function
7%
8%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%----------------------------------------------------------------------
15function GUI_input=ima_levels_batch(num_i1,num_i2,num_j1,num_j2,Series)
16%requests for the visibility of input windows in the GUI series  (activated directly by the selection in the menu ACTION)
17if ~exist('num_i1','var')
18    GUI_input={};
19    return %exit the function
20end
21
22%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%enable waitbar
23hseries=guidata(Series.hseries);%handles of the GUI series
24WaitbarPos=get(hseries.waitbar_frame,'Position');
25%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
26
27basename=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);
32dircur=pwd;
33cd(path);
34mkdir([subdir_ima '_levels']);
35  [xx,msg2] = fileattrib([subdir_ima '_levels'],'+w','g'); %yield writing access (+w) to user group (g)
36if ~strcmp(msg2,'')
37    msgbox_uvmat('ERROR',['pb of permission for ' subdir_ima ': ' msg2])%error message for directory creation
38    cd(dircur)
39    return
40end
41cd(dircur);
42basename_new=fullfile(path,[subdir_ima '_levels'],namebase);
43
44% read imadoc
45%[XmlData,warntext]=imadoc2struct([basename '.xml']);
46% nbfield1=size(XmlData.Time,1);
47% nbfield2=size(XmlData.Time,2);
48
49msgbox_uvmat('CONFIRMATION','apply image rescaling function levels.m ');
50
51%copy the xml file
52if exist([basename '.xml'],'file')
53    copyfile([basename '.xml'],[basename_new '.xml']);% copy the .civ file
54end
55
56%main loop
57batch_file_list={};
58nbfield=size(num_i1,2);
59nbfield2=size(num_i1,1);
60for ifile=1:nbfield
61    update_waitbar(hseries.waitbar,WaitbarPos,ifile/nbfield)
62    stopstate=get(hseries.RUN,'BusyAction');
63    if isequal(stopstate,'queue') % enable STOP command
64        for jfile=1:nbfield2
65            OutputFile=name_generator(basename_new,num_i1(jfile,ifile),num_j1(jfile,ifile),'',Series.NomType);
66            filename=name_generator(basename,num_i1(jfile,ifile),num_j1(jfile,ifile),Series.FileExt,Series.NomType);
67            filename_new=name_generator(basename_new,num_i1(jfile,ifile),num_j1(jfile,ifile),'.png',Series.NomType);
68            path_series=[fileparts(which('civ')) '/series'];
69           
70            filename_bat=[OutputFile '.bat'];
71            [fid,message]=fopen(filename_bat,'w');
72            if isequal(fid,-1)
73                msgbox_uvmat('ERROR', ['creation of .bat file: ' message])
74                return
75            end
76            fprintf(fid,['/opt/matlab/R2011a/bin/matlab -nodisplay -nosplash -r "cd(''' path_series ''');'...
77                'A=imread(' filename ');C=levels(A);imwrite(C,' filename_new ');exit"']);
78            fclose(fid);
79            if isunix
80                system(['chmod +x ' filename_bat]);
81            end
82            batch_file_list{length(batch_file_list)+1}=filename_bat;
83        end
84    end
85end
86
87
88ncores=1;
89walltime_onejob=10;%seconds
90filename_joblist=fullfile(path,[subdir_ima '_levels'],'job_list.txt')
91fid=fopen(filename_joblist,'w+')
92for p=1:length(batch_file_list)
93    fprintf(fid,[batch_file_list{p} '\n']);
94end
95fclose(fid);
96oar_command=['oarsub -n ima_levels '...
97    '-l /core=' num2str(ncores) ','...
98    'walltime=' datestr(1.05*walltime_onejob/86400*max(length(batch_file_list),ncores)/ncores,13) ' '...
99    '-E ' regexprep(filename_joblist,'\.txt\>','.errors') ' '...
100    '-O ' regexprep(filename_joblist,'\.txt\>','.log') ' '...
101    '"oar-parexec -f ' filename_joblist ' -l ' filename_joblist '.log"'];
102filename_oarcommand=fullfile(path,[subdir_ima '_levels'],'oar_command');
103fid=fopen(filename_oarcommand,'w');
104fprintf(fid,[oar_command '\n']);
105fclose(fid);
106display(oar_command);
107eval(['! . ' filename_oarcommand])
108
109
Note: See TracBrowser for help on using the repository browser.