Menu

Home

Dominik R.

Gimp Gradient Extrapolate

Warning: This is a rather slow plug-in, since it is complex and script based. If there's enough interest, I will consider implementing a fast C version of it.

This tool is a plugin for gimp which allows clean removal of gaps or objects, if these are in front of monotonous background. This background may be gradient like in any way, so it may have slowly changing colors.

Installation

The extracted script needs to be placed in the gimp plugins folder. This would usually result in the file structure:

.gimp-2.8/plug-ins/gradientExtrapolate.py

The folder ".gimp-2.8/" can be found in your home directory on linux and in the user's directory of windows.

You will have to restart Gimp to make the plugin available.
The plugin can then be found in the Gimp menu:

Filters > Enhance > Gradient Extrapolation

Typical Workflow

Select the region you want to have filled. If this is a gap (e.g. pure white and black) then the "Fuzzy select tool" comes in very handy.

  1. work on one object or gap at a time. This prevents global estimation over most likely different backgrounds / gradients
  2. select a (tight) region around that object
  3. apply the Gradient extrapolation filter. Note this may take a longer time, since this is a non-trivial (i.e. non-filter based) operation and also it is script based.
  4. compare the noise with the surrounding region and possibly adapt the noise in the now filled region

Example + Tips & Tricks

Here I have an image of an eagle at sunset:
Eagle and sun

You can see boundary artefacts from a rotation application. I rotated the original image such that the eagle and the sun are in the center of a golden spiral.

Also, bear with me, for the purpose of demonstration, let's remove the eagle and the dead tree.

  1. For removing the eagle above, I selected a tight region around it. I kept the "estimation distance from selection" rather low (~50px at the original image size of 24Mpixels) since otherwise the lens flare would have influenced the results too strongly. If possible,however, a higher distance makes the result more stable.
    If, in general, the object/gap is surrounded by background (i.e. not a border region), then
    1. select an order of 5 to 9. The higher the order the more "wavy" the result might get but the selection boundaries will blend in smoothly. The lower the order (i.e. for order 1) the less well it may fit a the selection boundaries.
    2. All other variables should be reasonable in this situation but you may want to play with it
  2. If the object/gap is placed at the border region, then it is more difficult to obtain nice results. In the above example I selected one black region at a time and used a very low order (i.e. 1 or 2). Otherwise the rather bad polynomial extrapolation behaviour kicks in and the values will become extreme.
    In geneneral:
    • keep the order low
    • try to increase "estimation distance from selection" as much as the image allows
    • Alternatively, try to fill a region at the border with "guessed" values to support the gradient extrapolation

This is the result and as you can see, everything blends nicely.
Eagle removed

More Examples

Here is another example of how the gradient extrapolation produces a nice output as compared to naive removal of objects (due to an only very slight background gradient, this might not be notable on every screen):
Helicopter removed

Here is a toy example (after cutting from a radial gradient):
Toy example

Applying the gradient filter on this region will ask for options, I selected these:
Toy example - options

The result:
Toy example - refilled

Parameters explained

Parameter Explanation
Order of polynomials The degree of the polynomials which are used for surface fitting. The higher the better but also the more "wavy" or with extreme results.
Estimation distance the distance in px around the given selection with will be used for estimating/fitting the polynomials. I.e. this is the input source distance
sub selection of pixels to increase the speed of the estimation increase this value. the image will be subsampled every so many pixels in both directions
increase selection area quite often boundaries to gaps are smeared or have sharp edges. Also this is used to feather the new values with existing values.
restore original selection restore the original selection after the operation has been performed or leave the new, larger selection for further processing
Post Gaussian size smooth the newly filled region with a Gaussian (IIR) of that size

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.