Strange result replacing colors..
Strange result replacing colors..
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..
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 :
Something i'm doing wrong/missing?
thx
Using : ImageMagick-7.0.5-5-Q16-x64-dll.exe for windows in commandline..
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..
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 :
Something i'm doing wrong/missing?
thx
Using : ImageMagick-7.0.5-5-Q16-x64-dll.exe for windows in commandline..
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Strange result replacing colors..
It works fine for me, using "magick", v7.0.3-5.
Why are you using "convert"? What does "convert -version" say?
Why are you using "convert"? What does "convert -version" say?
snibgo's IM pages: im.snibgo.com
Re: Strange result replacing colors..
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'
And "convert -version" says :
'Version: ImageMagick 7.0.5-5 Q16 x64 2017-04-25'
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Strange result replacing colors..
change "convert" to "magick" for IM 7 and try your command again
Re: Strange result replacing colors..
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
It is also important to get the correct command in V7 as it is stricter than V6
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Strange result replacing colors..
"Something similar"? Was that the exact command you used?Gunvald wrote:My main idea is something similar to :
"convert Capture.png -fill "#FFFFFF" +opaque "#000000" Capture2.png"
snibgo's IM pages: im.snibgo.com
Re: Strange result replacing colors..
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..
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..
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Strange result replacing colors..
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.
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.magick Capture.png -fill "#FFFFFF" +opaque "#000000" Capture2.png
Re: Strange result replacing colors..
Yes, that is what i want and cant get to work..
Re: Strange result replacing colors..
I got it to work!!!!!!
first :
magick Capture.png -type Grayscale Capture2.png
and then :
magick Capture2.png -fill "#FFFFFF" +opaque "#000000" Capture3.png
first :
magick Capture.png -type Grayscale Capture2.png
and then :
magick Capture2.png -fill "#FFFFFF" +opaque "#000000" Capture3.png
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Strange result replacing colors..
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.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Strange result replacing colors..
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
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Strange result replacing colors..
That does not work for me on IM 7.0.5.5.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