Page 1 of 1

RGB to grayscale with red=0,blue=255

Posted: 2012-04-03T10:54:43-07:00
by anatuss
Hi,
I've got an image generated from a matrix with red-white-blue gradient. When converting into grayscale with any approach I found so far blue and red become the same gray since the values are symmetric around zero. I would like to convert the colorscale as follows: blue to black, white to black!50 and red to white.

Could you help me with this? Thanks in advance,
anatuss

Re: RGB to grayscale with red=0,blue=255

Posted: 2012-04-03T11:16:28-07:00
by fmw42
blue to black, white to black!50 and red to white

What do you mean by white to black!50?


Do you really mean green to 50% gray? If so then try the following, which sets each r,g,b channel to the desired value:

convert logo: \
-channel r -evaluate set 100% +channel \
-channel g -evaluate set 50% +channel \
-channel b -evaluate set 0% +channel \
logo_tmp.png


identify -verbose logo_tmp.png
...
Channel statistics:
Red:
min: 255 (1)
max: 255 (1)
mean: 255 (1)
standard deviation: 0 (0)
kurtosis: 0
skewness: 0
Green:
min: 128 (0.501961)
max: 128 (0.501961)
mean: 128 (0.501961)
standard deviation: 0 (0)
kurtosis: 0
skewness: 0
Blue:
min: 0 (0)
max: 0 (0)
mean: 0 (0)
standard deviation: 0 (0)
kurtosis: 0
skewness: 0


If I misunderstand, please clarify further.


Perhaps you could provide a link to your image so that we can see what you have and you could explain what needs changing where.

Are you trying to change hues rather than channels?

Re: RGB to grayscale with red=0,blue=255

Posted: 2012-04-04T06:41:50-07:00
by anatuss
Hi,
I'd like to convert Image into Image.
There is no green channel, at least it's symmetric for red and blue, and therefore not suited.

Re: RGB to grayscale with red=0,blue=255

Posted: 2012-04-04T07:44:58-07:00
by whugemann
I looks like calculations based on the RGB co-ordnates are not well suited for the desired conversion. You shoud rather convert the image into the HSB colorspace and base the conversion to greyscale on its components. To me it looks like that in your original image, you move from 0° on the circumference of the color circle to its centre and from there to 240° on the circumference, at least you're doing something very similar to that.

Re: RGB to grayscale with red=0,blue=255

Posted: 2012-04-04T10:39:17-07:00
by fmw42
I don't understand, your output image is smaller than your input image. So why not just create a grayscale gradient between the values you want?

Re: RGB to grayscale with red=0,blue=255

Posted: 2012-04-04T17:56:24-07:00
by henrywho
Not really sure what you wanna do, but the following looks similar to your sample output:

Code: Select all

convert.exe k1s1mb.gif -gamma 1.6 -color-matrix "1 -0.5 0 1 -0.5 0 1 -0.5 0" -gamma 0.625 -quality 05 k1s1mb_gray.png
Adjust the pair of gamma values till it looks good for you.