Changeset 442 for trunk/src/series/ima_levels.m
- Timestamp:
- Jun 6, 2012, 2:46:15 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/series/ima_levels.m
r349 r442 13 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 14 %---------------------------------------------------------------------- 15 function GUI_input=ima_levels( num_i1,num_i2,num_j1,num_j2,Series)15 function GUI_input=ima_levels(Param) 16 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')17 if ~exist('Param','var') 18 18 GUI_input={}; 19 19 return %exit the function 20 20 end 21 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) 22 %% input parameters 23 % read the xml file for batch case 24 if ischar(Param) && ~isempty(find(regexp('Param','.xml$'))) 25 Param=xml2struct(Param); 26 checkrun=0; 27 else % 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; 31 end 32 %filebase=fullfile(Param.InputTable{1,1},Param.InputTable{1,3}); 33 RootPath=Param.InputTable{1,1}; 34 Subdir=Param.InputTable{1,2}; 35 RootFile=Param.InputTable{1,3}; 36 NomType=Param.InputTable{1,4}; 37 FileExt=Param.InputTable{1,5}; 38 [filecell,i1_series,i2_series,j1_series]=get_file_series(Param);% list of input files and indices 39 if size(filecell,1)>1 40 msgbox_uvmat('WARNING','This function uses only the first input image series') 39 41 return 40 42 end 41 cd(dircur);42 basename_new=fullfile(path,[subdir_ima '_levels'],namebase);43 43 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}); 46 ListTypes={'image','multimage','mmreader','video'}; 48 47 48 if 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 51 end 52 53 %% create dir of the new images 54 SubdirResult=[Param.InputTable{1,2} '.lev'];% add the suffix '.lev' to the name of the image folder 55 try 56 mkdir(fullfile(Param.InputTable{1,1},SubdirResult)); 57 catch ME 58 msgbox_uvmat('ERROR',['error in creating result directory: ' ME.message]);%display error msg for directory creation if fails 59 return 60 end 61 [xx,msg2] = fileattrib(fullfile(Param.InputTable{1,1},SubdirResult),'+w','g'); %yield writing access (+w) to user group (g) 62 if ~strcmp(msg2,'') 63 msgbox_uvmat('ERROR',['pb of permission for ' fullfile(Param.InputTable{1,1},SubdirResult) ': ' msg2])%error message for directory creation 64 return 65 end 49 66 msgbox_uvmat('CONFIRMATION','apply image rescaling function levels.m '); 50 67 51 68 %copy the xml file 52 if exist([basename '.xml'],'file')53 copyfile([basename '.xml'],[basename_new '.xml']);% copy the .civ file54 end69 % if exist([basename '.xml'],'file') 70 % copyfile([basename '.xml'],[basename_new '.xml']);% copy the .civ file 71 % end 55 72 56 % main loop57 nbfield=size( num_i1,2);58 nbfield2=size( num_i1,1);73 %% main loop 74 nbfield=size(i1_series{1},2); 75 nbfield2=size(i1_series{1},1); 59 76 for 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 62 84 if isequal(stopstate,'queue') % enable STOP command 63 85 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 67 97 C=levels(A); 98 filename_new=fullfile_uvmat(RootPath,SubdirResult,RootFile,'.png',NomType,i1_series{1}(jfile,ifile),[],j1_series{1}(jfile,ifile)); 68 99 imwrite(C,filename_new) 100 display([filename_new ' written']) 69 101 end 70 102 end 71 103 end 72 73 104 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 74 105 75 106 function C=levels(A)
Note: See TracChangeset
for help on using the changeset viewer.