The usage of "colorspace( )"

8 views (last 30 days)
x.d
x.d on 1 Apr 2012
I have used the function “colorspace( )” which can be found in the page of " http://www.mathworks.com/matlabcentral/fileexchange/28790-colorspace-transformations " as follows:
rgb = imread('peppers.png');
C = makecform('srgb2lab');
lab = applycform(rgb,C);
lab_2 = colorspace('lab<-rgb', rgb);
lab_3 = lab2uint8(lab_2);
I was surprised that the values in lab and lab_3 were quite different. I want to know the mistake in my code or my logical.
Thanks a lot.

Answers (1)

Image Analyst
Image Analyst on 1 Apr 2012
I don't have that File Exchange file and didn't try it. Maybe it wants double. Try this code:
clc;
rgb = imread('peppers.png');
C = makecform('srgb2lab');
lab = applycform(double(rgb)/255,C);
lChannel = lab(:,:,1);
aChannel = lab(:,:,2);
bChannel = lab(:,:,3);
lab_2_uint8 = colorspace('lab<-rgb', rgb);
lChannel2u = lab_2(:,:,1);
aChannel2u = lab_2(:,:,2);
bChannel2u = lab_2(:,:,3);
lab_2_double = colorspace('lab<-rgb', double(rgb)/255);
lChannel2d = lab_2(:,:,1);
aChannel2d = lab_2(:,:,2);
bChannel2d = lab_2(:,:,3);
% Now compute differences between them
lDiffu = lChannel2u - lChannel;
aDiffu = aChannel2u - aChannel;
bDiffu = bChannel2u - bChannel;
lDiffd = lChannel2d - lChannel;
aDiffd = aChannel2d - aChannel;
bDiffd = bChannel2d - bChannel;
% lab_3 = lab2uint8(lab_2);
Let me know if that reveals anything.
  2 Comments
x.d
x.d on 4 Apr 2012
Thanks for your attention!
I have tested the above codes, but there is not essential differences in
lab_2_double = colorspace('lab<-rgb', double(rgb)/255);
lab_2_uint8 = colorspace('lab<-rgb', rgb);
as the "colorspace()" has Input parsing codes as follows:
%%%%%%%%%%% Input parsing %%%%%%%%%%%
if nargin < 2, error('Not enough input arguments.'); end
[SrcSpace,DestSpace] = parse(Conversion);
if nargin == 2
Image = varargin{1};
elseif nargin >= 3
Image = cat(3,varargin{:});
else
error('Invalid number of input arguments.');
end
FlipDims = (size(Image,3) == 1);
if FlipDims, Image = permute(Image,[1,3,2]); end
if ~isa(Image,'double'), Image = double(Image)/255; end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
What's more, lDiffu is not an all-zero matrix at last.
max(max(aDiffd)) = 3.4091;
min(min(aDiffd)) = -4.8193;
Image Analyst
Image Analyst on 4 Apr 2012
Since my demo code worked and colorspace() isn't, I suggest you contact the author of colorspace().

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!