I have a set of transparent PNG images with black artifacts around the edges, for example:

I am looking for a way to automatically clear borders. I tried just to mask the pixels with a specific RGB value, but the images themselves may also contain black pixels, and then they are filtered out. I am using Python3 and opencv3 / PIL.
My question is: How can I get rid of black edges while preserving black pixels that are not part of the edge?
EDIT: As indicated in note usr2564301 below, very few (if any) edge pixels are black. I still need to remove them, so I want to use some threshold value and remove pixels that are neighbors, transparent pixels, and either:
- The darker the threshold, or
- Darker at least the threshold than any adjacent opaque pixel.
source share