fill black color for an outline

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?".
Amused23
Posts: 20
Joined: 2015-09-24T22:48:39-07:00
Authentication code: 1151

fill black color for an outline

Post 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?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: fill black color for an outline

Post 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
Amused23
Posts: 20
Joined: 2015-09-24T22:48:39-07:00
Authentication code: 1151

Re: fill black color for an outline

Post by Amused23 »

Started using imagemagick yesterday....should have posted the image...here it is...

https://www.dropbox.com/s/bofcu28v7l0uhro/out.png?dl=0
Last edited by Amused23 on 2015-09-24T23:48:08-07:00, edited 1 time in total.
Amused23
Posts: 20
Joined: 2015-09-24T22:48:39-07:00
Authentication code: 1151

Re: fill black color for an outline

Post by Amused23 »

My imagemagick version is ImageMagick 6.7.7-10 and i am on ubuntu 14.04
Amused23
Posts: 20
Joined: 2015-09-24T22:48:39-07:00
Authentication code: 1151

Re: fill black color for an outline

Post by Amused23 »

is it possible to fill colour without giving the coordinates of the number?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: fill black color for an outline

Post 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
Amused23
Posts: 20
Joined: 2015-09-24T22:48:39-07:00
Authentication code: 1151

Re: fill black color for an outline

Post by Amused23 »

Amused23
Posts: 20
Joined: 2015-09-24T22:48:39-07:00
Authentication code: 1151

Re: fill black color for an outline

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: fill black color for an outline

Post 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.
snibgo's IM pages: im.snibgo.com
Amused23
Posts: 20
Joined: 2015-09-24T22:48:39-07:00
Authentication code: 1151

Re: fill black color for an outline

Post by Amused23 »

Hi..i am new to imagemagick...could you put that as commands? I would really appreciate it.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: fill black color for an outline

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: fill black color for an outline

Post by snibgo »

Yes, that's a better way. I hadn't seen that dark column.
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: fill black color for an outline

Post 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.
Amused23
Posts: 20
Joined: 2015-09-24T22:48:39-07:00
Authentication code: 1151

Re: fill black color for an outline

Post 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
Amused23
Posts: 20
Joined: 2015-09-24T22:48:39-07:00
Authentication code: 1151

Re: fill black color for an outline

Post by Amused23 »

worked it out..have to use

Code: Select all

convert -white-threshold 20%
instead of 50%

Thanks all.
Post Reply