Page 1 of 1

change color of bitmap pixels

Posted: 2011-01-01T09:10:01-07:00
by Phantom
Hi,

I have a set of .png files which display chess pieces.
I want to convert the color of the pieces to any chosen RGB value. (from a colorpicker dialog).
I dont know anything about Imagemagick yet, i did read some exampes on color adjustment.
I have an example of what i tried on:

http://chess.freewebhostx.com/

How can i use the convert command to change the color of the pieces.
It seems to work with convert WB.png +level-colors ,red TEST.png
But it doesnt work for all RGB values.
Can anyone tell me how to do this ?
I hope my question is clear enough.

Re: change color of bitmap pixels

Posted: 2011-01-01T09:46:44-07:00
by Bonzo
In your second example rgb(0,0,0) is black anyway.
rgb(255,0,0) works.

Re: change color of bitmap pixels

Posted: 2011-01-01T09:56:47-07:00
by Phantom
Yes, i know it works for rgb(255,0,0) thats what i said.
If i use rgb(0,0,0) the entire picture is black thats not what i want i want to see the cross on the bishop.

Re: change color of bitmap pixels

Posted: 2011-01-01T11:50:11-07:00
by Phantom
Ok, i have seen it done in a program called babaschess (which is free).
I guess when the user selects rgb(0,0,0) using the colorpicker dialogbox it does not color with that value but maybe something like rgb(50,50,50).
There is no visible difference in the coloring of the pieces when selecting those values.
If i select rgb(50,50,50) 'the bishops cross' is still visible, so i will use that.

Re: change color of bitmap pixels

Posted: 2011-01-01T12:27:44-07:00
by fmw42
Phantom wrote:Hi,


It seems to work with convert WB.png +level-colors ,red TEST.png
But it doesnt work for all RGB values.
Can anyone tell me how to do this ?
I hope my question is clear enough.

try converting the image to grayscale first, then use +level-colors as follows:

convert image -colorspace gray +level-colors somecolor,white resultimage

or perhaps

convert image -colorspace gray +level-colors black,somecolor resultimage

if necessary you can even stretch the grayscale image to full dynamic range by adding -auto-level after -colorspace gray


Unfortunately, when you do:

convert WB.png +level-colors ,"rgb(0,0,0)" TEST2.png

it defaults to +level-colors black,"rgb(0,0,0)" and that will give you a full black image.

So try +level-colors black,"gray(XX%)" or +level-colors "gray(XX%)",white

Or try one of the following -level, +level or -contrast-stretch on the grayscale image to get the desired effect and leave off the +level-colors

see http://www.imagemagick.org/Usage/color_ ... vel-colors

Re: change color of bitmap pixels

Posted: 2011-01-02T11:13:17-07:00
by Phantom
Thanks fmw42,

I used

convert inputimage -colorspace gray +level-colors black,"gray(30%)" outputimage

and the result looks fine.

I will study imagemagick some more maybe even buy a book about it, looks interesting.

Re: change color of bitmap pixels

Posted: 2011-01-02T11:23:16-07:00
by fmw42
All the books are very outdated and much new has been added since. The best reading is each page or topic at http://www.imagemagick.org/Usage/