basic swap color failed

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
alphanoch
Posts: 2
Joined: 2013-12-12T07:18:34-07:00
Authentication code: 6789

basic swap color failed

Post by alphanoch »

Hello,

I'm trying to do a basic color replacement operation like follows:
>convert source.png -fill #77AA52 -opaque #436FC0 result.png

This is not working unless I put the -fuzz operator:
>convert source.png -fuzz 20% -fill #77AA52 -opaque #436FC0 result.png

The color #436FC0 does exist in the source, I tested it with several desktop color picker !
You can find it here:
https://drive.google.com/file/d/0B2OHG9 ... sp=sharing

I can't get to know where I'm wrong, I tried several other options like putting -channel rgba, using rgb notation:
>convert source.png -fill rgb(119,170,82) -opaque rgb(67,111,192) result.png
changing colorspace, saving source to a 32bit detph png with PNG32, etc...

Could somebody give me a hint on what is involved here that make this conversion fail ?
thx.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: basic swap color failed

Post by snibgo »

The image is a blue arrow on a transparent background. Gimp shows the arrow is around #0072c6 and the background is transparent black.

According to

Code: Select all

identify -verbose source.png
no pixels have non-zero in the red channel. The only pixels are:

Code: Select all

  Colors: 6
  Histogram:
      1905: (  0,  0,  0,  0) #00000000 none
        18: (  0,113,197,249) #0071C5F9 srgba(0,113,197,0.97647058823529409)
         1: (  0,113,197,253) #0071C5FD srgba(0,113,197,0.99215686274509807)
       163: (  0,114,198,255) #0072C6 srgba(0,114,198,1)
        22: (  0,114,198,252) #0072C6FC srgba(0,114,198,0.9882352941176471)
        41: (  0,115,197, 84) #0073C554 srgba(0,115,197,0.32941176470588235)
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: basic swap color failed

Post by fmw42 »

Another issue when dealing with images with transparency, is that you need to include the transparency as well in your hex code values.

I concur with snibgo. There is no red component in any of your colors in the image.


convert source.png -unique-colors txt:

# ImageMagick pixel enumeration: 6,1,255,srgba
0,0: (0,114,198,1) #0072C6 srgba(0,114,198,1)
1,0: (0,113,197,0.992157) #0071C5FD srgba(0,113,197,0.992157)
2,0: (0,114,198,0.988235) #0072C6FC srgba(0,114,198,0.988235)
3,0: (0,113,197,0.976471) #0071C5F9 srgba(0,113,197,0.976471)
4,0: (0,0,0,0) #00000000 none
5,0: (0,115,197,0.329412) #0073C554 srgba(0,115,197,0.329412)


All hexcodes start with #00 (the red component)
alphanoch
Posts: 2
Joined: 2013-12-12T07:18:34-07:00
Authentication code: 6789

Re: basic swap color failed

Post by alphanoch »

Hello,

For sure #0072C6 is not #436FC0 and both are pure RGB with no transparency.
I just put too many trust in the way I picked my colors... Iconico ColorPic4.1 and veign Pixeurv3.2 are OK it's definitely that's crappy Windows Photo Viewer that failed !
Now I know I must use the commands you mentioned if I want to have an accurate color, or simply take the one gimp will pick !

Many thanks, have a good day.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: basic swap color failed

Post by snibgo »

One issue is that all computers do colour management to try to make colours look correct, whatever screen is used. An image will have a certain pixel value but the operating system will tweak the value before sending it to the screen. A utility that reads the screen will get this tweaked value.

Gimp told me the arrow was #0072c6. But saving the Gimp screen and looking at the resulting PNG gave me a value of #006dc0. And saving that screen and looking at the PNG gives #076dbe. So there is a slow colour-drift at each generation.

[Aside: I wouldn't be surprised if the equivalent on an Apple computer gives a better result, the "untweaked" result. Apple have always been more intelligent about colour than Microsoft.]

However, your result (#436FC0) is so massively different that something else is going wrong. And the major difference is in the red channel.

Note that Gimp is 8-bit, so won't give the exact result for 16-bit/channel images.
snibgo's IM pages: im.snibgo.com
Post Reply