Removing Background except inside content

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
kw7
Posts: 1
Joined: 2015-09-18T21:44:56-07:00
Authentication code: 1151

Removing Background except inside content

Post by kw7 »

I would like to remove the background from an image (turn white to transparent for example) but only remove it up until the point, actual content is encountered. I dont want white inside the content to be removed.

Here is an example image, the goal would be to remove the white except for the X as it is inside the star.
Image

The ideal output would look like this (the white of the X is maintained)
Image

Right now I am using the following command and the white inside the X is also being removed

Code: Select all

convert target.png -fuzz 5% -fill none -draw "matte 0,0 replace" target-out.png
Is there a way to achieve this from IM?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Removing Background except inside content

Post by fmw42 »

use "matte 0,0 floodfill"

Code: Select all

convert target.png -fuzz 5% -fill none -draw "matte 0,0 floodfill" target-out.png
see
http://www.imagemagick.org/script/magic ... aphics.php
http://www.imagemagick.org/Usage/draw/#matte
Post Reply