Inpaint on the command line

Hallo,

I try to use inpaint from the command line.

I have a tif image. The areas which I want to repair are red (0xFF0000).
How can I impaint the red areas using the command line.

I have read http://gmic.eu/reference.shtml but I did not understand how to
specify the mask.

Best regards,
Daniel

You didn’t tell which inpainting algorithm you want to use (patch-based, single scale, multi-scale ?).
Something like this anyway should do the job :

$ gmic input.tiff  --select_color 0,255,0,0 -inpaint[0] [1],9 -rm[1] -o result.png

Of course, this is a ‘minimal’ command line, you have to tweak the parameters of the command -inpaint according to your inputs and desired output.

Thanks, it worked.

I used gmic inside gimp 2.8 to inpaint the red areas. I tried to
use the command line to achieve the same result as a 16bit tif.

However, I did not achieve my aim for several reasons:

  1. The command line did not produce the same result
    like the gimp plugin. (I tweaked the command line and
    used the same parameters as the plugin.)

  2. The command line did not produce a 16 bit tiff
    which is readable by othe programs.

  3. The command line changed the color profile.

Daniel

When dealing with 16bits images, some care must be taken.
As the image values are in [0,65535], this usually has a strong influence on the algorithm parameters. I believe it does make a difference for the inpainting algorithm. It’s usually a good idea to first divide your image values by 257, apply the algorithm with the parameters you have for 8bits images, then multiply the result by 257 afterwards.
Note that you won’t loose any precision as G’MIC internally stores images with float-valued buffers.

Also note that if you output a tiff with G’MIC, it will output a float-valued tiff file, which is unfortunately not often supported by other programs. So it is a good idea to force the output to be in unsigned short mode, like this :

$ gmic -i input_16bits.tiff -div 257 ... put the inpainting commands here ... -mul 257 -cut 0,65535 -o output_16bits.tiff,ushort

Concerning the color profile, I believe this has to do with the exif info ? Maybe this thread could help ?

I tried your command line. It was very fast, the output was readable, but the output
image was the same as the input image, i.e. the red areas were not inpainted.

Is the div/mul value 257 correct.

Should I tweak the values in --select 0,255,0,0?

Daniel

well, if your 16bits input image defines the mask with pure red pixels, they should have value (65535,0,0), and then dividing the image with 257 should give you (255,0,0) which is correct for the command -select_color.
You can try to add a -display in the command line, just after the --select_color to see the mask (picture on the right). It it is totally black, then it means your mask color has not been detected, and probably the color of the mask is not pure red.

The select stuff does not work.

I created a black/white image which contains the mask, and I tried the following:

gmic input.tif mask.tif -div[0] 257 -inpaint[0] [1],5,16,0.1,1,1.2,0,0.05,10,1 -mul[0] 257 -rm[1] -o output.tif,ushort

output.tif is readable, but it is quite different from the output produced with the gimp-plugin in 8bit mode.

output.tif looks very similar to the output produced by gmic command line using the 8bit input.

There are sharp borders between the inpainted areas and the original parts in output.tif

DanielDD

Any chance you can post the tif file somewhere so I can test and tell you what’s going on ?
Also, beware that the inpainting filter in the G’MIC plugin for GIMP does things a bit more complicated than just invoking command -inpaint. You can get the exact command used by the plug-in by selecting Output messages -> Verbose [layer name], apply the filter then look at the layer name to get the exact command invoked.

I will be absent until Saturday.

DanielDD

The color of your mask if not ‘pure red’. It has values (65535,26,0) instead of (65535,0,0) which explains the problem of mask detection.

This command line works reasonably well for me :

$ gmic ~/Downloads/input1.tif --select_color 0,65535,26,0 -/[0] 257 -inpaint_patchmatch[0] [1] -rm[1] -*[0] 257 -o result.tif,ushort

with a 16bits output file result.tif (takes time to compute with such a resolution anyway!)