[8] | 1 | %'set_col_vec': sets the color code for vectors depending on a scalar vec_C and parameters given by the struct colcode
|
---|
[313] | 2 | %function [colorlist,col_vec,minC,ColCode1,ColCode2,maxC]=colvec(colcode,vec_C)
|
---|
[8] | 3 | %OUTPUT
|
---|
| 4 | %colorlist(nb,3); %list of nb colors
|
---|
| 5 | %col_vec, size=[length(vec_C),3)];%list of color indices corresponding to vec_C
|
---|
| 6 | %minC, maxC: min and max of vec_C
|
---|
[313] | 7 | %ColCode1, ColCode2: absolute threshold in vec_C corresponding to colcode.ColCode1 and colcode.ColCode2
|
---|
[8] | 8 | %INPUT
|
---|
| 9 | % colcode: struture setting the colorcode for vectors
|
---|
| 10 | % colcode.CName: 'ima_cor','black','white',...
|
---|
[313] | 11 | % colcode.ListColorCode ='black', 'white', 'rgb','brg', '64 colors'
|
---|
[315] | 12 | % colcode.CheckFixVecColor =0; thresholds scaling relative to min and max, =1 fixed thresholds
|
---|
| 13 | % colcode.MinVec; min
|
---|
| 14 | % colcode.MaxVec; max
|
---|
[313] | 15 | % colcode.ColCode1: first threshold for rgb, relative to min (0) and max (1)
|
---|
| 16 | % colcode.ColCode2: second threshold for rgb, relative to min (0) and max (1),
|
---|
| 17 | % rmq: we need min <= ColCode1 <= ColCode2 <= max, otherwise
|
---|
| 18 | % ColCode1 and ColCode2 are adjusted to the bounds
|
---|
[8] | 19 | % vec_C: matlab vector representing the scalar setting the color
|
---|
| 20 | function [colorlist,col_vec,colcode_out]=set_col_vec(colcode,vec_C)
|
---|
| 21 | col_vec=[];
|
---|
| 22 | colcode_out=colcode;%default
|
---|
| 23 | if isempty(vec_C) || ~isnumeric(vec_C)
|
---|
| 24 | colorlist=[0 0 1]; %blue
|
---|
[102] | 25 | col_vec=ones(size(vec_C));
|
---|
[8] | 26 | return
|
---|
| 27 | end
|
---|
[313] | 28 | if (isfield(colcode,'CheckFixVecColor') && isequal(colcode.CheckFixVecColor,1))
|
---|
| 29 | minC=colcode.MinVec;
|
---|
| 30 | maxC=colcode.MaxVec;
|
---|
[8] | 31 | else
|
---|
| 32 | minC=min(vec_C);
|
---|
| 33 | maxC=max(vec_C);
|
---|
| 34 | end
|
---|
| 35 |
|
---|
| 36 | %default input parameters
|
---|
| 37 | if ~isstruct(colcode),colcode=[];end;
|
---|
[313] | 38 | if ~isfield(colcode,'ListColorCode') || isempty(colcode.ListColorCode)
|
---|
[8] | 39 | colorlist=[0 0 1]; %blue
|
---|
[102] | 40 | col_vec=ones(size(vec_C));
|
---|
[8] | 41 | return
|
---|
| 42 | end
|
---|
[313] | 43 | if isfield(colcode,'ColCode1')
|
---|
| 44 | ColCode1=minC+colcode.ColCode1*(maxC-minC);
|
---|
[8] | 45 | else
|
---|
[313] | 46 | ColCode1=minC+(maxC-minC)/3;%default
|
---|
[8] | 47 | end
|
---|
[313] | 48 | if isfield(colcode,'ColCode2')
|
---|
| 49 | ColCode2=minC+colcode.ColCode2*(maxC-minC);
|
---|
[8] | 50 | else
|
---|
[313] | 51 | ColCode2=minC+2*(maxC-minC)/3;%default
|
---|
[8] | 52 | end
|
---|
| 53 | colcode_out.MinC=minC;
|
---|
| 54 | colcode_out.MaxC=maxC;
|
---|
[313] | 55 | if strcmp(colcode.ListColorCode,'black')
|
---|
[8] | 56 | colorlist(1,:)=[0 0 0];%black
|
---|
| 57 | col_vec=ones(size(vec_C));%all vectors at color#1
|
---|
[313] | 58 | elseif strcmp(colcode.ListColorCode,'white')
|
---|
[8] | 59 | colorlist(1,:)=[1 1 1];%white
|
---|
| 60 | col_vec=ones(size(vec_C));%all vectors at color#1
|
---|
[313] | 61 | elseif strcmp(colcode.ListColorCode,'rgb')|| strcmp(colcode.ListColorCode,'bgr')% 3 color representation
|
---|
[315] | 62 | % ind1=find(vec_C < ColCode1); % =1 for red vectors
|
---|
[313] | 63 | ind_green=find((vec_C >= ColCode1) & (vec_C < ColCode2));% =1 for green vectors
|
---|
[315] | 64 | % ind3=find(vec_C >= ColCode2);% =1 for blue vectors
|
---|
[8] | 65 | colorlist(2,:)=[0 1 0];%green
|
---|
[315] | 66 | col_vec(vec_C < ColCode1)=1;
|
---|
[8] | 67 | col_vec(ind_green)=2;
|
---|
[315] | 68 | col_vec(vec_C >= ColCode2)=3;
|
---|
[313] | 69 | if strcmp(colcode.ListColorCode,'rgb')
|
---|
[8] | 70 | colorlist(1,:)=[1 0 0];%red
|
---|
| 71 | colorlist(3,:)=[0 0 1];%blue
|
---|
| 72 | else
|
---|
| 73 | colorlist(1,:)=[0 0 1];%blue
|
---|
| 74 | colorlist(3,:)=[1 0 0];%red
|
---|
| 75 | end
|
---|
| 76 | else
|
---|
| 77 | colorjet=jet;% ususal colormap from blue to red
|
---|
| 78 | sizlist=size(colorjet);
|
---|
| 79 | indsel=ceil((sizlist(1)/64)*(1:64));
|
---|
| 80 | colorlist(:,1)=colorjet(indsel,1);
|
---|
| 81 | colorlist(:,2)=colorjet(indsel,2);
|
---|
| 82 | colorlist(:,3)=colorjet(indsel,3);
|
---|
| 83 | sizlist=size(colorlist);
|
---|
| 84 | nblevel=sizlist(1);
|
---|
| 85 | col2_1=maxC-minC;
|
---|
| 86 | col_vec=1+floor(nblevel*(vec_C-minC)/col2_1);
|
---|
| 87 | col_vec=col_vec.*(col_vec<= nblevel)+nblevel*(col_vec >nblevel);% take color #nblevel at saturation
|
---|
| 88 | col_vec=col_vec.*(col_vec>= 1)+ (col_vec <1);% take color #1 for values below 1
|
---|
| 89 | end
|
---|