Page 1 of 1

Strange result replacing colors..

Posted: 2017-04-30T10:21:46-07:00
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..

Re: Strange result replacing colors..

Posted: 2017-04-30T10:51:04-07:00
by snibgo
It works fine for me, using "magick", v7.0.3-5.

Why are you using "convert"? What does "convert -version" say?

Re: Strange result replacing colors..

Posted: 2017-04-30T10:54:45-07:00
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'

Re: Strange result replacing colors..

Posted: 2017-04-30T11:24:16-07:00
by fmw42
change "convert" to "magick" for IM 7 and try your command again

Re: Strange result replacing colors..

Posted: 2017-04-30T11:31:53-07:00
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

Re: Strange result replacing colors..

Posted: 2017-04-30T11:41:52-07:00
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?

Re: Strange result replacing colors..

Posted: 2017-04-30T11:45:34-07:00
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..

Re: Strange result replacing colors..

Posted: 2017-04-30T12:00:30-07:00
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.

Re: Strange result replacing colors..

Posted: 2017-04-30T12:46:46-07:00
by Gunvald
Yes, that is what i want and cant get to work..

Re: Strange result replacing colors..

Posted: 2017-04-30T13:56:42-07:00
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

Re: Strange result replacing colors..

Posted: 2017-04-30T14:57:03-07:00
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.

Re: Strange result replacing colors..

Posted: 2017-04-30T15:40:12-07:00
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

Re: Strange result replacing colors..

Posted: 2017-04-30T17:02:48-07:00
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.