Masking for enblend with SVG and Inkscape

Here is an incredibly simple two shot panorama:

originals in nautilus

..notice that there are people right in the middle where the shots overlap. The Hugin 'Preview window' shows this quite well in 'difference' mode:

Hugin difference preview

..where you can see the people and their shadow cover nearly the entire overlap area. I'll stitch this in Hugin using enblend (and I'll save the remapped images because we'll need them later):

Hugin rendering

..after rendering for some time, you can see that enblend has done a reasonable job by deciding to place the seam to include the people in the middle:

enblend result

..though the seam cuts through their shadow in a strange way.

Now lets try to change the blend using Inkscape. The intermediate TIFF layers were saved earlier, they can be used to assemble an SVG file using tif2svg:

running tif2svg

(this takes a while as it is tracing the alpha channel outlines and converting them to SVG clipping masks)

tif2svg done

..once that is done, this SVG file can be opened in Inkscape. The images themselves are not changed, but are referenced in separate layers with some transparency to make them a bit easier to see:

multilayer SVG in Inkscape

Layers can be turned on and off. This tutorial is going to work on masking out the people in layer 0, I'll draw a polygon around the area that needs to be masked out:

drawing polygon

..note that the polygon is a series of spline curves and can be re-edited easily. To combine this with the existing clipping mask, first select the image and 'release' the mask:

releasing the clip mask

..releasing the mask turns it into a 'normal' polygon. Select both polygons:

selecting both polygons

..and create a combination of the two with the 'difference' function:

boolean difference

..this creates a single outline which can be use to set the new clip mask for the image:

setting the clip mask

The layer is now completely transparent where the people were masked out (though this can be edited at any point later):

clip mask applied

Turn all the layers on, notice that the overlap is quite visible still:

save all layers

..save the SVG file and close Inkscape if you like.

enblend-svg can now be used to split the layers in the SVG file to separate TIFF files and blend them with enblend:

blend with enblend-svg

..this takes some time as it is creating large temporary files..

blending...

..as well as running enblend. Though eventually it finishes:

blending done

The result is a TIFF file with the masked-out area ignored by the blend:

enblend-svg result

As a final note, there are two reasons for working like this: one is that drawing outlines is simpler in a dedicated vector art tool like Inkscape; the other is that the TIFF images themselves are not modified and can be deleted, the SVG file itself is just a few kB:

file sizes

That's not quite it, 'positive' masking is a very similar process. If you want to positively include part of a layer instead of removing it, trace the outline as before, then move it to the another layer:

moving the path to the layer above

..combine this with the clipping mask here. Effectively forcing enblend to use the detail from the other layer for this area of the image:

setting the clip path on layer 1

Turn all the layers on and save the SVG file:

save all layers

After blending the SVG file with enblend-svg, here is the result:

enblend-svg result of positive masking

..the result is a TIFF file with the masked area 'masked-in', ie. positively masked.

tif2svg and enblend-mask can be found in the Panotools::Script perl module.

Bruno Postle - December 2007