isgray.m
来自「有关matlab的电子书籍有一定的帮助希望有用」· M 代码 · 共 38 行
M
38 行
function y = isgray(x)
%ISGRAY Return true for intensity image.
% FLAG = ISGRAY(A) returns 1 if A is a grayscale intensity
% image and 0 otherwise.
%
% ISGRAY uses these criteria to decide if A is an intensity
% image:
%
% - If A is of class double, all values must be in the range
% [0,1], and the number of dimensions of A must be 2.
%
% - If A is of class uint8, the number of dimensions of A must
% be 2.
%
% Class Support
% -------------
% A can be of class uint8 or double.
%
% See also ISBW, ISIND, ISRGB.
% Clay M. Thompson 2-25-93
% Copyright 1993-1998 The MathWorks, Inc. All Rights Reserved.
% $Revision: 5.9 $ $Date: 1997/11/24 15:35:47 $
y = ndims(x)==2;
if ~isa(x, 'uint8') & y
% At first just test a small chunk to get a possible quick negative
[m,n] = size(x);
chunk = x(1:min(m,10),1:min(n,10));
y = min(chunk(:))>=0 & max(chunk(:))<=1;
% If the chunk is an intensity image, test the whole image
if y
y = min(x(:))>=0 & max(x(:))<=1;
end
end
y = logical(double(y)); % Just make sure
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?