Changeset 641
- Timestamp:
- May 21, 2013, 9:12:42 PM (11 years ago)
- Location:
- trunk/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/uigetfile_uvmat.m
r635 r641 10 10 % InputDir: directory to browse at first display 11 11 12 function fileinput=uigetfile_uvmat(title,InputName) 12 function fileinput=uigetfile_uvmat(title,InputName,FilterExt) 13 if ~exist('FilterExt','var') 14 FilterExt='*'; 15 end 13 16 fileinput=''; %default file selection 14 17 if strcmp(title,'status_display') … … 59 62 uicontrol('Style','popupmenu','Units','normalized', 'Position', [0.75 0.8 0.2 0.04],'tag','sort_option','Callback',@refresh_GUI,'Visible','off',... 60 63 'String',{'name';'date'},'FontUnits','points','FontSize',12,'FontWeight','bold'); 61 uicontrol('Style','listbox','Units','normalized', 'Position',[0.05 0.08 0.9 0.66], 'Callback', @(src,event)list_Callback(option, src,event),'tag','list',...64 uicontrol('Style','listbox','Units','normalized', 'Position',[0.05 0.08 0.9 0.66], 'Callback', @(src,event)list_Callback(option,FilterExt,src,event),'tag','list',... 62 65 'FontUnits','points','FontSize',12); 63 66 uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.7 0.005 0.2 0.07],'Callback',@(src,event)close(option,src,event),... … … 80 83 drawnow 81 84 end 82 refresh_GUI(findobj(hfig,'Tag','refresh'),InputFileName )% refresh the list of content of the current dir85 refresh_GUI(findobj(hfig,'Tag','refresh'),InputFileName,FilterExt)% refresh the list of content of the current dir 83 86 if ~strcmp(option,'status_display') 84 87 uiwait(hfig) … … 98 101 %------------------------------------------------------------------------ 99 102 % --- launched by refreshing the display figure 100 function refresh_GUI(hObject,InputFileName )103 function refresh_GUI(hObject,InputFileName,FilterExt) 101 104 %------------------------------------------------------------------------ 102 105 if ~exist('InputFileName','var') … … 125 128 NbOutputFile_str=num2str(NbOutputFile); 126 129 end 127 [ListFiles,NumFiles]=list_files(DirName,1,TimeStart );% list the directory content130 [ListFiles,NumFiles]=list_files(DirName,1,TimeStart,FilterExt);% list the directory content 128 131 129 132 %% update the waitbar … … 140 143 end 141 144 hcheck_date=findobj(hfig,'tag','check_date'); 142 [ListFiles,NumFiles]=list_files(DirName,get(hcheck_date,'Value'),sort_option );% list the directory content145 [ListFiles,NumFiles]=list_files(DirName,get(hcheck_date,'Value'),sort_option,FilterExt);% list the directory content 143 146 end 144 147 … … 169 172 %------------------------------------------------------------------------ 170 173 % --- launched by selecting an item on the file list 171 function list_Callback(option, hObject,event)174 function list_Callback(option,filter_ext,hObject,event) 172 175 %------------------------------------------------------------------------ 173 176 hfig=get(hObject,'parent');%handle of the fig … … 214 217 hcheck_date=findobj(hfig,'tag','check_date'); 215 218 216 ListFiles=list_files(FullSelectName,get(hcheck_date,'Value'),sort_option );% list the directory content219 ListFiles=list_files(FullSelectName,get(hcheck_date,'Value'),sort_option,filter_ext);% list the directory content 217 220 set(hObject,'Value',1) 218 221 set(hObject,'String',ListFiles) … … 242 245 %------------------------------------------------------------------------- 243 246 % list the content of a directory 244 function [ListFiles,NumFiles]=list_files(DirName,check_date,sort_option )247 function [ListFiles,NumFiles]=list_files(DirName,check_date,sort_option,filter_ext) 245 248 %------------------------------------------------------------------------- 246 249 ListStruct=dir(DirName);% get structure of the current directory … … 253 256 ListFiles=ListCells(1,:);%list of file names 254 257 check_dir=cell2mat(ListCells(4,:));% =1 for directories, =0 for files 258 255 259 ListFiles(check_dir)=regexprep(ListFiles(check_dir),'^.+','+/$0');% put '+/' in front of dir name display 256 260 ListDates=cell2mat(ListCells(5,:));%list of numerical dates … … 262 266 ListDates(check_dir)=max(ListDates(~check_dir))+1000; % we set the dir in front 263 267 end 268 264 269 if isnumeric(sort_option)|| strcmp(sort_option,'date') 265 270 [tild,index_sort]=sort(ListDates,2,'descend');% sort files by chronological order, recent first, put the dir first in the list … … 270 275 cell_remove=regexp(ListFiles,'^(-|\.|\+/\.)');% detect strings beginning by '-' ,'.' or '+/.'(dir beginning by . ) 271 276 check_keep=cellfun('isempty', cell_remove); 277 if exist('filter_ext') 278 switch filter_ext 279 case 'image' 280 check_keep=check_keep & (cellfun(@isimage,ListFiles) |check_dir); 281 end 282 end 272 283 ListFiles=[{'+/..'} ListFiles(check_keep)]; 273 284 if check_date … … 319 330 320 331 %------------------------------------------------------------------------- 321 % launched by deleting the status figure (only used in mode series status') 332 % --- launched by deleting the status figure (only used in mode series status') 333 %------------------------------------------------------------------------- 322 334 function close(option,hObject, eventdata) 323 %------------------------------------------------------------------------- 335 324 336 if strcmp(option,'status_display') 325 337 hseries=findobj(allchild(0),'Tag','series'); … … 330 342 delete(gcbf) 331 343 344 %------------------------------------------------------------------------- 345 % --- check whether a file is has an image name extension 346 %------------------------------------------------------------------------- 347 function CheckImage=isimage(filename) 348 349 [pp,name,ext]=fileparts(filename); 350 ext 351 CheckImage=~isempty(ext)&&~strcmp(ext,'.')&&~isempty(imformats(regexprep(ext,'^.',''))); -
trunk/src/uvmat.m
r638 r641 1283 1283 %case of view mask selection 1284 1284 if isequal(get(handles.CheckMask,'Value'),1) 1285 [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles); 1286 FileBase=fullfile(RootPath,SubDir,RootFile); 1287 num_i1=stra2num(get(handles.i1,'String')); 1288 num_j1=stra2num(get(handles.j1,'String')); 1289 currentdir=pwd; 1290 cd(RootPath); 1291 maskfiles=dir('*_*mask_*.png');%look for a mask file 1292 cd(currentdir);%come back to the working directory 1285 [RootPath,SubDir]=read_file_boxes(handles); 1286 MaskSubDir=regexprep(SubDir,'\..*','');%take the root part of SubDir, before the first dot '.' 1287 MaskPath=fullfile(RootPath,[MaskSubDir '.mask']); 1293 1288 mdetect=0; 1294 if ~isempty(maskfiles)1295 for ilist=1:length(maskfiles)1296 maskname=maskfiles(ilist).name;% take the first mask file in the list1297 [tild,tild,tild,tild,tild,tild,tild,MaskExt,Mask_NomType{ilist}]=fileparts_uvmat(maskname);1298 [tild,Name]=fileparts(maskname);1299 Namedouble=double(Name);1300 val=(48>Namedouble)|(Namedouble>57);% select the non-numerical characters1301 ind_mask=findstr('mask',Name);1302 i=ind_mask-1;1303 while val(i)==0 && i>01304 i=i-1;1289 if exist(MaskPath,'dir') 1290 ListStruct=dir(MaskPath);%look for a mask file 1291 ListCells=struct2cell(ListStruct);% transform dir struct to a cell arrray 1292 check_dir=cell2mat(ListCells(4,:));% =1 for directories, =0 for files 1293 ListFiles=ListCells(1,:);%list of file names 1294 ListFiles=ListFiles(~check_dir); 1295 if ~isempty(ListFiles) 1296 [tild,tild,MaskExt]=fileparts(ListFiles{1}); 1297 [tild,tild,MaskFile,i1_series,i2_series,j1_series,j2_series,MaskNomType,MaskFileType]=find_file_series(MaskPath,ListFiles{1}); 1298 if strcmp(MaskFileType,'image') && isempty(i2_series) && isempty(j2_series) 1299 mdetect=1; 1305 1300 end 1306 nbmask_str=str2num(Name(i+1:ind_mask-1)); 1307 if ~isempty(nbmask_str) 1308 nbslice(ilist)=nbmask_str; % number of different masks (slices) 1301 end 1302 if mdetect==0 1303 MaskFullName=uigetfile_uvmat('pick a mask image file:',fullfile(RootPath,SubDir),'image'); 1304 [MaskPath,MaskName,MaskExt]=fileparts(MaskFullName); 1305 [tild,tild,MaskFile,i1_series,i2_series,j1_series,j2_series,MaskNomType]=find_file_series(MaskPath,[MaskName MaskExt]); 1306 if ~(isempty(i2_series) && isempty(j2_series)) 1307 MaskNomType='*'; 1309 1308 end 1310 1309 end 1311 if isequal(min(nbslice),max(nbslice)) 1312 nbslice=nbslice(1); 1313 else 1314 msgbox_uvmat('ERROR','several inconsistent mask sets coexist in the current image directory') 1315 return 1316 end 1317 if ~isempty(nbslice) && Name(i)=='_' 1318 Mask.Base=[FileBase Name(i:ind_mask+3)]; 1319 Mask.NbSlice=nbslice; 1320 num_i1=mod(num_i1-1,nbslice)+1; 1321 Mask.NomType=regexprep(Mask_NomType{1},'0','');%remove '0' in nom type for masks 1322 [RootPath,RootFile]=fileparts(Mask.Base); 1323 maskname=fullfile_uvmat(RootPath,'',RootFile,'.png',Mask.NomType,num_i1,[],num_j1); 1324 %maskname=name_generator(Mask.Base,num_i1,num_j1,'.png',Mask.NomType);% 1325 mdetect=exist(maskname,'file'); 1326 if mdetect 1327 set(handles.num_NbSlice,'String',Name(i+1:ind_mask-1)); 1328 set(handles.num_NbSlice,'BackgroundColor',[1 1 0]) 1329 set(handles.CheckMask,'UserData',Mask); 1330 set(handles.CheckMask,'BackgroundColor',[1 1 0]) 1331 if nbslice > 1 1332 set(handles.slices,'value',1) 1333 slices_Callback(hObject, eventdata, handles) 1334 end 1335 end 1336 end 1337 end 1338 errormsg=[];%default 1339 if mdetect==0 1340 maskname=uigetfile_uvmat('pick a mask image file:',fullfile(RootPath,SubDir)); 1341 1342 %% display the selected field and related information 1343 if isempty(maskname) 1344 set(handles.CheckMask,'Value',0) 1345 return 1346 end 1347 % [FileName, PathName, filterindex] = uigetfile( ... 1348 % {'*.png', ' (*.png)'; 1349 % '*.png', '.png files '; ... 1350 % '*.*', 'All Files (*.*)'}, ... 1351 % 'Pick a mask file *.png',FileBase); 1352 % if ~ischar(FileName),return,end %abandon if the browser is cancelled 1353 % maskname=fullfile(PathName,FileName); 1354 [RootDir,SubDir,RootFile,tild,tild,tild,tild,tild,Mask.NomType]=fileparts_uvmat(maskname); 1355 Mask.Base=fullfile(RootDir,SubDir,RootFile); 1356 % Mask.NbSlice=1; 1310 Mask.Path=MaskPath; 1311 Mask.File=MaskFile; 1312 Mask.Ext=MaskExt; 1313 Mask.NomType=MaskNomType; 1357 1314 set(handles.CheckMask,'UserData',Mask); 1358 % set(handles.CheckMask,'BackgroundColor',[1 1 0]) 1359 end 1360 if isempty(errormsg) 1361 errormsg=update_mask(handles,num_i1,num_j1); 1362 end 1363 if ~isempty(errormsg) 1364 set(handles.CheckMask,'Value',0) 1365 set(handles.CheckMask,'BackgroundColor',[0.7 0.7 0.7]) 1366 end 1315 end 1316 errormsg=update_mask(handles); 1367 1317 else % desactivate mask display 1368 1318 MaskData=get(handles.CheckMask,'UserData'); 1369 1319 if isfield(MaskData,'maskhandle') && ishandle(MaskData.maskhandle) 1370 delete(MaskData.maskhandle)1371 end 1372 set(handles.CheckMask,'UserData',[]) 1320 delete(MaskData.maskhandle) 1321 end 1322 set(handles.CheckMask,'UserData',[]) 1373 1323 UvData=get(handles.uvmat,'UserData'); 1374 1324 if isfield(UvData,'MaskName') … … 1380 1330 1381 1331 %------------------------------------------------------------------------ 1382 function errormsg=update_mask(handles ,num_i1,num_j1)1332 function errormsg=update_mask(handles) 1383 1333 %------------------------------------------------------------------------ 1384 1334 errormsg=[];%default 1385 MaskData=get(handles.CheckMask,'UserData'); 1386 if isfield(MaskData,'maskhandle')&& ishandle(MaskData.maskhandle) 1387 uistack(MaskData.maskhandle,'top'); 1388 end 1389 num_i1_mask=mod(num_i1-1,MaskData.NbSlice)+1; 1390 [RootPath,RootFile]=fileparts(MaskData.Base); 1391 MaskName=fullfile_uvmat(RootPath,'',RootFile,'.png',MaskData.NomType,num_i1_mask,[],num_j1); 1335 Mask=get(handles.CheckMask,'UserData'); 1336 MaskIndex=1; 1337 if strcmp(get(handles.z_index,'Visible'),'on') 1338 MaskIndex=str2num(get(handles.z_index,'String')); 1339 end 1340 if isfield(Mask,'maskhandle')&& ishandle(Mask.maskhandle) 1341 uistack(Mask.maskhandle,'top'); 1342 end 1343 MaskName=fullfile_uvmat(Mask.Path,'',Mask.File,Mask.Ext,Mask.NomType,MaskIndex); 1392 1344 UvData=get(handles.uvmat,'UserData'); 1393 %update mask image if the mask is new 1345 1346 %% update mask image if the mask is new 1394 1347 if ~ (isfield(UvData,'MaskName') && isequal(UvData.MaskName,MaskName)) 1395 1348 UvData.MaskName=MaskName; %update the recorded name on UvData 1396 1349 set(handles.uvmat,'UserData',UvData); 1397 1350 if ~exist(MaskName,'file') 1398 if isfield(Mask Data,'maskhandle')&& ishandle(MaskData.maskhandle)1399 delete(Mask Data.maskhandle)1351 if isfield(Mask,'maskhandle')&& ishandle(Mask.maskhandle) 1352 delete(Mask.maskhandle) 1400 1353 end 1401 1354 else 1402 1355 %read mask image 1403 [Mask,tild,errormsg] = read_field(MaskName,'image'); 1404 % Mask.AName='image'; 1405 % Mask.A=imread(MaskName); 1356 [MaskField,tild,errormsg] = read_field(MaskName,'image'); 1406 1357 if ~isempty(errormsg) 1407 1358 return 1408 1359 end 1409 npxy=size(Mask .A);1360 npxy=size(MaskField.A); 1410 1361 if length(npxy)>2 1411 1362 errormsg=[MaskName ' is not a grey scale image']; 1412 1363 return 1413 elseif ~isa(Mask .A,'uint8')1364 elseif ~isa(MaskField.A,'uint8') 1414 1365 errormsg=[MaskName ' is not a 8 bit grey level image']; 1415 1366 return 1416 1367 end 1417 % Mask.AX=[0.5 npxy(2)-0.5]; 1418 % Mask.AY=[npxy(1)-0.5 0.5 ]; 1419 % Mask.CoordUnit='pixel'; 1420 if isequal(get(handles.slices,'Value'),1) 1421 NbSlice=str2num(get(handles.num_NbSlice,'String')); 1422 num_i1=str2num(get(handles.i1,'String')); 1423 Mask.ZIndex=mod(num_i1-1,NbSlice)+1; 1424 end 1368 MaskField.ZIndex=MaskIndex; 1425 1369 %px to phys or other transform on field 1426 1370 menu_transform=get(handles.TransformName,'String'); … … 1431 1375 if isfield(UvData,'XmlData') && isfield(UvData.XmlData{1},'GeometryCalib')%use geometry calib recorded from the ImaDoc xml file as first priority 1432 1376 Calib=UvData.XmlData{1}.GeometryCalib; 1433 Mask =transform(Mask,UvData.XmlData{1});1377 MaskField=transform(MaskField,UvData.XmlData{1}); 1434 1378 end 1435 1379 end 1436 flagmask=Mask .A < 200;1380 flagmask=MaskField.A < 200; 1437 1381 1438 1382 %make brown color image … … 1443 1387 %update mask image 1444 1388 hmask=[]; %default 1445 if isfield(Mask Data,'maskhandle')&& ishandle(MaskData.maskhandle)1446 hmask=Mask Data.maskhandle;1389 if isfield(Mask,'maskhandle')&& ishandle(Mask.maskhandle) 1390 hmask=Mask.maskhandle; 1447 1391 end 1448 1392 if ~isempty(hmask) 1449 1393 set(hmask,'CData',imflag) 1450 1394 set(hmask,'AlphaData',flagmask*0.6) 1451 set(hmask,'XData',Mask .AX);1452 set(hmask,'YData',Mask .AY);1395 set(hmask,'XData',MaskField.AX); 1396 set(hmask,'YData',MaskField.AY); 1453 1397 % uistack(hmask,'top') 1454 1398 else 1455 1399 axes(handles.PlotAxes) 1456 1400 hold on 1457 Mask Data.maskhandle=image(Mask.AX,Mask.AY,imflag,'Tag','mask','HitTest','off','AlphaData',0.6*ones(size(flagmask)));1458 set(handles.CheckMask,'UserData',Mask Data)1401 Mask.maskhandle=image(MaskField.AX,MaskField.AY,imflag,'Tag','mask','HitTest','off','AlphaData',0.6*ones(size(flagmask))); 1402 set(handles.CheckMask,'UserData',Mask) 1459 1403 end 1460 1404 end … … 2756 2700 %% update the mask 2757 2701 if isequal(get(handles.CheckMask,'Value'),1)%if the mask option is on 2758 update_mask(handles ,num_i1,num_i2);2702 update_mask(handles); 2759 2703 end 2760 2704 … … 3721 3665 XmlData=UvData.XmlData{1}; 3722 3666 DataOut=feval(transform_handle,'*',XmlData); 3723 if isfield(DataOut,'CoordUnit') 3667 if isfield(DataOut,'CoordUnit')% set the requested coord unit (info used to possibly delete the current projection objects) 3724 3668 CoordUnit=DataOut.CoordUnit; 3725 3669 end 3726 if isfield(DataOut,'InputFieldType') 3670 if isfield(DataOut,'InputFieldType')% to be used to impose a type of input file (eg. for image transform) 3727 3671 UvData.InputFieldType=DataOut.InputFieldType; 3672 end 3673 if isfield(DataOut,'XmlData')% used to add transform parameters at selection of the transform fct 3674 ListFields=fieldnames(DataOut.XmlData); 3675 for ilist=1:numel(ListFields) 3676 UvData.XmlData{1}.(ListFields{ilist})=DataOut.XmlData.(ListFields{ilist}); 3677 end 3728 3678 end 3729 3679 else
Note: See TracChangeset
for help on using the changeset viewer.