📄 im2obj.m
字号:
%IM2OBJ Convert Matlab images to dataset object%% B = IM2OBJ(IM,A)% B = IM2OBJ(IM,FEATSIZE)%% INPUT% IM X*Y image, X*Y*C image, X*Y*K array of K images, % X*Y*C*K array of color images, or cell-array of images% A Input dataset% FEATSIZE Vector with desired feature sizes to solve ambiguities%% OUTPUT% B Dataset with IM added%% DESCRIPTION% Add standard Matlab images, as objects, to an existing dataset A. If A is % not given, a new dataset is created. Images of type 'uint8' are converted% to 'double' and divided by 256. The resulting feature size is X*Y or% X*Y*C%% SEE ALSO% DATASETS, IM2FEAT, DATA2IM% Copyright: R.P.W. Duin, duin@ph.tn.tudelft.nl% Faculty of Applied Physics, Delft University of Technology% P.O. Box 5046, 2600 GA Delft, The Netherlands% $Id: im2obj.m,v 1.4 2007/05/04 08:35:33 duin Exp $function a = im2obj (im,a) prtrace(mfilename); if iscell(im) imsize = size(im{1}); else imsize = size(im); end nodataset = 0; if (nargin > 1) if (~isdataset(a)) & size(a,1) ~= 1 error('second argument should be a dataset or a size vector'); end if isdataset(a) featsize = getfeatsize(a); else featsize = a; nodataset = 1; end else % no information on feature size, assume most simple solution nodataset = 1; if length(imsize) == 2 featsize = imsize; else featsize = imsize(1:end-1); end end if length(featsize) == length(imsize) nobj = 1; elseif length(featsize) == (length(imsize)-1) nobj = imsize(end); elseif length(featsize) == (length(imsize)-2) & imsize(3) == 1 nobj = imsize(end); else wrongfeatsize; end if any(featsize ~= imsize(1:length(featsize))) wrongfeatsize; end if (isa(im,'cell')) % If IM is a cell array of images, unpack it and recursively call IM2OBJ % to add each image. im = im(:); % Reshape to 1D cell array. for i = 1:length(im) b = feval(mfilename,im{i}); if ~isempty(a) & any(a.objsize ~= b.objsize) error('Images should have equal sizes') end a = [a; feval(mfilename,im{i},featsize)]; end else % If IM is an image or array of images, reshape it and add it in one go. % Convert to double, if necessary if (isa(im,'uint8')) prwarning(4,'image is uint8; converting to double and dividing by 256'); im = double(im)/256; else im = double(im); end % ready for the real work, at last! if nobj == 1 im = im(:)'; else im = shiftdim(im,ndims(im)-1); im = reshape(im,nobj,prod(featsize)); end if nodataset a = dataset(im); a = setfeatsize(a,featsize); else a = [a; im]; end end returnfunction wrongfeatsize error('Desired feature size and size of supplied image array are inconsistent')return
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -