Changeset 139


Ignore:
Timestamp:
Nov 26, 2010, 5:47:09 AM (13 years ago)
Author:
sommeria
Message:

possibility of displaying a mask with any name: if 'view mask' is selected it will first look for the mask in the current directory, else a browser appears and any mask can be choosen.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/uvmat.m

    r132 r139  
    693693    hhh=which('mmreader');
    694694    ColorType=imainfo.ImageType;%='truecolor' for color images
    695 elseif ~isempty(imformats(FileExt(2:end))) || isequal(FileExt,'.vol')%&& isequal(NomType,'*')% multi-frame image
     695elseif ~isempty(FileExt(2:end))&&(~isempty(imformats(FileExt(2:end))) || isequal(FileExt,'.vol'))%&& isequal(NomType,'*')% multi-frame image
    696696    testima=1;
    697697    if ~isequal(SubDir,'')
     
    13781378function i1_Callback(hObject, eventdata, handles)
    13791379%-------------------------------------------------------------------
    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);
     1380set(handles.i1,'BackgroundColor',[0.7 0.7 0.7])
    13821381NomType=get(handles.FileIndex,'UserData');
    13831382num1=stra2num(get(handles.i1,'String'));
     
    13871386indices=name_generator('',num1,num_a,'',NomType,1,num2,num_b,'');
    13881387set(handles.FileIndex,'String',indices)
     1388set(handles.FileIndex,'BackgroundColor',[0.7 0.7 0.7])
    13891389if get(handles.SubField,'Value')==1
    13901390    NomType_1=get(handles.FileIndex_1,'String');
     
    13931393     indices=name_generator('',num1,num_a,'',NomType_1,1,num2,num_b,'');
    13941394     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])
     1396end
     1397%Run0_Callback(hObject, eventdata, handles)
    13971398
    13981399%-------------------------------------------------------------------
    13991400function i2_Callback(hObject, eventdata, handles)
     1401set(handles.i2,'BackgroundColor',[0.7 0.7 0.7])
    14001402i1_Callback(hObject, eventdata, handles)
    14011403%-------------------------------------------------------------------
     
    14031405%-------------------------------------------------------------------
    14041406function j1_Callback(hObject, eventdata, handles)
     1407set(handles.j1,'BackgroundColor',[0.7 0.7 0.7])
    14051408i1_Callback(hObject, eventdata, handles)
    14061409%-------------------------------------------------------------------
     
    14081411%-------------------------------------------------------------------
    14091412function j2_Callback(hObject, eventdata, handles)
     1413set(handles.j2,'BackgroundColor',[0.7 0.7 0.7])
    14101414i1_Callback(hObject, eventdata, handles)
    14111415%-------------------------------------------------------------------
     
    14641468function mask_test_Callback(hObject, eventdata, handles)
    14651469%-------------------------------------------------------------------
     1470%case of view mask selection
    14661471if isequal(get(handles.mask_test,'Value'),1)
    14671472    [FF,RootPath,FileBase]=read_file_boxes(handles);
     
    14731478    cd(currentdir);%come back to the working directory
    14741479    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')
    14841505            return
    14851506        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
    15201523            end
    15211524        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
    15231532    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
     1555else
    15301556    MaskData=get(handles.mask_test,'UserData');
    15311557    if isfield(MaskData,'maskhandle') && ishandle(MaskData.maskhandle)
     
    15431569
    15441570%-------------------------------------------------------------------
    1545 function update_mask(handles,num_i1,num_j1)
    1546 %-------------------------------------------------------------------
    1547 
     1571function errormsg=update_mask(handles,num_i1,num_j1)
     1572%-------------------------------------------------------------------
     1573errormsg=[];%default
    15481574MaskData=get(handles.mask_test,'UserData');
    15491575if isfield(MaskData,'maskhandle')&& ishandle(MaskData.maskhandle)
     
    15511577end
    15521578num_i1_mask=mod(num_i1-1,MaskData.NbSlice)+1;
    1553 [MaskName,mdetect]=name_generator(MaskData.Base,num_i1_mask,num_j1,'.png',MaskData.NomType);
     1579MaskData.NomType
     1580MaskName=name_generator(MaskData.Base,num_i1_mask,num_j1,'.png',MaskData.NomType);
    15541581huvmat=get(handles.mask_test,'parent');
    15551582UvData=get(huvmat,'UserData');
     
    15591586    UvData.MaskName=MaskName; %update the recorded name on UvData
    15601587    set(huvmat,'UserData',UvData);
    1561     if mdetect==0
     1588    if ~exist(MaskName,'file')
    15621589        if isfield(MaskData,'maskhandle')&& ishandle(MaskData.maskhandle)
    15631590            delete(MaskData.maskhandle)   
     
    15681595        Mask.A=imread(MaskName);
    15691596        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
    15701605        Mask.AX=[0.5 npxy(2)-0.5];
    15711606        Mask.AY=[npxy(1)-0.5 0.5 ];
     
    19912026if ~isempty(errormsg)
    19922027      msgbox_uvmat('ERROR',errormsg);
     2028else
     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])
    19932035end   
    19942036set(handles.run0,'BackgroundColor',[1 0 0])
     2037
    19952038
    19962039%------------------------------------------------------------------------
     
    47664809        answer=msgbox_uvmat('INPUT_TXT','mask file name:', mask_name);
    47674810        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
    47684816            imwrite(imflag,answer,'BitDepth',8);
    47694817        end
Note: See TracChangeset for help on using the changeset viewer.