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 |
|
---|
16 | %=======================================================================
|
---|
17 | % Copyright 2008-2018, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
|
---|
18 | % http://www.legi.grenoble-inp.fr
|
---|
19 | % Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
|
---|
20 | %
|
---|
21 | % This file is part of the toolbox UVMAT.
|
---|
22 | %
|
---|
23 | % UVMAT is free software; you can redistribute it and/or modify
|
---|
24 | % it under the terms of the GNU General Public License as published
|
---|
25 | % by the Free Software Foundation; either version 2 of the license,
|
---|
26 | % or (at your option) any later version.
|
---|
27 | %
|
---|
28 | % UVMAT is distributed in the hope that it will be useful,
|
---|
29 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
30 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
31 | % GNU General Public License (see LICENSE.txt) for more details.
|
---|
32 | %=======================================================================
|
---|
33 |
|
---|
34 | function GUI_input=ima_levels_batch(num_i1,num_i2,num_j1,num_j2,Series)
|
---|
35 | %requests for the visibility of input windows in the GUI series (activated directly by the selection in the menu ACTION)
|
---|
36 | if ~exist('num_i1','var')
|
---|
37 | GUI_input={};
|
---|
38 | return %exit the function
|
---|
39 | end
|
---|
40 |
|
---|
41 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%enable waitbar
|
---|
42 | hseries=guidata(Series.hseries);%handles of the GUI series
|
---|
43 | WaitbarPos=get(hseries.waitbar_frame,'Position');
|
---|
44 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
45 |
|
---|
46 | basename=fullfile(Series.RootPath,Series.RootFile) ;
|
---|
47 |
|
---|
48 | %create dir of the new images
|
---|
49 | [dir_images,namebase]=fileparts(basename);
|
---|
50 | [path,subdir_ima]=fileparts(dir_images);
|
---|
51 | dircur=pwd;
|
---|
52 | cd(path);
|
---|
53 | mkdir([subdir_ima '_levels']);
|
---|
54 | [xx,msg2] = fileattrib([subdir_ima '_levels'],'+w','g'); %yield writing access (+w) to user group (g)
|
---|
55 | if ~strcmp(msg2,'')
|
---|
56 | msgbox_uvmat('ERROR',['pb of permission for ' subdir_ima ': ' msg2])%error message for directory creation
|
---|
57 | cd(dircur)
|
---|
58 | return
|
---|
59 | end
|
---|
60 | cd(dircur);
|
---|
61 | basename_new=fullfile(path,[subdir_ima '_levels'],namebase);
|
---|
62 |
|
---|
63 | % read imadoc
|
---|
64 | %[XmlData,warntext]=imadoc2struct([basename '.xml']);
|
---|
65 | % nbfield1=size(XmlData.Time,1);
|
---|
66 | % nbfield2=size(XmlData.Time,2);
|
---|
67 |
|
---|
68 | msgbox_uvmat('CONFIRMATION','apply image rescaling function levels.m ');
|
---|
69 |
|
---|
70 | %copy the xml file
|
---|
71 | if exist([basename '.xml'],'file')
|
---|
72 | copyfile([basename '.xml'],[basename_new '.xml']);% copy the .civ file
|
---|
73 | end
|
---|
74 |
|
---|
75 | %main loop
|
---|
76 | batch_file_list={};
|
---|
77 | nbfield=size(num_i1,2);
|
---|
78 | nbfield2=size(num_i1,1);
|
---|
79 | for ifile=1:nbfield
|
---|
80 | update_waitbar(hseries.waitbar,WaitbarPos,ifile/nbfield)
|
---|
81 | stopstate=get(hseries.RUN,'BusyAction');
|
---|
82 | if isequal(stopstate,'queue') % enable STOP command
|
---|
83 | for jfile=1:nbfield2
|
---|
84 | OutputFile=name_generator(basename_new,num_i1(jfile,ifile),num_j1(jfile,ifile),'',Series.NomType);
|
---|
85 | filename=name_generator(basename,num_i1(jfile,ifile),num_j1(jfile,ifile),Series.FileExt,Series.NomType);
|
---|
86 | filename_new=name_generator(basename_new,num_i1(jfile,ifile),num_j1(jfile,ifile),'.png',Series.NomType);
|
---|
87 | path_series=[fileparts(which('civ')) '/series'];
|
---|
88 |
|
---|
89 | filename_bat=[OutputFile '.bat'];
|
---|
90 | [fid,message]=fopen(filename_bat,'w');
|
---|
91 | if isequal(fid,-1)
|
---|
92 | msgbox_uvmat('ERROR', ['creation of .bat file: ' message])
|
---|
93 | return
|
---|
94 | end
|
---|
95 | fprintf(fid,['/opt/matlab/R2011a/bin/matlab -nodisplay -nosplash -r "cd(''' path_series ''');'...
|
---|
96 | 'A=imread(' filename ');C=levels(A);imwrite(C,' filename_new ');exit"']);
|
---|
97 | fclose(fid);
|
---|
98 | if isunix
|
---|
99 | system(['chmod +x ' filename_bat]);
|
---|
100 | end
|
---|
101 | batch_file_list{length(batch_file_list)+1}=filename_bat;
|
---|
102 | end
|
---|
103 | end
|
---|
104 | end
|
---|
105 |
|
---|
106 |
|
---|
107 | ncores=1;
|
---|
108 | walltime_onejob=10;%seconds
|
---|
109 | filename_joblist=fullfile(path,[subdir_ima '_levels'],'job_list.txt')
|
---|
110 | fid=fopen(filename_joblist,'w+')
|
---|
111 | for p=1:length(batch_file_list)
|
---|
112 | fprintf(fid,[batch_file_list{p} '\n']);
|
---|
113 | end
|
---|
114 | fclose(fid);
|
---|
115 | oar_command=['oarsub -n ima_levels '...
|
---|
116 | '-l /core=' num2str(ncores) ','...
|
---|
117 | 'walltime=' datestr(1.05*walltime_onejob/86400*max(length(batch_file_list),ncores)/ncores,13) ' '...
|
---|
118 | '-E ' regexprep(filename_joblist,'\.txt\>','.errors') ' '...
|
---|
119 | '-O ' regexprep(filename_joblist,'\.txt\>','.log') ' '...
|
---|
120 | '"oar-parexec -f ' filename_joblist ' -l ' filename_joblist '.log"'];
|
---|
121 | filename_oarcommand=fullfile(path,[subdir_ima '_levels'],'oar_command');
|
---|
122 | fid=fopen(filename_oarcommand,'w');
|
---|
123 | fprintf(fid,[oar_command '\n']);
|
---|
124 | fclose(fid);
|
---|
125 | display(oar_command);
|
---|
126 | eval(['! . ' filename_oarcommand])
|
---|
127 |
|
---|
128 |
|
---|