Reputation: 121
I am trying to plot a 2D composite image in gnuplot. I have three different channels, and I would like each to be displayed in a different color. I would like to be able to pick the color, rather than using e.g. RGB. I want the output to look like this. Right now, I have my image data saved in a text file with columns X, Y, Channel 1, Channel 2, Channel 3
I can plot an RGB composite image using
file = "data.txt"
plot file using 1:2:3:4:5 with rgbimage
I can make a composite image "by hand" in the following way
# define channel colors by RGB values (normalized to 1)
array c1 = [0, 1, 1] # cyan
array c2 = [1, 0, 1] # magenta
array c3 = [1, 1, 0] # yellow
# define output colors for three channels
r(x, y, z) = c1[1] * x + c2[1] * y + c3[1] * z
g(x, y, z) = c1[2] * x + c2[2] * y + c3[2] * z
b(x, y, z) = c1[3] * x + c2[3] * y + c3[3] * z
plot data using 1:2:(r($3,$4,$5)):(g($3,$4,$5)):(b($3,$4,$5)) with rgbimage
Is there a built in gnuplot way to do this?
Upvotes: 1
Views: 76
Reputation: 15118
There is a builtin CMY color model for the palette, but I don't think that helps for this purpose. I can propose an alternative method that is slightly simpler than what you show. It works specifically for CMY, whereas the scheme you show could be adapted for other sets of colors. So honestly I think you may be better off with what you have.
# Assume input CMY values are in the range [0:1]
# We will convert to RGB values also in the range [0:1]
# Since color component values by default run from 0-255 we must
# first reset that range.
#
set rgbmax 1.0 # this command introduced in version 5.2.1
plot data using 1:2:(1.-$3):(1.-$4):(1.-$5) with rgbimage
Upvotes: 2