Page 2 of 2

Re: Replace specific color of image

Posted: 2017-10-09T01:08:10-07:00
by mefuzar
Hi,

I am trying to achieve something very similar to the problem described in this post, i.e: change colour of an image with another colour but the problem is that I would like to change it with white.

This is not grayscale as I would like to set specific RGB which will transition to white.

for example, I have an image of 4 pixels:
(0,0,0)=BLACK
(32,0,0)=VERY VERY LIGHT RED
(64,0,0)=VERY LIGHT RED
(128,0,0)=LIGHT RED

so the LIGHT RED will be changed to white (255,255,255) , VERY LIGHT RED to GREY and VERY VERY LIGHT RED to LIGHT GREY.

It is a little bit hard for me to explain, for example, if I have a source picture of a red gradient, starts with BLACK and finishes at (128,0,0)
i will be able to set (128,0,0) as: (255,255,255) and get a BLACK to WHITE gradient output which will match the source.

I have tried: Fred's ImageMagick color2gray but did not know how to use it and was not sure it is the right script to solve this problem.

Thank you very much in advance,
Shuki

Re: Replace specific color of image

Posted: 2017-10-09T09:54:45-07:00
by fmw42

Code: Select all

convert colorimage -colorspace gray grayimage
My script does the same, but allows different types of representation of "gray".

Re: Replace specific color of image

Posted: 2017-10-09T10:53:02-07:00
by mefuzar
Hi Fred,

Thank you for your answer and your scripts are awesome BTW!!! :D

I have tried the command you have posted, and I can't seem to get the effect I want.

Here is an example, the following image has 4 squares:
RGB = 16,0,0 (left upper)
RGB = 32,0,0 (right upper)
RGB = 64,0,0 (left down)
RGB = 128,0,0 (right down)
Image

After converting using the "convert red.png -colorspace gray gray.png" command, i get the following:
Image

You can clearly see the right down square is not white.

The problem is that I want the grayscale image to be referenced to the maximum red value, i.e: specify somehow to Imagemagick that the red (RGB: 128,0,0) should be: white (RGB: 255,255,255).

I am expecting a result that the right down square will be completely white and the three will be darker compared to it.

Do you know of a way to achieve this task using Imagemagick?

Thank you very much in advance,
Shuki

Re: Replace specific color of image

Posted: 2017-10-09T13:11:13-07:00
by snibgo
mefuzar wrote:It is a little bit hard for me to explain, for example, if I have a source picture of a red gradient, starts with BLACK and finishes at (128,0,0)
i will be able to set (128,0,0) as: (255,255,255) and get a BLACK to WHITE gradient output which will match the source.
Put this another way: make a grayscale image from just the red channel, and auto-level it.

Code: Select all

convert redsq.png -channel Red -separate +channel -auto-level out.png

Re: Replace specific color of image

Posted: 2017-10-09T13:53:21-07:00
by mefuzar
This is exactly what I was looking for... thank you so much both of you!!!