Home > . > set_col_vec.m

set_col_vec

PURPOSE ^

'set_col_vec': sets the color code for vectors depending on a scalar vec_C and parameters given by the struct colcode

SYNOPSIS ^

function [colorlist,col_vec,colcode_out]=set_col_vec(colcode,vec_C)

DESCRIPTION ^

'set_col_vec': sets the color code for vectors depending on a scalar vec_C and parameters given by the struct colcode
function [colorlist,col_vec,minC,colcode1,colcode2,maxC]=colvec(colcode,vec_C)
OUTPUT
colorlist(nb,3); %list of nb colors
col_vec, size=[length(vec_C),3)];%list of color indices corresponding to vec_C
minC, maxC: min and max of vec_C
colcode1, colcode2: absolute threshold in vec_C corresponding to colcode.colcode1 and colcode.colcode2
INPUT
 colcode: struture setting the colorcode for vectors
 colcode.CName: 'ima_cor','black','white',...
 colcode.ColorCode ='black', 'white', 'rgb','brg', '64 colors'
 colcode.FixedCbounds =0; thresholds scaling relative to min and max, =1 fixed thresholds
 colcode.MinC; min 
 colcode.MaxC; max
 colcode.colcode1: first threshold for rgb, relative to min (0) and max (1)
 colcode.colcode2: second threshold for rgb, relative to min (0) and max (1), 
 rmq: we need min <= colcode1 <= colcode2 <= max, otherwise
 colcode1 and colcode2 are adjusted to the bounds
 vec_C: matlab vector representing the scalar setting the color

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %'set_col_vec': sets the color code for vectors depending on a scalar vec_C and parameters given by the struct colcode
0002 %function [colorlist,col_vec,minC,colcode1,colcode2,maxC]=colvec(colcode,vec_C)
0003 %OUTPUT
0004 %colorlist(nb,3); %list of nb colors
0005 %col_vec, size=[length(vec_C),3)];%list of color indices corresponding to vec_C
0006 %minC, maxC: min and max of vec_C
0007 %colcode1, colcode2: absolute threshold in vec_C corresponding to colcode.colcode1 and colcode.colcode2
0008 %INPUT
0009 % colcode: struture setting the colorcode for vectors
0010             % colcode.CName: 'ima_cor','black','white',...
0011             % colcode.ColorCode ='black', 'white', 'rgb','brg', '64 colors'
0012             % colcode.FixedCbounds =0; thresholds scaling relative to min and max, =1 fixed thresholds
0013             % colcode.MinC; min
0014             % colcode.MaxC; max
0015             % colcode.colcode1: first threshold for rgb, relative to min (0) and max (1)
0016             % colcode.colcode2: second threshold for rgb, relative to min (0) and max (1),
0017             % rmq: we need min <= colcode1 <= colcode2 <= max, otherwise
0018             % colcode1 and colcode2 are adjusted to the bounds
0019 % vec_C: matlab vector representing the scalar setting the color
0020 function [colorlist,col_vec,colcode_out]=set_col_vec(colcode,vec_C)
0021 
0022 col_vec=[]; 
0023 colcode_out=colcode;%default
0024 if isempty(vec_C) || ~isnumeric(vec_C)
0025     colorlist=[0 0 1]; %blue
0026     return
0027 end
0028 if (isfield(colcode,'FixedCbounds') && isequal(colcode.FixedCbounds,1))
0029     minC=colcode.MinC;
0030     maxC=colcode.MaxC;
0031 else
0032     minC=min(vec_C);
0033     maxC=max(vec_C);
0034 end
0035 
0036 %default input parameters
0037 if ~isstruct(colcode),colcode=[];end;
0038 if ~isfield(colcode,'ColorCode') || isempty(colcode.ColorCode)
0039     colorlist=[0 0 1]; %blue
0040     return
0041 end
0042 if  isfield(colcode,'colcode1')
0043     colcode1=minC+colcode.colcode1*(maxC-minC);
0044 else
0045     colcode1=minC+(maxC-minC)/3;%default
0046 end
0047 if isfield(colcode,'colcode2')
0048     colcode2=minC+colcode.colcode2*(maxC-minC);
0049 else
0050     colcode2=minC+2*(maxC-minC)/3;%default
0051 end
0052 colcode_out.MinC=minC;
0053 colcode_out.MaxC=maxC;
0054 
0055 if strcmp(colcode.ColorCode,'black')
0056     colorlist(1,:)=[0 0 0];%black
0057     col_vec=ones(size(vec_C));%all vectors at color#1
0058 elseif strcmp(colcode.ColorCode,'white')
0059     colorlist(1,:)=[1 1 1];%white
0060     col_vec=ones(size(vec_C));%all vectors at color#1
0061 elseif strcmp(colcode.ColorCode,'rgb')|| strcmp(colcode.ColorCode,'bgr')% 3 color representation
0062     ind1=find(vec_C < colcode1); % =1 for red vectors
0063     ind_green=find((vec_C >= colcode1) & (vec_C < colcode2));% =1 for green vectors
0064     ind3=find(vec_C >= colcode2);% =1 for blue vectors
0065     colorlist(2,:)=[0 1 0];%green
0066     col_vec(ind1)=1;
0067     col_vec(ind_green)=2;
0068     col_vec(ind3)=3;
0069     if strcmp(colcode.ColorCode,'rgb')
0070         colorlist(1,:)=[1 0 0];%red
0071         colorlist(3,:)=[0 0 1];%blue
0072     else
0073         colorlist(1,:)=[0 0 1];%blue
0074         colorlist(3,:)=[1 0 0];%red
0075     end
0076 else
0077     colorjet=jet;% ususal colormap from blue to red
0078     sizlist=size(colorjet);
0079     indsel=ceil((sizlist(1)/64)*(1:64));
0080     colorlist(:,1)=colorjet(indsel,1);
0081     colorlist(:,2)=colorjet(indsel,2);
0082     colorlist(:,3)=colorjet(indsel,3);
0083     sizlist=size(colorlist);
0084     nblevel=sizlist(1);
0085     col2_1=maxC-minC;
0086     col_vec=1+floor(nblevel*(vec_C-minC)/col2_1);
0087     col_vec=col_vec.*(col_vec<= nblevel)+nblevel*(col_vec >nblevel);% take color #nblevel at saturation
0088     col_vec=col_vec.*(col_vec>= 1)+  (col_vec <1);% take color #1 for values below 1
0089 end

Generated on Fri 13-Nov-2009 11:17:03 by m2html © 2003