Reputation: 1513
I am not sure how to approach this problem. I am trying to find good resources on how to customize a colormap (without using colormap editor) to set your colors and your boundaries for an image in Matlab. I have managed to do it using the colormap editor but I want to figure out how to do it manually.
I am trying to make a colormap that ranges between 0 and 127. The boundaries would be:
0 to 64 is black (0) to white (64)
65 to 127 is blue (65) to red (127)
Can someone give me some advice on how to manually make these changes to the colormap? A good resource would also be useful.
Thanks.
Upvotes: 1
Views: 1634
Reputation: 20915
I suggest using linspace
. It helps you creating a uniform distribution of numbers in some range.
blackToWhite = repmat(linspace(0,1,66),3,1)' ;
l1 = linspace(0,1,127-65+1);
blueToRed = [flipud(l1(:)) zeros(size(l1(:))) l1(:) ];
cmap = [blackToWhite; blueToRed];
The idea is to interpolate [1 0 0]
up to [0 0 1]
; Each of the color channels, red green and blue is interpolated on its own.
Red -> 1 ... 0
Green -> 0 ... 0
Blue -> 0 ... 1
So I generated l1
both for the red and the blue channel, but flipped it in one of them.
Upvotes: 2