Strange result replacing colors..

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
Gunvald
Posts: 5
Joined: 2017-04-30T04:41:52-07:00
Authentication code: 1151

Strange result replacing colors..

Post by Gunvald »

Hi..
Im working on a script where i take a screenshot, and then change some colors in the image so that only the selected text stands out, which makes it possible to have a program OCR-read only that part.. like this..

Image

Image

But after two days i start giving up.. it should be so easy.. :)

My main idea is something similar to :
"convert Capture.png -fill "#FFFFFF" +opaque "#000000" Capture2.png"
However.. This gives me this unexpected result :

Image

Something i'm doing wrong/missing?

thx

Using : ImageMagick-7.0.5-5-Q16-x64-dll.exe for windows in commandline..
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Strange result replacing colors..

Post by snibgo »

It works fine for me, using "magick", v7.0.3-5.

Why are you using "convert"? What does "convert -version" say?
snibgo's IM pages: im.snibgo.com
Gunvald
Posts: 5
Joined: 2017-04-30T04:41:52-07:00
Authentication code: 1151

Re: Strange result replacing colors..

Post by Gunvald »

Because when i google Imagemagick remove all colours but one, i only end up with examples using convert, so i thougt that was what i should use.. new to this..

And "convert -version" says :
'Version: ImageMagick 7.0.5-5 Q16 x64 2017-04-25'
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Strange result replacing colors..

Post by fmw42 »

change "convert" to "magick" for IM 7 and try your command again
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Strange result replacing colors..

Post by Bonzo »

For your information Gunvald Imagemagick version 7 uses magick but convert will usually work depending on how V7 was installed. Most of the examples on the web will be for a V6 version hence the convert.

It is also important to get the correct command in V7 as it is stricter than V6
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Strange result replacing colors..

Post by snibgo »

Gunvald wrote:My main idea is something similar to :
"convert Capture.png -fill "#FFFFFF" +opaque "#000000" Capture2.png"
"Something similar"? Was that the exact command you used?
snibgo's IM pages: im.snibgo.com
Gunvald
Posts: 5
Joined: 2017-04-30T04:41:52-07:00
Authentication code: 1151

Re: Strange result replacing colors..

Post by Gunvald »

I understand..
But.. i tried "magick Capture.png -fill "#FFFFFF" +opaque "#000000" Capture2.png" with the same result..

.. and with "something similar" i mean that i have tried adding alot of parameters from time to time to see what difference it makes.. like -alpha remove.. -fuzz .. and so on..
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Strange result replacing colors..

Post by fmw42 »

You do not have solid black. The black text is antialiased to smooth it. So it is not pure black. So you may need to add -fuzz.
magick Capture.png -fill "#FFFFFF" +opaque "#000000" Capture2.png
should replace everything that is not pure black with white. Is that what you want? In fact, it seems that IM 7 is not working correctly on this image and is changing non-black to red. I will report this bug.
Gunvald
Posts: 5
Joined: 2017-04-30T04:41:52-07:00
Authentication code: 1151

Re: Strange result replacing colors..

Post by Gunvald »

Yes, that is what i want and cant get to work..
Gunvald
Posts: 5
Joined: 2017-04-30T04:41:52-07:00
Authentication code: 1151

Re: Strange result replacing colors..

Post by Gunvald »

I got it to work!!!!!!

first :
magick Capture.png -type Grayscale Capture2.png

and then :
magick Capture2.png -fill "#FFFFFF" +opaque "#000000" Capture3.png
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Strange result replacing colors..

Post by fmw42 »

Yes, that would help since you are making only one channel before changing colors. But it should work in sRGB color as well. It works fine in IM 6, but has a bug in IM 7.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Strange result replacing colors..

Post by snibgo »

It works fine with v7.0.3-5, so I guess it broke after that. It might be worth trying "-channel":

Code: Select all

magick Capture.png -channel RGB -fill "#FFFFFF" +opaque "#000000" +channel Capture2.png
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: Strange result replacing colors..

Post by fmw42 »

snibgo wrote: 2017-04-30T15:40:12-07:00 It works fine with v7.0.3-5, so I guess it broke after that. It might be worth trying "-channel":

Code: Select all

magick Capture.png -channel RGB -fill "#FFFFFF" +opaque "#000000" +channel Capture2.png
That does not work for me on IM 7.0.5.5.
Post Reply