color image: kitchen1.tif
grayscale image: kitchen2.tif
gray = im2double(imread('kitchen2.tif')); rgb = im2double(imread('kitchen1.tif')); diff = gray - rgb2gray(rgb); a = [ max(diff(:)) min(diff(:)) ] rms = std2(diff)
a = 0.0935 -0.0390 rms = 0.0111
cdiff = (diff+1)/2;
imhist(cdiff);
[counts,x] = imhist(cdiff);
stem(x(110:150),counts(110:150));
cdx = (diff - a(2))/(a(1)-a(2)); imshow(cdx) imwrite(cdx,'cdx.jpg');
mean | -0.0036 |
---|---|
stdev | 0.0111 |
max | 0.0353 |
min | -0.0941 |
max-min | 0.1294 |
type rgb2gray.m function a = rgb2gray(r,g,b) %RGB2GRAY Convert RGB image or colormap to grayscale. % RGB2GRAY converts RGB images to grayscale by eliminating the % hue and saturation information while retaining the % luminance. % % I = RGB2GRAY(RGB) converts the truecolor image RGB to the % grayscale intensity image I. % % NEWMAP = RGB2GRAY(MAP) returns a grayscale colormap % equivalent to MAP. % % Class Support % ------------- % If the input is an RGB image, it can be of class uint8 or % double; the output image I is of the same class as the input % image. If the input is a colormap, the input and output % colormaps are both of class double. % % See also IND2GRAY, NTSC2RGB, RGB2IND, RGB2NTSC. % Clay M. Thompson 9-16-92 % Copyright (c) 1993-97 by The MathWorks, Inc. % $Revision: 5.8 $ $Date: 1997/03/11 18:32:12 $ if nargin==0, error('Need input arguments.'); end threeD = (ndims(r)==3); % Determine if input includes a 3-D array if nargin==1, if threeD, rgb = reshape(r(:),size(r,1)*size(r,2),3); a = zeros([size(r,1), size(r,2)]); else % Colormap rgb = r; a = zeros(size(r,1),1); end elseif nargin==2, error('Wrong number of arguments.'); else if (any(size(r)~=size(g)) | any(size(r)~=size(b))), error('R, G, and B must all be the same size.') end rgb = [r(:), g(:), b(:)]; a = zeros(size(r)); end T = inv([1.0 0.956 0.621; 1.0 -0.272 -0.647; 1.0 -1.106 1.703]); if isa(rgb, 'uint8') a(:) = uint8(double(rgb)*T(1,:)'); else a(:) = rgb*T(1,:)'; end if ((nargin==1) & (~threeD)), % rgb2gray(MAP) if isa(a, 'uint8') a = double(a)/255; end a = [a,a,a]; end T = inv([1 0.956 0.621; 1 -0.272 -0.647; 1 -1.106 1.703]) T = 0.2989 0.5870 0.1140 0.5959 -0.2744 -0.3216 0.2115 -0.5229 0.3114 T(1,:) ans = 0.2989 0.5870 0.1140
Maintained by John Loomis, last updated 27 May 1998