I have a set of transparent PNG images with black artifacts around the edges, like this:
I'm looking for a way to clean up the borders automatically. I tried simply masking out pixels under a certain RGB value, but the images themselves can also contain black pixels, and those then get filtered out. I'm using Python3 and opencv3/PIL.
My question is: How can I get rid of the black edges, while preserving black pixels that are not part of an edge?
EDIT: As usr2564301 pointed out below, very few (if any) of the edge pixels are pure black. I still need to remove them, so I'd want to use some threshold value and remove pixels that are neighbors to a transparent pixel and are either:
Try taking the alpha channel and eroding it by a couple of pixels. I am illustrating the technique with ImageMagick because that's easier, but you can do the same thing with OpenCV:
convert pinkboythingwithcathead.png \( +clone -alpha extract -morphology erode disk:2 \) -compose copy-alpha -composite result.png
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With