isrgb.m

来自「有关matlab的电子书籍有一定的帮助希望有用」· M 代码 · 共 43 行

M
43
字号
function y = isrgb(x)
%ISRGB Return true for RGB image.
%   FLAG = ISRGB(A) returns 1 if A is an RGB truecolor image and
%   0 otherwise.
%
%   ISRGB uses these criteria to determine if A is an RGB image:
%
%   - If A is of class double, all values must be in the range
%     [0,1], and A must be M-by-N-by-3.
%
%   - If A is of class uint8, A must be M-by-N-by-3.
%
%   Note that a four-dimensional array that contains multiple RGB
%   images returns 0, not 1.
%
%   Class Support
%   -------------
%   A can be of class uint8 or double.
%
%   See also ISBW, ISGRAY, ISIND.

%   Chris Griffin 1-6-97
%   Copyright 1993-1998 The MathWorks, Inc.  All Rights Reserved.
%   $Revision: 1.5 $  $Date: 1997/11/24 15:35:50 $

y = size(x,3)==3;
if y
   if isa(x, 'uint8')
      y = ~islogical(x);
   else
      % At first just test a small chunk to get a possible quick negative  
      [m,n,o] = size(x);
      chunk = x(1:min(m,10),1:min(n,10),:);         
      y = (~islogical(chunk) & min(chunk(:))>=0 & max(chunk(:))<=1);
      % If the chunk is an RGB image, test the whole image
      if y
         y = (min(x(:))>=0 & max(x(:))<=1);
      end
   end
end

y = double(logical(y));

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?