Changeset 641


Ignore:
Timestamp:
May 21, 2013, 9:12:42 PM (11 years ago)
Author:
sommeria
Message:

corrections for mask and transform fct

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/uigetfile_uvmat.m

    r635 r641  
    1010% InputDir: directory to browse at first display
    1111
    12 function fileinput=uigetfile_uvmat(title,InputName)
     12function fileinput=uigetfile_uvmat(title,InputName,FilterExt)
     13if ~exist('FilterExt','var')
     14    FilterExt='*';
     15end
    1316fileinput=''; %default file selection
    1417if strcmp(title,'status_display')
     
    5962    uicontrol('Style','popupmenu','Units','normalized', 'Position', [0.75 0.8 0.2 0.04],'tag','sort_option','Callback',@refresh_GUI,'Visible','off',...
    6063            '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',...
    6265        'FontUnits','points','FontSize',12);
    6366    uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.7 0.005 0.2 0.07],'Callback',@(src,event)close(option,src,event),...
     
    8083    drawnow
    8184end
    82 refresh_GUI(findobj(hfig,'Tag','refresh'),InputFileName)% refresh the list of content of the current dir 
     85refresh_GUI(findobj(hfig,'Tag','refresh'),InputFileName,FilterExt)% refresh the list of content of the current dir 
    8386if ~strcmp(option,'status_display') 
    8487    uiwait(hfig)
     
    98101%------------------------------------------------------------------------   
    99102% --- launched by refreshing the display figure
    100 function refresh_GUI(hObject,InputFileName)
     103function refresh_GUI(hObject,InputFileName,FilterExt)
    101104%------------------------------------------------------------------------
    102105if ~exist('InputFileName','var')
     
    125128        NbOutputFile_str=num2str(NbOutputFile);
    126129    end
    127     [ListFiles,NumFiles]=list_files(DirName,1,TimeStart);% list the directory content
     130    [ListFiles,NumFiles]=list_files(DirName,1,TimeStart,FilterExt);% list the directory content
    128131   
    129132    %% update the waitbar
     
    140143    end
    141144    hcheck_date=findobj(hfig,'tag','check_date');
    142     [ListFiles,NumFiles]=list_files(DirName,get(hcheck_date,'Value'),sort_option);% list the directory content
     145    [ListFiles,NumFiles]=list_files(DirName,get(hcheck_date,'Value'),sort_option,FilterExt);% list the directory content
    143146end
    144147
     
    169172%------------------------------------------------------------------------   
    170173% --- launched by selecting an item on the file list
    171 function list_Callback(option,hObject,event)
     174function list_Callback(option,filter_ext,hObject,event)
    172175%------------------------------------------------------------------------
    173176hfig=get(hObject,'parent');%handle of the fig
     
    214217    hcheck_date=findobj(hfig,'tag','check_date');
    215218   
    216     ListFiles=list_files(FullSelectName,get(hcheck_date,'Value'),sort_option);% list the directory content
     219    ListFiles=list_files(FullSelectName,get(hcheck_date,'Value'),sort_option,filter_ext);% list the directory content
    217220    set(hObject,'Value',1)
    218221    set(hObject,'String',ListFiles)
     
    242245%-------------------------------------------------------------------------   
    243246% list the content of a directory
    244 function [ListFiles,NumFiles]=list_files(DirName,check_date,sort_option)
     247function [ListFiles,NumFiles]=list_files(DirName,check_date,sort_option,filter_ext)
    245248%-------------------------------------------------------------------------
    246249ListStruct=dir(DirName);% get structure of the current directory
     
    253256ListFiles=ListCells(1,:);%list of file names
    254257check_dir=cell2mat(ListCells(4,:));% =1 for directories, =0 for files
     258
    255259ListFiles(check_dir)=regexprep(ListFiles(check_dir),'^.+','+/$0');% put '+/' in front of dir name display
    256260ListDates=cell2mat(ListCells(5,:));%list of numerical dates
     
    262266ListDates(check_dir)=max(ListDates(~check_dir))+1000; % we set the dir in front
    263267end
     268
    264269if isnumeric(sort_option)|| strcmp(sort_option,'date')
    265270    [tild,index_sort]=sort(ListDates,2,'descend');% sort files by chronological order, recent first, put the dir first in the list
     
    270275cell_remove=regexp(ListFiles,'^(-|\.|\+/\.)');% detect strings beginning by '-' ,'.' or '+/.'(dir beginning by . )
    271276check_keep=cellfun('isempty', cell_remove);
     277if exist('filter_ext')
     278    switch filter_ext
     279        case 'image'
     280            check_keep=check_keep & (cellfun(@isimage,ListFiles) |check_dir);
     281    end
     282end
    272283ListFiles=[{'+/..'} ListFiles(check_keep)];
    273284if check_date
     
    319330
    320331%-------------------------------------------------------------------------   
    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%-------------------------------------------------------------------------
    322334function close(option,hObject, eventdata)
    323 %-------------------------------------------------------------------------
     335
    324336if strcmp(option,'status_display')
    325337    hseries=findobj(allchild(0),'Tag','series');
     
    330342delete(gcbf)
    331343
     344%-------------------------------------------------------------------------
     345% --- check whether a file is has an image name extension
     346%-------------------------------------------------------------------------
     347function CheckImage=isimage(filename)
     348
     349[pp,name,ext]=fileparts(filename);
     350ext
     351CheckImage=~isempty(ext)&&~strcmp(ext,'.')&&~isempty(imformats(regexprep(ext,'^.','')));
  • trunk/src/uvmat.m

    r638 r641  
    12831283%case of view mask selection
    12841284if 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']);
    12931288    mdetect=0;
    1294     if ~isempty(maskfiles)
    1295         for ilist=1:length(maskfiles)
    1296             maskname=maskfiles(ilist).name;% take the first mask file in the list
    1297             [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 characters
    1301             ind_mask=findstr('mask',Name);
    1302             i=ind_mask-1;
    1303             while val(i)==0 && i>0
    1304                 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;
    13051300            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='*';
    13091308            end
    13101309        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;
    13571314        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);
    13671317else % desactivate mask display
    13681318    MaskData=get(handles.CheckMask,'UserData');
    13691319    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',[])
    13731323    UvData=get(handles.uvmat,'UserData');
    13741324    if isfield(UvData,'MaskName')
     
    13801330
    13811331%------------------------------------------------------------------------
    1382 function errormsg=update_mask(handles,num_i1,num_j1)
     1332function errormsg=update_mask(handles)
    13831333%------------------------------------------------------------------------
    13841334errormsg=[];%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);
     1335Mask=get(handles.CheckMask,'UserData');
     1336MaskIndex=1;
     1337if strcmp(get(handles.z_index,'Visible'),'on')
     1338    MaskIndex=str2num(get(handles.z_index,'String'));
     1339end
     1340if isfield(Mask,'maskhandle')&& ishandle(Mask.maskhandle)
     1341    uistack(Mask.maskhandle,'top');
     1342end
     1343MaskName=fullfile_uvmat(Mask.Path,'',Mask.File,Mask.Ext,Mask.NomType,MaskIndex);
    13921344UvData=get(handles.uvmat,'UserData');
    1393 %update mask image if the mask is new
     1345
     1346%% update mask image if the mask is new
    13941347if ~ (isfield(UvData,'MaskName') && isequal(UvData.MaskName,MaskName))
    13951348    UvData.MaskName=MaskName; %update the recorded name on UvData
    13961349    set(handles.uvmat,'UserData',UvData);
    13971350    if ~exist(MaskName,'file')
    1398         if isfield(MaskData,'maskhandle')&& ishandle(MaskData.maskhandle)
    1399             delete(MaskData.maskhandle)   
     1351        if isfield(Mask,'maskhandle')&& ishandle(Mask.maskhandle)
     1352            delete(Mask.maskhandle)   
    14001353        end
    14011354    else
    14021355        %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');
    14061357        if ~isempty(errormsg)
    14071358            return
    14081359        end
    1409         npxy=size(Mask.A);
     1360        npxy=size(MaskField.A);
    14101361        if length(npxy)>2
    14111362            errormsg=[MaskName ' is not a grey scale image'];
    14121363            return
    1413         elseif ~isa(Mask.A,'uint8')
     1364        elseif ~isa(MaskField.A,'uint8')
    14141365            errormsg=[MaskName ' is not a 8 bit grey level image'];
    14151366            return
    14161367        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;
    14251369        %px to phys or other transform on field
    14261370         menu_transform=get(handles.TransformName,'String');
     
    14311375            if isfield(UvData,'XmlData') && isfield(UvData.XmlData{1},'GeometryCalib')%use geometry calib recorded from the ImaDoc xml file as first priority
    14321376                Calib=UvData.XmlData{1}.GeometryCalib;
    1433                 Mask=transform(Mask,UvData.XmlData{1});
     1377                MaskField=transform(MaskField,UvData.XmlData{1});
    14341378            end
    14351379        end
    1436         flagmask=Mask.A < 200;
     1380        flagmask=MaskField.A < 200;
    14371381       
    14381382        %make brown color image
     
    14431387        %update mask image
    14441388        hmask=[]; %default
    1445         if isfield(MaskData,'maskhandle')&& ishandle(MaskData.maskhandle)
    1446             hmask=MaskData.maskhandle;
     1389        if isfield(Mask,'maskhandle')&& ishandle(Mask.maskhandle)
     1390            hmask=Mask.maskhandle;
    14471391        end
    14481392        if ~isempty(hmask)
    14491393            set(hmask,'CData',imflag)   
    14501394            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);
    14531397%             uistack(hmask,'top')
    14541398        else
    14551399            axes(handles.PlotAxes)
    14561400            hold on   
    1457             MaskData.maskhandle=image(Mask.AX,Mask.AY,imflag,'Tag','mask','HitTest','off','AlphaData',0.6*ones(size(flagmask)));
    1458             set(handles.CheckMask,'UserData',MaskData)
     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)
    14591403        end
    14601404    end
     
    27562700    %% update the mask
    27572701    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);
    27592703    end
    27602704   
     
    37213665        XmlData=UvData.XmlData{1};
    37223666        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)
    37243668            CoordUnit=DataOut.CoordUnit;
    37253669        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)
    37273671            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
    37283678        end
    37293679    else
Note: See TracChangeset for help on using the changeset viewer.