Page 1 of 2

fill black color for an outline

Posted: 2015-09-24T22:59:08-07:00
by Amused23
Hi!!
I have a image with white background and a number with black outline. I need to fill the number with black colour without disturbing the background. How can I achieve this?

Re: fill black color for an outline

Posted: 2015-09-24T23:04:12-07:00
by fmw42
Please identify your version of IM and platform and upload your image to dropbox.com and put the link here. We cannot help without seeing the image and figuring out what needs to be done.

One approach might be to use -floodfill or -draw "... floodfill". See
http://www.imagemagick.org/Usage/color_ ... dfill_draw
http://www.imagemagick.org/Usage/color_ ... #floodfill

See also viewtopic.php?f=1&t=9620

Re: fill black color for an outline

Posted: 2015-09-24T23:26:19-07:00
by Amused23
Started using imagemagick yesterday....should have posted the image...here it is...

https://www.dropbox.com/s/bofcu28v7l0uhro/out.png?dl=0

Re: fill black color for an outline

Posted: 2015-09-24T23:31:09-07:00
by Amused23
My imagemagick version is ImageMagick 6.7.7-10 and i am on ubuntu 14.04

Re: fill black color for an outline

Posted: 2015-09-24T23:44:18-07:00
by Amused23
is it possible to fill colour without giving the coordinates of the number?

Re: fill black color for an outline

Posted: 2015-09-25T00:01:23-07:00
by fmw42
I cannot download since you made it to require your login information. You should upload to the public folder on dropbox so no login is needed

Re: fill black color for an outline

Posted: 2015-09-25T00:28:00-07:00
by Amused23

Re: fill black color for an outline

Posted: 2015-09-25T03:52:44-07:00
by Amused23
If it is not possible to fill the numbers...is it possible to extract the numbers? I need this for Optical Character Recognition.

Re: fill black color for an outline

Posted: 2015-09-25T06:25:59-07:00
by snibgo
An obvious method to fill the numbers is:

1. Floodfill with red from top-left.
2. Floodfill with red from top-right.
3. Change white into black.
4. Floodfill with white from top-left.
5. Floodfill with white from top-right.

Re: fill black color for an outline

Posted: 2015-09-25T06:51:39-07:00
by Amused23
Hi..i am new to imagemagick...could you put that as commands? I would really appreciate it.

Re: fill black color for an outline

Posted: 2015-09-25T09:53:38-07:00
by fmw42
Somewhat similar to user snibgo's suggestion.

1) pad the image all around with 1 pixel of white
2) floodfill at the top left corner to replace white with red
3) replace white with black
4) replace red with white
5) shave 1 pixel all around the image to get back to original size
6) output result

(Note: your image has a dark column at around the second column from the left which is why I padded with white to avoid getting only one column of red in my step 2 and snibgo's step 1)

Code: Select all

convert out.png -bordercolor white -border 1 \
-fill red -draw "color 0,0 floodfill" \
-fill black -opaque white \
-fill white -opaque red \
-shave 1x1 \
result.png
see
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/
http://www.imagemagick.org/Usage/crop/#border
http://www.imagemagick.org/Usage/crop/#shave
http://www.imagemagick.org/Usage/color_basics/#opaque
http://www.imagemagick.org/Usage/color_ ... dfill_draw
http://www.imagemagick.org/Usage/color_ ... #floodfill

Re: fill black color for an outline

Posted: 2015-09-25T10:07:05-07:00
by snibgo
Yes, that's a better way. I hadn't seen that dark column.

Re: fill black color for an outline

Posted: 2015-09-25T10:12:38-07:00
by fmw42
snibgo wrote:Yes, that's a better way. I hadn't seen that dark column.
I first tried your method and that was when I saw the black column, since the red stopped there and did not fill all the white. So that was why I decided to pad and do only one floodfill and then shave again.

Re: fill black color for an outline

Posted: 2015-09-25T22:43:28-07:00
by Amused23
Thank you ...that worked like a charm!! I have a problem I don't understand. I first tried

Code: Select all

convert -white-threshold 50% on 
https://www.dropbox.com/s/pvb5l1itdj73rhd/out.png?dl=0
and I got this result https://www.dropbox.com/s/as3elqdz77417zi/bw.png?dl=0. The yellow / orange colour is removed.

But when i try the same command on https://www.dropbox.com/s/7t315s2c9ee1pj6/out3.png?dl=0
I get https://www.dropbox.com/s/g63zieo4836mxuv/bw3.png?dl=0. The green colour remains.

How to get rid of the any background colour for the letters

Re: fill black color for an outline

Posted: 2015-09-25T22:54:49-07:00
by Amused23
worked it out..have to use

Code: Select all

convert -white-threshold 20%
instead of 50%

Thanks all.