📄 filtim.m
字号:
%FILTIM Mapping to filter multinabnd image objects in datasets and datafiles%% B = FILTM(A,FILTER_COMMAND,{PAR1,PAR2,....},SIZE)% B = A*FILTM([],FILTER_COMMAND,{PAR1,PAR2,....},SIZE)%% INPUT% A Dataset or datafile with image objects% FILTER_COMMAND String with function name% {PAR1, ... } Cell array with optional parameters to FILTER_COMMAND% SIZE Output size of the mapping (default: input size)%% OUTPUT% B Dataset containing images processed by FILTER_COMMAND,% image by image. Image bands are processes separately.%% DESCRIPTION% For each object stored in A a filter operation is performed as%% OBJECT_OUT = FILTER_COMMAND(OBJECT_IN,PAR1,PAR2,....)%% The results are collected and stored in B. In case A (and thereby B) is% a datafile, execution is postponed until conversion into a dataset, or a% call to SAVEDATAFILE.%% The difference between FILTIM and the similar command FILTM is that% FILTIM is aware of the image structure and test on it.%% EXAMPLE% A = DELFT_IMAGES; B = A(120 121 131 230)*COL2GRAY% E = B*FILTM([],'FFT2')*FILTM([],'ABS')*FILTM([],'FFTSHIFT');% FIGURE; SHOW(E); FIGURE; SHOW((1+E)*FILTM([],'LOG')); %% SEE ALSO% DATASETS, DATAFILES, IM2OBJ, DATA2IM, IM2FEAT, DATGAUSS, DATFILT, FILTM% Copyright: R.P.W. Duin, r.p.w.duin@prtools.org% Faculty EWI, Delft University of Technology% P.O. Box 5031, 2600 GA Delft, The Netherlandsfunction b = filtim(a,command,pars,outsize) prtrace(mfilename); if nargin < 4, outsize = []; end if nargin < 3, pars = {}; end if nargin < 2 error('No command given') end if ~iscell(pars), pars = {pars}; end mapname = 'dataset image processing'; if isempty(a) % no data, so just mapping definition b = mapping(mfilename,'fixed',{command,pars}); if ~isempty(outsize) b = setsize_out(b,outsize); end b = setname(b,mapname); return end if isdatafile(a) % for datafiles filters will be stored isobjim(a); if isempty(getpostproc(a)) % as preprocessing (if no preproc defined) b = addpreproc(a,mfilename,{command pars},outsize); else % or as mapping as postprocessing v = mapping(mfilename,'fixed',{command,pars}); if ~isempty(outsize) v = setsize_out(v,outsize); end v = setname(v,mapname); b = addpostproc(a,v); end if ~isempty(outsize) b = setfeatsize(b,outsize); end return elseif isdataset(a) % convert to image and process isobjim(a); m = size(a,1); d = data2im(a); %out = feval(mfilename,d,command,pars{:}); % effectively jumps to double out = feval(mfilename,d,command,pars); % effectively jumps to double fsize = size(out); if m > 1 fsize = fsize(1:3); if fsize(3) == 1 fsize = fsize(1:2); end end % store processed images in dataset b = setdata(a,im2obj(out,fsize)); b = setfeatsize(b,fsize); else % double % make imsize 4D: horz*vert*bands*objects imsize = size(a); if length(imsize) == 2 imsize = [imsize 1 1]; elseif length(imsize) == 3 imsize = [imsize 1]; end % find size of first image first = feval(command,getsubim(a,1,1),pars{:}); if all(imsize(3:4) == 1) % preserve DipLib format for the time being b = first; return end first = double(first); % for DipLib users outsize = size(first); % process all other images b = repmat(first,[1 1 imsize(3:4)]); for i = 1:imsize(3) for j = 1:imsize(4) ima = double(feval(command,getsubim(a,i,j),pars{:})); if (any(outsize ~= size(ima))) % check size error('All image sizes should be the same') end b(:,:,i,j) = ima; end end end returnfunction asub = getsubim(a,i,j)% needed as Dip_Image cannot handle 4d subsript if data is 2d or 3dn = ndims(a);if n == 2 if i ~= 1 | j ~= 1 error('Illegal image requested') end asub = a;elseif n == 3 if j ~= 1 error('Illegal image requested') end asub = a(:,:,i);elseif n == 4 asub = a(:,:,i,j);else error('Incorrect image supplied')end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -