Remove background to take text

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
alone76816
Posts: 5
Joined: 2014-05-30T00:44:31-07:00
Authentication code: 6789

Remove background to take text

Post by alone76816 »

I have an image as below, name of image "res.png":
Image

I use this command:
"convert res.png -blur 0x0.5 -contrast-stretch 50x0%% -unsharp 0x2 z.png"
result is:
Image
I don't know to how i remove background to take text. Anybody help me, please !

I use an other way:
"convert res.png -edge 1 -negate -normalize -colorspace Gray -blur 0x.5 -contrast-stretch 0x50% y.png"
Then, i have an image:
Image

I want an image with "white background" and "black text", help me, please, please, please !
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Remove background to take text

Post by snibgo »

Most of your pixels should be white. "-contrast-stretch 50x0%%" makes half of them black.

"-contrast-stretch 2x90%%" works better.
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: Remove background to take text

Post by fmw42 »

If on unix (Linus or Mac OSX or Windows with Cygwin) see my script textcleaner at the link below. If on pure Windows see the IM function -lat.

try something like

Code: Select all

convert image -lat 25x25+10% result
alone76816
Posts: 5
Joined: 2014-05-30T00:44:31-07:00
Authentication code: 6789

Re: Remove background to take text

Post by alone76816 »

Thank for "snibgo" and "fmw42", thank you very much !
I used fmw42' code:

Code: Select all

convert image -lat 25x25+10% result
then, this result:
Image
I want remove black background, because my image must black text and white background, or white text and black background. I don't know how i do it.
And, how can i convert image from black to white and from white to black ?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Remove background to take text

Post by fmw42 »

Take your input and use -negate so that the input to textcleaner is always black text on white background. Then use -negate to convert back if need be. Textcleaner only works with dark text on light background
convert image -negate image_neg

textcleaner ..... image_neg result

See
http://www.imagemagick.org/script/comma ... php#negate
alone76816
Posts: 5
Joined: 2014-05-30T00:44:31-07:00
Authentication code: 6789

Re: Remove background to take text

Post by alone76816 »

Thank you, I will more research !
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Remove background to take text

Post by fmw42 »

try this

Code: Select all

textcleaner -g -e normalize -f 25 -o 10 res.png res_tc_f25_o10.png
alone76816
Posts: 5
Joined: 2014-05-30T00:44:31-07:00
Authentication code: 6789

Re: Remove background to take text

Post by alone76816 »

Why can I run that command ?
when I run, I gave an error:
"textcleaner: command not found"

How can i run this scripts, fmw42 ?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Remove background to take text

Post by fmw42 »

You must be on Linux, Mac OS X or Windows with Cygwin. You have to download the script from my web site and follow the Pointers for set it up properly.
alone76816
Posts: 5
Joined: 2014-05-30T00:44:31-07:00
Authentication code: 6789

Re: Remove background to take text

Post by alone76816 »

Thank you, fmw42.
I tried this command, and it's ok:

Code: Select all

./textcleaner -g -e normalize -f 25 -o 10 res.png res_tc_f25_o10.png
Post Reply