HOWW TO REmove black pixel noise based on the surrounding area

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
mactuan12
Posts: 1
Joined: 2020-01-10T03:08:01-07:00
Authentication code: 1152

HOWW TO REmove black pixel noise based on the surrounding area

Post by mactuan12 »

I have an image to which I've applied threshold ( so all pixels below a threshold limit have been converted to 100% black).

As a result of applying threshold, there are some stray black pixels, i.e. ones that have no other black pixel in their neighbourhood.
I was looking to eliminate such such pixels, and retain only contagious areas of black in the image.

So say any black pixel ( or a small group of black pixels, say 3x3) that do not have any other black pixel (or a 3x3 black pixel group) in its immediate neighbourhood should be turned white. How do i do this with imagemagick?

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

Re: HOWW TO REmove black pixel noise based on the surrounding area

Post by fmw42 »

Please always provide your IM version and platform and if possible your image.

There are two general ways:

1) use morphology close

2) use connected-components

See
https://imagemagick.org/Usage/morphology/#close
https://imagemagick.org/script/connected-components.php

I do not know if Imagick supports either.

Post Reply