You are here

Remove Holes (from Selection)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
Rate this item!
AttachmentSize
remove-holes-f-s.zip3.21 KB

Gino D's GIMP Scripts: https://sites.google.com/site/ginodonig/gimp-scripts


Overview

This script enables you to remove the holes of a selection, if by hole we mean every unselected or partially selected area of the image which is surrounded by a fully selected area.

In order to understand how the script works, we have to focus on the selection mask, that is the channel related to the selection (you can view it by either activating the Quick Mask or 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 surrounded by a border of white pixels, and the elimination consists in filling such areas of the selection mask with white, so that the corresponding holes of the selection will disappear. Therefore, a black and gray region of the selection mask which is contiguous to the image's borders across at least one pixel cannot be regarded as a hole, because not all of its edges are adjacent to white pixels.


Activating the script

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


Options

 
Normalize initial selection
When this box is checked, the contrast of the selection mask will be initially stretched, causing the lightest pixels to become white and the darkest pixels to become black; in this way, it is often possible to remove some holes even from selections whose masks are devoid of white pixels, which are essential for circumscribing any possible hole. The following illustration shows that enabling this option helps at least to eliminate the holes in the letters G and M, which could not be removed otherwise.

 
Sharpen initial selection
By activating this checkbox, the selection mask will be preliminarily transformed into a black and white channel without anti-aliasing, a kind of enhancement that can make the subsequent action of removal more effective in case the selection is provided with soft borders and blurred zones, as shown in the illustration below.
Threshold
Allows you to set the level of gray (in a scale from 0 to 255) to use as a threshold in sharpening the initial selection, so that all the pixels of the selection mask with a luminosity (gray level) equal to or higher than the specified threshold will become white, while all the pixels darker than the specified threshold will become black.

 
Feather resultant selection
When this box is checked, it is possible to reduce the sharpness of the borders of the eventual selection.
Radius of feather (in pixels)
Allows you to set the amount of blur affecting the selection borders when the "Feather resultant selection" checkbox is activated.
Values vary within a range of 0 to 32767.

Code License: 
GIMP Version: 
Scripting Engine: 

Comments

RELEASE NOTES

  • Renamed some options of the script.
  • Fixed some minor bugs; enhanced and cleaned up the code.

_RELEASE NOTES_

  • Made the script fully compatible with GIMP 2.8, while maintaining the backward compatibility with the previous versions beginning from GIMP 2.6.10.
  • Changed the method of removal, which now uses a temporary image rather than a temporary layer of the active image.
  • Lots of improvements, cleanups and minor bug fixes regarding both the code and the dialog window.

_RELEASE NOTES_

  • Fixed a bug that made the script crash when operating on non-RGB images.
  • As for normalizing the selection, added a new code snippet consisting only of GIMP internal procedures, so that doing without the "plug-in-c-astretch" command.
  • Fixed a small flaw in the display of the progress bar.
  • Corrected the year range in my copyright notice.
  • Improved and cleaned up the code.

_RELEASE NOTES_

  • Improved the method of removal, by resorting to a temporary layer instead of manipulating the canvas size.
  • Reshaped and cleaned up the code.

Just did a quick test and it worked quite well. Thanks. :)

_ RELEASE NOTES _

* Only reshaped and cleaned up the code.

Thanks!

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!

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.

Thanks Gino!

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

Subscribe to Comments for "Remove Holes (from Selection)"