Remove noise surrounded by transparency

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
Posts: 1
Joined: 2018-09-08T20:43:24-07:00
Authentication code: 1152

Remove noise surrounded by transparency

Post by jiexi » 2018-09-08T20:53:49-07:00

I'm trying to remove the noise that runs around the border on these polaroid images


I think the correct approach is to separate out each part of the image that is completely surrounded by only transparent background, then discard the small pieces which should leave us with just the larger image?

User avatar
Posts: 25050
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Remove noise surrounded by transparency

Post by fmw42 » 2018-09-08T21:10:17-07:00

There are two ways to approach it. First is to use -morphology open on the alpha channel. The second is to use -connected-components to remove small regions.

These both work on your first image for me with IM Q16 Mac OSX Sierra. But you will likely have to change the value for octagon:X or area-threshold=X

Code: Select all

convert wrnTV0w.png -channel a -morphology open octagon:5 +channel result.png

Code: Select all

convert wrnTV0w.png \
\( +clone -alpha extract -type bilevel \
-define connected-components:area-threshold=1000 \
-define connected-components:mean-color=true \
-connected-components 4 \) \
-alpha off -compose copy_opacity -composite \


Please, always provide your IM version and platform when asking questions, since syntax may differ. Also provide your exact command line and if possible your images.

See the top-most post in this forum "IMPORTANT: Please Read This FIRST Before Posting" at ... f=1&t=9620

If using Imagemagick 7, then see

For novices, see ... f=1&t=9620 ... essing.php

Post Reply