Remove Holes (from Selection)

In order to understand how this script works, we must focus on the selection mask, that is the channel related to the selection (you can view it either by activating Quick Mask or by saving the selection as a channel). Referring to this mask, the script eliminates every area that is composed from non-white pixels and is completely enclosed by a fence of white pixels; since the elimination consists in filling such areas of the mask with white, the corresponding holes of the selection will disappear.
Therefore, a black and gray region contiguous to the image's borders across at least one pixel is not supposed to be a hole, because not all of its edges are adjacent to white pixels.

With the purpose of being more powerful, the script provides two options for adjusting the selection before the real removal operates. It presents moreover the ability to feather, by a certain radius, the edges of the selection after the holes have been taken off.


_

When the option called 'Normalize selection at first' is on, the contrast of the selection mask is stretched so that the lightest pixels become white and the darkest pixels become black; this way, it's often possible to remove some holes even from selections whose masks are devoid of white pixels, which are essential for circumscribing every eliminable hole. The example hereunder shows how this initial improvement helps at least to eliminate certain holes (the ones of the letters G and M) which you couldn't remove without it instead.


_

By activating the option called 'Apply threshold to selection at first', the selection mask will be transformed into a black and white channel without antialiasing; the extent of white areas can be regulated with the slider called 'White threshold'. This feature is useful to boost the action of removal, especially when the selection has got soft borders and blurred zones, as shown in the illustration below.


_

If you want to reduce the sharpness of the selection borders (which is inevitably produced, for instance, by turning the 'Threshold' option on), then you have to activate the option called 'Feather resultant selection'; the slider named 'Radius of feather (in pixels)' allows to set the amount of blur.
_

Once installed, you can launch this script from the image menubar through 'Select -> Remove Holes...'.

AttachmentSize
remove-holes-f-s.scm4.98 KB

Comments

Thanks!

Thanks!

Possible to add feathering, Gino D?

Thanks Gino! Nice script, have already used it on several occasions.

Is it possible to add feathering and/or anti-aliasing as options (feathering with slider) with this script?

Thanks again!

Interesting suggestion, mahvin

I agree with you: the ability to feather the resultant selection might be very handy, thus it surely deserves to be added. I am going to update the script with such functionality.
Thanks for your suggestion.

Got it, Gino. Thanks!

Thanks Gino!

I downloaded the updated script and it works great. :)

Syndicate content