Skip to content

Commit fdd33ef

Browse files
committed
add blue-white-red colormap
1 parent 8e383b3 commit fdd33ef

File tree

3 files changed

+78
-9
lines changed

3 files changed

+78
-9
lines changed

ImageM/+imagem/+actions/+view/SetImageColorMap.m

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,39 +73,42 @@ function run(obj, frame) %#ok<INUSD>
7373

7474
% create the appropriate LUT array depending on LUT name and on
7575
% number of levels
76-
if strcmp(name, 'inverted')
76+
if strcmpi(name, 'inverted')
7777
lut = repmat(((nValues-1):-1:0)', 1, 3) / (nValues-1);
7878

79-
elseif strcmp(name, 'blue-gray-red')
79+
elseif strcmpi(name, 'blue-gray-red')
8080
lut = gray(nValues);
8181
lut(1,:) = [0 0 1];
8282
lut(end,:) = [1 0 0];
8383

84-
elseif strcmp(name, 'colorcube')
84+
elseif strcmpi(name, 'blue-white-red')
85+
lut = imagem.util.color.blue2White2Red(nValues);
86+
87+
elseif strcmpi(name, 'colorcube')
8588
map = colorcube(double(nValues) + 2);
8689
lut = [0 0 0; map(sum(map==0, 2)~=3 & sum(map==1, 2)~=3, :)];
8790

88-
elseif strcmp(name, 'red')
91+
elseif strcmpi(name, 'red')
8992
lut = gray(nValues);
9093
lut(:, 2:3) = 0;
9194

92-
elseif strcmp(name, 'green')
95+
elseif strcmpi(name, 'green')
9396
lut = gray(nValues);
9497
lut(:, [1 3]) = 0;
9598

96-
elseif strcmp(name, 'blue')
99+
elseif strcmpi(name, 'blue')
97100
lut = gray(nValues);
98101
lut(:, 1:2) = 0;
99102

100-
elseif strcmp(name, 'yellow')
103+
elseif strcmpi(name, 'yellow')
101104
lut = gray(nValues);
102105
lut(:, 3) = 0;
103106

104-
elseif strcmp(name, 'cyan')
107+
elseif strcmpi(name, 'cyan')
105108
lut = gray(nValues);
106109
lut(:, 1) = 0;
107110

108-
elseif strcmp(name, 'magenta')
111+
elseif strcmpi(name, 'magenta')
109112
lut = gray(nValues);
110113
lut(:, 2) = 0;
111114

ImageM/+imagem/+gui/FrameMenuBuilder.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ function buildImageFrameMenu(obj, hf)
200200
addMenuItem(obj, lutMenu, SetImageColorMap('colorcube'), 'Color Cube');
201201
addMenuItem(obj, lutMenu, SetImageColorMap('prism'), 'Prism');
202202
addMenuItem(obj, lutMenu, SetImageColorMap('jet'), 'Jet');
203+
addMenuItem(obj, lutMenu, SetImageColorMap('blue-white-red'), 'Blue-White-Red');
203204

204205
matlabLutMenu = addMenu(obj, lutMenu, 'Matlab''s');
205206
addMenuItem(obj, matlabLutMenu, SetImageColorMap('hot'), 'Hot');
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
function newmap = blue2White2Red(m)
2+
%BLUE2WHITE2RED Blue to white to red color map.
3+
%
4+
% blue2White2Red(M)
5+
% Returns an M-by-3 matrix containing a blue to white to red colormap,
6+
% with white corresponding to the CAXIS value closest to zero.
7+
% This colormap is most useful for images and surface plots with positive
8+
% and negative values.
9+
%
10+
% Example
11+
% figure
12+
% surf(peaks)
13+
% colormap(bluewhitered)
14+
% axis tight
15+
%
16+
% See also HSV, HOT, COOL, BONE, COPPER, PINK, FLAG,
17+
% COLORMAP, RGBPLOT.
18+
19+
% default number of values
20+
if nargin < 1
21+
m = 256;
22+
end
23+
24+
% define color "waypoints"
25+
bottom = [0 0 0.5];
26+
botmiddle = [0 0.5 1];
27+
middle = [1 1 1];
28+
topmiddle = [1 0 0];
29+
top = [0.5 0 0];
30+
31+
% It has both negative and positive
32+
% Find ratio of negative to positive
33+
ratio = .5;
34+
neglen = round(m * ratio);
35+
poslen = m - neglen;
36+
37+
38+
% Process colors for negative part
39+
new = [bottom; botmiddle; middle];
40+
len = length(new);
41+
oldsteps = linspace(0, 1, len);
42+
newsteps = linspace(0, 1, neglen);
43+
newmap1 = zeros(neglen, 3);
44+
45+
for i = 1:3
46+
% Interpolate over RGB spaces of colormap
47+
newmap1(:,i) = min(max(interp1(oldsteps, new(:,i), newsteps), 0), 1)';
48+
end
49+
50+
51+
% Process colors for positive part
52+
new = [middle; topmiddle; top];
53+
len = length(new);
54+
oldsteps = linspace(0, 1, len);
55+
newsteps = linspace(0, 1, poslen);
56+
newmap = zeros(poslen, 3);
57+
58+
for i = 1:3
59+
% Interpolate over RGB spaces of colormap
60+
newmap(:,i) = min(max(interp1(oldsteps, new(:,i), newsteps), 0), 1)';
61+
end
62+
63+
64+
% concatenate
65+
newmap = [newmap1; newmap];

0 commit comments

Comments
 (0)