- Timestamp:
- Nov 26, 2010, 5:47:09 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/uvmat.m
r132 r139 693 693 hhh=which('mmreader'); 694 694 ColorType=imainfo.ImageType;%='truecolor' for color images 695 elseif ~isempty( imformats(FileExt(2:end))) || isequal(FileExt,'.vol')%&& isequal(NomType,'*')% multi-frame image695 elseif ~isempty(FileExt(2:end))&&(~isempty(imformats(FileExt(2:end))) || isequal(FileExt,'.vol'))%&& isequal(NomType,'*')% multi-frame image 696 696 testima=1; 697 697 if ~isequal(SubDir,'') … … 1378 1378 function i1_Callback(hObject, eventdata, handles) 1379 1379 %------------------------------------------------------------------- 1380 % [filebase,num1,num_a,num2,num_b,ext,NomType,subdir]=read_input_file(handles); 1381 %[FileName,RootPath,filebase,xx,FileExt]=read_file_boxes(handles); 1380 set(handles.i1,'BackgroundColor',[0.7 0.7 0.7]) 1382 1381 NomType=get(handles.FileIndex,'UserData'); 1383 1382 num1=stra2num(get(handles.i1,'String')); … … 1387 1386 indices=name_generator('',num1,num_a,'',NomType,1,num2,num_b,''); 1388 1387 set(handles.FileIndex,'String',indices) 1388 set(handles.FileIndex,'BackgroundColor',[0.7 0.7 0.7]) 1389 1389 if get(handles.SubField,'Value')==1 1390 1390 NomType_1=get(handles.FileIndex_1,'String'); … … 1393 1393 indices=name_generator('',num1,num_a,'',NomType_1,1,num2,num_b,''); 1394 1394 set(handles.FileIndex_1,'String',indices) 1395 end 1396 run0_Callback(hObject, eventdata, handles) 1395 set(handles.FileIndex_1,'BackgroundColor',[0.7 0.7 0.7]) 1396 end 1397 %Run0_Callback(hObject, eventdata, handles) 1397 1398 1398 1399 %------------------------------------------------------------------- 1399 1400 function i2_Callback(hObject, eventdata, handles) 1401 set(handles.i2,'BackgroundColor',[0.7 0.7 0.7]) 1400 1402 i1_Callback(hObject, eventdata, handles) 1401 1403 %------------------------------------------------------------------- … … 1403 1405 %------------------------------------------------------------------- 1404 1406 function j1_Callback(hObject, eventdata, handles) 1407 set(handles.j1,'BackgroundColor',[0.7 0.7 0.7]) 1405 1408 i1_Callback(hObject, eventdata, handles) 1406 1409 %------------------------------------------------------------------- … … 1408 1411 %------------------------------------------------------------------- 1409 1412 function j2_Callback(hObject, eventdata, handles) 1413 set(handles.j2,'BackgroundColor',[0.7 0.7 0.7]) 1410 1414 i1_Callback(hObject, eventdata, handles) 1411 1415 %------------------------------------------------------------------- … … 1464 1468 function mask_test_Callback(hObject, eventdata, handles) 1465 1469 %------------------------------------------------------------------- 1470 %case of view mask selection 1466 1471 if isequal(get(handles.mask_test,'Value'),1) 1467 1472 [FF,RootPath,FileBase]=read_file_boxes(handles); … … 1473 1478 cd(currentdir);%come back to the working directory 1474 1479 mdetect=0; 1475 if isempty(maskfiles) 1476 msgbox_uvmat('ERROR','no mask file detected (format ..._xxmask_ii.png needed), use the menu bar Tools/Make mask') 1477 return 1478 end 1479 for ilist=1:length(maskfiles) 1480 maskname=maskfiles(ilist).name;% take the first mask file in the list 1481 [rr,ff,x1,x2,xa,xb,xext,Mask_NomType{ilist}]=name2display(maskname); 1482 if ~strcmp(Mask_NomType{ilist},Mask_NomType{1}) 1483 msgbox_uvmat('ERROR',['inconsistent mask types ' Mask_NomType{1} Mask_NomType{ilist } ' coexist in the current image directory']) 1480 if ~isempty(maskfiles) 1481 for ilist=1:length(maskfiles) 1482 maskname=maskfiles(ilist).name;% take the first mask file in the list 1483 [rr,ff,x1,x2,xa,xb,xext,Mask_NomType{ilist}]=name2display(maskname); 1484 if ~strcmp(Mask_NomType{ilist},Mask_NomType{1}) 1485 msgbox_uvmat('ERROR',['inconsistent mask types ' Mask_NomType{1} Mask_NomType{ilist } ' coexist in the current image directory']) 1486 return 1487 end 1488 [Path2,Name,ext]=fileparts(maskname); 1489 Namedouble=double(Name); 1490 val=(48>Namedouble)|(Namedouble>57);% select the non-numerical characters 1491 ind_mask=findstr('mask',Name); 1492 i=ind_mask-1; 1493 while val(i)==0 && i>0 1494 i=i-1; 1495 end 1496 nbmask_str=str2num(Name(i+1:ind_mask-1)); 1497 if ~isempty(nbmask_str) 1498 nbslice(ilist)=nbmask_str; % number of different masks (slices) 1499 end 1500 end 1501 if isequal(min(nbslice),max(nbslice)) 1502 nbslice=nbslice(1); 1503 else 1504 msgbox_uvmat('ERROR','several inconsistent mask sets coexist in the current image directory') 1484 1505 return 1485 1506 end 1486 [Path2,Name,ext]=fileparts(maskname); 1487 Namedouble=double(Name); 1488 val=(48>Namedouble)|(Namedouble>57);% select the non-numerical characters 1489 ind_mask=findstr('mask',Name); 1490 i=ind_mask-1; 1491 while val(i)==0 && i>0 1492 i=i-1; 1493 end 1494 nbmask_str=str2num(Name(i+1:ind_mask-1)); 1495 if ~isempty(nbmask_str) 1496 nbslice(ilist)=nbmask_str; % number of different masks (slices) 1497 end 1498 end 1499 if isequal(min(nbslice),max(nbslice)) 1500 nbslice=nbslice(1); 1501 else 1502 msgbox_uvmat('ERROR','several inconsistent mask sets coexist in the current image directory') 1503 return 1504 end 1505 if ~isempty(nbslice) && Name(i)=='_' 1506 Mask.Base=[FileBase Name(i:ind_mask+3)]; 1507 Mask.NbSlice=nbslice; 1508 num_i1=mod(num_i1-1,nbslice)+1; 1509 Mask.NomType=Mask_NomType{1}; 1510 [maskname,mdetect]=name_generator(Mask.Base,num_i1,num_j1,'.png',Mask.NomType);% 1511 mdetect=exist(maskname,'file'); 1512 if mdetect 1513 set(handles.nb_slice,'String',Name(i+1:ind_mask-1)); 1514 set(handles.nb_slice,'BackgroundColor',[1 1 0]) 1515 set(handles.mask_test,'UserData',Mask); 1516 set(handles.mask_test,'BackgroundColor',[1 1 0]) 1517 if nbslice > 1 1518 set(handles.slices,'value',1) 1519 slices_Callback(hObject, eventdata, handles) 1507 if ~isempty(nbslice) && Name(i)=='_' 1508 Mask.Base=[FileBase Name(i:ind_mask+3)]; 1509 Mask.NbSlice=nbslice; 1510 num_i1=mod(num_i1-1,nbslice)+1; 1511 Mask.NomType=Mask_NomType{1}; 1512 [maskname,mdetect]=name_generator(Mask.Base,num_i1,num_j1,'.png',Mask.NomType);% 1513 mdetect=exist(maskname,'file'); 1514 if mdetect 1515 set(handles.nb_slice,'String',Name(i+1:ind_mask-1)); 1516 set(handles.nb_slice,'BackgroundColor',[1 1 0]) 1517 set(handles.mask_test,'UserData',Mask); 1518 set(handles.mask_test,'BackgroundColor',[1 1 0]) 1519 if nbslice > 1 1520 set(handles.slices,'value',1) 1521 slices_Callback(hObject, eventdata, handles) 1522 end 1520 1523 end 1521 1524 end 1522 end 1525 % if mdetect==0 1526 % msgbox_uvmat('ERROR','no mask file detected (format ..._xxmask_ii.png needed), use the menu bar Tools/Make mask') 1527 % set(handles.mask_test,'Value',0) 1528 % return 1529 % end 1530 end 1531 errormsg=[];%default 1523 1532 if mdetect==0 1524 msgbox_uvmat('ERROR','no mask file detected (format ..._xxmask_ii.png needed), use the menu bar Tools/Make mask') 1525 set(handles.mask_test,'Value',0) 1526 return 1527 end 1528 update_mask(handles,num_i1,num_j1); 1529 else 1533 [FileName, PathName, filterindex] = uigetfile( ... 1534 {'*.png', ' (*.png)'; 1535 '*.png', '.png files '; ... 1536 '*.*', 'All Files (*.*)'}, ... 1537 'Pick a mask file *.png',FileBase); 1538 maskname=fullfile(PathName,FileName); 1539 if ~exist(maskname,'file') 1540 errormsg='no file browsed'; 1541 end 1542 [RootDir,RootFile,x1,x2,xa,xb,xext,Mask.NomType]=name2display(maskname); 1543 Mask.Base=fullfile(RootDir,RootFile); 1544 Mask.NbSlice=1; 1545 set(handles.mask_test,'UserData',Mask); 1546 set(handles.mask_test,'BackgroundColor',[1 1 0]) 1547 end 1548 if isempty(errormsg) 1549 errormsg=update_mask(handles,num_i1,num_j1); 1550 end 1551 if ~isempty(errormsg) 1552 set(handles.mask_test,'Value',0) 1553 set(handles.mask_test,'BackgroundColor',[0.7 0.7 0.7]) 1554 end 1555 else 1530 1556 MaskData=get(handles.mask_test,'UserData'); 1531 1557 if isfield(MaskData,'maskhandle') && ishandle(MaskData.maskhandle) … … 1543 1569 1544 1570 %------------------------------------------------------------------- 1545 function update_mask(handles,num_i1,num_j1)1546 %------------------------------------------------------------------- 1547 1571 function errormsg=update_mask(handles,num_i1,num_j1) 1572 %------------------------------------------------------------------- 1573 errormsg=[];%default 1548 1574 MaskData=get(handles.mask_test,'UserData'); 1549 1575 if isfield(MaskData,'maskhandle')&& ishandle(MaskData.maskhandle) … … 1551 1577 end 1552 1578 num_i1_mask=mod(num_i1-1,MaskData.NbSlice)+1; 1553 [MaskName,mdetect]=name_generator(MaskData.Base,num_i1_mask,num_j1,'.png',MaskData.NomType); 1579 MaskData.NomType 1580 MaskName=name_generator(MaskData.Base,num_i1_mask,num_j1,'.png',MaskData.NomType); 1554 1581 huvmat=get(handles.mask_test,'parent'); 1555 1582 UvData=get(huvmat,'UserData'); … … 1559 1586 UvData.MaskName=MaskName; %update the recorded name on UvData 1560 1587 set(huvmat,'UserData',UvData); 1561 if mdetect==01588 if ~exist(MaskName,'file') 1562 1589 if isfield(MaskData,'maskhandle')&& ishandle(MaskData.maskhandle) 1563 1590 delete(MaskData.maskhandle) … … 1568 1595 Mask.A=imread(MaskName); 1569 1596 npxy=size(Mask.A); 1597 test_error=0; 1598 if length(npxy)>2 1599 errormsg=[MaskName ' is not a grey scale image']; 1600 return 1601 elseif ~isa(Mask.A,'uint8') 1602 errormsg=[MaskName ' is not a 8 bit grey level image']; 1603 return 1604 end 1570 1605 Mask.AX=[0.5 npxy(2)-0.5]; 1571 1606 Mask.AY=[npxy(1)-0.5 0.5 ]; … … 1991 2026 if ~isempty(errormsg) 1992 2027 msgbox_uvmat('ERROR',errormsg); 2028 else 2029 set(handles.i1,'BackgroundColor',[1 1 1]) 2030 set(handles.i2,'BackgroundColor',[1 1 1]) 2031 set(handles.j1,'BackgroundColor',[1 1 1]) 2032 set(handles.j2,'BackgroundColor',[1 1 1]) 2033 set(handles.FileIndex,'BackgroundColor',[1 1 1]) 2034 set(handles.FileIndex_1,'BackgroundColor',[1 1 1]) 1993 2035 end 1994 2036 set(handles.run0,'BackgroundColor',[1 0 0]) 2037 1995 2038 1996 2039 %------------------------------------------------------------------------ … … 4766 4809 answer=msgbox_uvmat('INPUT_TXT','mask file name:', mask_name); 4767 4810 if ~strcmp(answer,'Cancel') 4811 mask_dir=fileparts(answer); 4812 if ~exist(mask_dir,'dir') 4813 msgbox_uvmat('ERROR',['directory ' mask_dir ' does not exist']) 4814 return 4815 end 4768 4816 imwrite(imflag,answer,'BitDepth',8); 4769 4817 end
Note: See TracChangeset
for help on using the changeset viewer.