% phasecolor - display of using color to represent phase angle % % Usage: % [pc,rgbColor,rgbCircle]=phasecolor(rangeSelect,angle) % % matching 360 deg of angle to 0-1 and use it as Hue. % Both Saturation and Values are full (1). % % Arguments: % rangeSelect - 0, range = [0,360] (default) % 1, range = [-180,180] % angle - optional, be pointed out in the graph % Output: % pc - 4 x 360 matrix % - 1st row is the angle (1-360) % - 2nd-4th rows are the R,G,B color value(0-255) % rgbColor - image matrix of the lower output % rgbCircle - image matrix of the circle output % % 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 [pc,rgbColor,rgbCircle]=phasecolor(rangeSelect,angle) hsvColor=ones(40,360,3); hsvColor(:,:,1)=ones(1,40)'*[1/360:1/360:1]; hsvColor(:,:,2:3)=1; titleText1 = 'Representation of phase angle using hsv color'; titleText2 = 'Range of angle in degree ='; if nargin >0, if rangeSelect == 1, % if range is [-180,180] hsvColor2(:,181:360,:)=hsvColor(:,1:180,:); hsvColor2(:,1:180,:) =hsvColor(:,181:360,:); hsvColor = hsvColor2; titleText = sprintf('%s\n%s %s',titleText1,titleText2,'[-180,180]'); else rangeSelect = 0; titleText = sprintf('%s\n%s %s',titleText1,titleText2,'[0,360]'); end else rangeSelect = 0; titleText = sprintf('%s\n%s %s',titleText1,titleText2,'[0,360]'); end if nargin >1; while angle<=0; angle = angle+360; end while angle>360; angle = angle-360; end hsvColor(25:40,:,3)=0; hsvColor(25:40,angle,3)=1; hsvColor(25:40,angle,2)=0; if rangeSelect == 1, % if range is [-180,180] if angle >180, angle = angle-360; end end titleText = sprintf('%s \nAngle of interest in degree = %d',... titleText,angle); end % To make the column index equal angle in degree % RGB color range: 0-255 rgbColor=uint8(hsv2rgb(hsvColor)*255); figNo = figure; clf; subplot(2,1,2); subplot('position',[.01 .05 .98 .35]) imshow([rgbColor rgbColor]) % show 0-720 deg xlabel('angle(degree)'); pixval on axis on pc(:,2:4) = rgbColor(1,:,:); pc=double(pc); pc(1:360,1) = [1:360.0]'; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% r = 150; hsvCircle = ones(2*r+1,2*r+1,3); xCoord = ones(2*r+1,1)*[1:2*r+1] - (r+1); yCoord = flipud([1:2*r+1]'*ones(1,2*r+1)- (r+1)); circle = xCoord.^2+yCoord.^2 < (r*.8)^2; circle(:,:,2)=circle; circle(:,:,3)=circle(:,:,1); % get angle in degree warning off MATLAB:divideByZero; hsvCircle(:,:,1)=atan(yCoord./xCoord)*180/pi; % make angle into range [0,360] instead of [-180,180] hsvCircle(:,1:r,1) = hsvCircle(:,1:r,1) + 180; % 2nd, 3rd Quadrant hsvCircle(r+1:end,r+1:end,1) = hsvCircle(r+1:end,r+1:end,1) + 360; % 4th Quadrant % make angle into range [0,1] for hsv color hsvCircle(:,:,1) = hsvCircle(:,:,1)/360; if rangeSelect == 1, % if range is [-180,180] hsvCircle(:,:,1) = flipud(fliplr(hsvCircle(:,:,1))); hsvCircle(:,:,2) = flipud(fliplr(hsvCircle(:,:,2))); hsvCircle(:,:,3) = flipud(fliplr(hsvCircle(:,:,3))); end rgbCircle=hsv2rgb(hsvCircle); rgbCircle=rgbCircle.*circle; rgbCircle=uint8(rgbCircle*255); figure(figNo), subplot(2,1,1) subplot('position',[.25 .4 .5 .5]) imshow(rgbCircle) title(titleText); hold on, if nargin >1, angleRad=angle*pi/180; % sin and cosine work in Rad x1=r*cos(angleRad); y1=r*sin(angleRad); x2=r*.8*cos(angleRad); y2=r*.8*sin(angleRad); % shift origin to (r+1), axis ij, flip y-coord X = [x1,x2]+(r+1); Y = (r+1)-[y1,y2]; line(X,Y) axis ij end truesize hold off warning on