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 | %----------------------------------------------------------------------
|
---|
15 | function 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)
|
---|
17 | if ~exist('num_i1','var')
|
---|
18 | GUI_input={};
|
---|
19 | return %exit the function
|
---|
20 | end
|
---|
21 |
|
---|
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)
|
---|
39 | return
|
---|
40 | end
|
---|
41 | cd(dircur);
|
---|
42 | basename_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 |
|
---|
49 | msgbox_uvmat('CONFIRMATION','apply image rescaling function levels.m ');
|
---|
50 |
|
---|
51 | %copy the xml file
|
---|
52 | if exist([basename '.xml'],'file')
|
---|
53 | copyfile([basename '.xml'],[basename_new '.xml']);% copy the .civ file
|
---|
54 | end
|
---|
55 |
|
---|
56 | %main loop
|
---|
57 | batch_file_list={};
|
---|
58 | nbfield=size(num_i1,2);
|
---|
59 | nbfield2=size(num_i1,1);
|
---|
60 | for 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
|
---|
85 | end
|
---|
86 |
|
---|
87 |
|
---|
88 | ncores=1;
|
---|
89 | walltime_onejob=10;%seconds
|
---|
90 | filename_joblist=fullfile(path,[subdir_ima '_levels'],'job_list.txt')
|
---|
91 | fid=fopen(filename_joblist,'w+')
|
---|
92 | for p=1:length(batch_file_list)
|
---|
93 | fprintf(fid,[batch_file_list{p} '\n']);
|
---|
94 | end
|
---|
95 | fclose(fid);
|
---|
96 | oar_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"'];
|
---|
102 | filename_oarcommand=fullfile(path,[subdir_ima '_levels'],'oar_command');
|
---|
103 | fid=fopen(filename_oarcommand,'w');
|
---|
104 | fprintf(fid,[oar_command '\n']);
|
---|
105 | fclose(fid);
|
---|
106 | display(oar_command);
|
---|
107 | eval(['! . ' filename_oarcommand])
|
---|
108 |
|
---|
109 |
|
---|