Hello, I'm trying to remove the background from this image:
I've read many forum posts where they use -transparent white, or replace the color with -opaque in combination with fuzz. but the problem is that you'll always end up with jagged edges.
I want to make all white in the image transparent and let the black lines fade off into into the transparent background. so that if I would overlay the line art over a black image, nothing (no white) would show up.
Would really appreciate some help with this, thank you!
removing white background and have transparency instead of jagged edges
removing white background and have transparency instead of jagged edges
Last edited by jeroen511 on 2019-06-22T03:29:59-07:00, edited 2 times in total.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: removing white from background while preserving transparency
Ignoring the logo bottom-right, Windows syntax:
Code: Select all
magick Xk9Wza0.png -negate ( +clone -fill Black -colorize 100 ) +swap -alpha off -compose CopyOpacity -composite out.png
snibgo's IM pages: im.snibgo.com
Re: removing white from background while preserving transparency
That's exactly it, thank you Snibgo!
Now I want to convert it to C++, but I'm not sure how to do this one, but more complex than I thought. Do you know to write that down?
Now I want to convert it to C++, but I'm not sure how to do this one, but more complex than I thought. Do you know to write that down?
Re: removing white from background while preserving transparency
got it after some fiddling!
Code: Select all
Magick::Image img = Magick::Image("img.png");
img.negate(false);
Magick::Image imgBlack = img;
imgBlack.colorize(100, Magick::ColorRGB(0, 0, 0));
imgBlack.alphaChannel(AlphaChannelOption::OffAlphaChannel);
Magick::Image imgResult = imgBlack;
imgResult.composite(img, Magick::GravityType::CenterGravity, Magick::CompositeOperator::CopyAlphaCompositeOp);
imgResult.write("imgRemovedBg.png");