change color of bitmap pixels

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
Phantom
Posts: 5
Joined: 2010-12-31T22:25:58-07:00
Authentication code: 8675308

change color of bitmap pixels

Post 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.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: change color of bitmap pixels

Post by Bonzo »

In your second example rgb(0,0,0) is black anyway.
rgb(255,0,0) works.
Phantom
Posts: 5
Joined: 2010-12-31T22:25:58-07:00
Authentication code: 8675308

Re: change color of bitmap pixels

Post 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.
Phantom
Posts: 5
Joined: 2010-12-31T22:25:58-07:00
Authentication code: 8675308

Re: change color of bitmap pixels

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

Re: change color of bitmap pixels

Post 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
Phantom
Posts: 5
Joined: 2010-12-31T22:25:58-07:00
Authentication code: 8675308

Re: change color of bitmap pixels

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

Re: change color of bitmap pixels

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