% colorComp - display RGB and HSV color components % % Usage: % colorComp(rgbhsv,range,flipSel) % % % Arguments: (optional) % rgbhsv - select range color mode % 1 - RGB ; 2 - HSV % range - 3 x 2 matrix specifying the range of component % flipSel - show the range from [a,b] and [b,a] on 'flipSel' component % 2 - green or saturation component flipped % 3 - blue or value component flipped % anything else - nothing flipped % % Output: % nil % % Example: % colorComp(1,[0 1;1 0;0.3 1]); % RGB mode,Red 0-1,Green 1-0,Blue 0.3-1 % colorComp(2,[0 1;1 0;0.3 1]); % HSV mode,Hue 0-1,Sat. 1-0,Value 0.3-1 % colorComp; % default, HSV [0-1,1,1] % % Author: % Tzu Yen Wong % wongt AT csse DOT uwa DOT edu DOT au % Department of Computer Science & Software Engineering % The University of Western Australia % % Oct 2003 % June 2004 change email address to fight SPAM!!! %1234567890123456789012345678901234567890123456789012345678901234567890123456789 function colorComp(rgbhsv,range,flipSel) if nargin <3, flipSel = 0; end if nargin >= 2, if size(range)==[3,2] if rgbhsv == 2, % 2 for hsv hsvColor = range2color(range,flipSel); rgbColor=uint8(hsv2rgb(hsvColor)*255); red='';green='';blue=''; hue=sprintf('[%.1f,%.1f]',range(1,1),range(1,2)); sat=sprintf('[%.1f,%.1f]',range(2,1),range(2,2)); val=sprintf('[%.1f,%.1f]',range(3,1),range(3,2)); elseif rgbhsv == 1, % 1 for rgb rgbColor = range2color(range,flipSel); hsvColor=rgb2hsv(rgbColor); hue='';sat='';val=''; red =sprintf('[%.1f,%.1f]',range(1,1),range(1,2)); green=sprintf('[%.1f,%.1f]',range(2,1),range(2,2)); blue =sprintf('[%.1f,%.1f]',range(3,1),range(3,2)); else disp('invalid choice, default value used'); [range,hsvColor,rgbColor,red,green,blue,hue,sat,val]=dispDefault; end else disp('invalid range, size should be [3,2], default value used'); [range,hsvColor,rgbColor,red,green,blue,hue,sat,val]=dispDefault; end else [range,hsvColor,rgbColor,red,green,blue,hue,sat,val]=dispDefault; end figure; subplot(7,1,1); imshow(rgbColor) title('Display RGB and HSV color components') ylabel('Full Color','ROTATION',0,'HorizontalAlignment','right') subplot(7,1,2); imshow(rgbColor(:,:,1)) ylabel(sprintf('Red %s',red) ,'ROTATION',0,... 'HorizontalAlignment','right','BackgroundColor',[1 0 0]); subplot(7,1,3); imshow(rgbColor(:,:,2)) ylabel(sprintf('Green %s',green),'ROTATION',0,... 'HorizontalAlignment','right','BackgroundColor',[0 1 0]); subplot(7,1,4); imshow(rgbColor(:,:,3)) ylabel(sprintf('Blue %s',blue) ,'ROTATION',0,... 'HorizontalAlignment','right','BackgroundColor',[0 0 1]); subplot(7,1,5); imshow(hsvColor(:,:,1)) ylabel(sprintf('Hue %s', hue) ,'ROTATION',0,... 'HorizontalAlignment','right') subplot(7,1,6); imshow(hsvColor(:,:,2)) ylabel(sprintf('Saturation %s', sat),'ROTATION',0,... 'HorizontalAlignment','right') subplot(7,1,7); imshow(hsvColor(:,:,3)) ylabel(sprintf('Value %s',val) ,'ROTATION',0,... 'HorizontalAlignment','right') truesize pixval on % function to composite color image rgb/hsv components from given range function whateverColor = range2color(range,flip23) r1=range(1,:); r2=range(2,:); r3=range(3,:); h=40; w=360; Color=ones(h,w,3); if r1(1)~=r1(2) Color(:,:,1)=ones(1,h)'*... [r1(1)+(r1(2)-r1(1))/w:(r1(2)-r1(1))/w:r1(2)]; else Color(:,:,1)=r1(1); end if r2(1)~=r2(2) Color(:,:,2)=ones(1,h)'*... [r2(1)+(r2(2)-r2(1))/w:(r2(2)-r2(1))/w:r2(2)]; else Color(:,:,2)=r2(1); end if r3(1)~=r3(2) Color(:,:,3)=ones(1,h)'*... [r3(1)+(r3(2)-r3(1))/w:(r3(2)-r3(1))/w:r3(2)]; else Color(:,:,3)=r3(1); end whateverColor(:,:,1)=[Color(:,:,1) Color(:,:,1)]; if flip23==2, ColorF2 = fliplr(Color(:,:,2)); whateverColor(:,:,2)=[Color(:,:,2) ColorF2]; whateverColor(:,:,3)=[Color(:,:,3) Color(:,:,3)]; elseif flip23==3, ColorF3 = fliplr(Color(:,:,3)); whateverColor(:,:,3)=[Color(:,:,3) ColorF3]; whateverColor(:,:,2)=[Color(:,:,2) Color(:,:,2)]; else whateverColor(:,:,2)=[Color(:,:,2) Color(:,:,2)]; whateverColor(:,:,3)=[Color(:,:,3) Color(:,:,3)]; end return % function to load all default values if arguments are invalid function [range,hsvColor,rgbColor,red,green,blue,hue,sat,val]... =dispDefault range = [0 1; 1 1; 1 1]; hsvColor = range2color(range,2); rgbColor=uint8(hsv2rgb(hsvColor)*255); red='';green='';blue=''; hue=sprintf('[%.1f,%.1f]',range(1,1),range(1,2)); sat=sprintf('[%.1f,%.1f]',range(2,1),range(2,2)); val=sprintf('[%.1f,%.1f]',range(3,1),range(3,2)); return