Friday, October 25, 2013

Repairing Blown-Out Highlights with Inpaint

Inpainting refers to repairing or reconstructing portions of an image.  That area may have been damaged in some way or the image may include unwanted content.  Modern image editing software often offer options to automatically repair these sorts of image defects by using an Inpaint plug-in or filter.


Example of Inpaint

I use GIMP when editing images.  It's free to use and offers a large array of image editing options.  Inpaint is not included as part of the basic program, but can be added through plug-ins.  The G'MIC plug-in offers over 500 additional filters, including three different inpaint options.  I will be using one of these filters in this example.  (Inpaint filters are similar enough that the example will help illustrate how Inpaint filters work independent of program.)

 Here's the starting image chosen for this example.  It's a shot of a mushroom growing in a pile of old leaves in my yard.  There is a large area with blown-out highlights at the top of the image and the image could be drastically improved by eliminating that patch.


Note: blown-out highlights are not the only areas that can be repaired by Inpaint.  It just happens to be the reason for using it with the above image.  Also, Inpaint is not the only method available for addressing these sorts of image problems.

The example here will use the G'MIC patch-based Inpaint filter.  G'MIC also offers solidify and diffusion based filters.  I found the diffusion Inpaint filter to be far too time consuming to actually use and the patch-based filter produced far better results than solidify.

Using the Filter

Step 1.  Define the Area
This tells the software what portion of the image should be effected by the Inpaint filter.  The G'MIC plug-in for GIMP offers three methods of defining the area to be effected. 

One method applies Inpaint to transparent areas.  For this type of filter, simply erase the area to be affected.  (Make sure the image has an alpha channel first if not enabled by default.)

The second applies the filter to a particular color.  The area affected needs to be replaced with that color.  The actual method used is not important, but it must involve no feathering.  Feathering will result in part of the color being left behind after the filter is applied.

The third method uses a second transparent layer.  The area to be affected is painted in.  The filter then applies the effect to the areas under the opaque portion of this layer.  The color used for marking the area is not important.  It just needs to be opaque.


Other programs may utilize a different method for marking the area for the filter. 


Applying the "mask" for the filter.
Here the area has been marked using red by using GIMP's pencil tool set to 100% hardness to avoid feathering.

Step 2.  Run the Filter
In GIMP, the G'MIC plug-in filters are accessed by selecting filters on the top menu bar and then scrolling down to the bottom of the filters list.  G'MIC is listed at the bottom.  Clicking on it starts the G'MIC plugin and brings up all the filter options offered by that plug-in.

The Inpaint options are listed under "Repair".  Click on that option to expand it.  Scroll down until the Inpaint options are listed and select "Inpaint [patch-based].   This brings up the filter and its options.  (I just use the default settings.  They work fairly well and there is little documentation on the settings.)

After running the filter:

Better, but definitely not perfect.  The area isn't as distracting now, but there are obvious artifacts.  This leads to...

Step 3. Improve the Results
There are times when the results from running an Inpaint filter need no adjustment.  In this case, the area has obvious problems that need addressing.

Smoothing the area:

Followed by cutting and pasting leaves from other areas:

The pasted leaves are partially transparent and the edges feathered for better integration.  Part of the area filled by the Inpaint filter are still visible.


Why Use Inpaint

Using Inpaint can be useful, even if the results need to be altered after running the filter.  In the above example, Inpaint produced vague leaf-shaped results which provided a good background for manual steps.  Inpaint produced this background far quicker that doing so manually.

Combining copies of other parts of the image with this background helps limit the obvious nature of this fix.  This is one advantage of using Inpaint.  Even if the results aren't perfect, the results can be combined with other methods used to correct image flaws and the results may be better than utilize one method by itself.


One bit of advice on using Inpaint.  Keep the area selected fairly small.  200-300 pixels in diameter is a good limit on my system.  (Computers with faster processors or more memory may be handle larger areas.)  The filter can be applied in stages if dealing with larger areas.

If dealing with multiple areas, apply the filter to one area at a time.

No comments:

Post a Comment