RGB to grayscale with red=0,blue=255

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
anatuss
Posts: 2
Joined: 2012-04-03T10:17:18-07:00
Authentication code: 8675308

RGB to grayscale with red=0,blue=255

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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?
anatuss
Posts: 2
Joined: 2012-04-03T10:17:18-07:00
Authentication code: 8675308

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

Post 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.
User avatar
whugemann
Posts: 289
Joined: 2011-03-28T07:11:31-07:00
Authentication code: 8675308
Location: Münster, Germany 52°N,7.6°E

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

Post 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.
Wolfgang Hugemann
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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?
henrywho
Posts: 188
Joined: 2011-08-17T06:46:40-07:00
Authentication code: 8675308

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

Post 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.
Post Reply