Combine Images

Binary Masks

There are many useful ways to combine different images. A typical goal is to define regions of interests, so a evaluation tasks can be restricted to certain areas in an image.

For that purpose we use binary masks, where white foreground areas indicate the region to evaluate, and black background areas indicate the regions that are ignored.

Such masks can be created in many ways. For example manually painting over the regions, or using interactive threshold selection, or automatically by standard algorithms like Otsu’s method or even via advanced machine learning models.

Logical Operations

In all cases, basic logical operations can be useful to then combine multiple such masks to get all the different desired regions of interests.

Many such logical combination tasks can be used in XamFlow.

The simplest is Lucid.Core.LogicalInvert, which only takes one input image and changes white to black and black to white.

The intersection of two objects A and B can be found using Lucid.Core.LogicalAnd. It takes two inputs A and B, and creates a mask that contains the parts that are both in A ‘’and’’ in B.

The union of two objects A and B can be found using Lucid.Core.LogicalOr. The result contains any parts that are in A ‘’or’’ in B.

A bit less frequently used is the exclusion Lucid.Core.LogicalXOr. It keeps the parts that are only in A or only in B, but not in both.

Maybe in practice the most useful of them all is the complement Lucid.Core.LogicalAndNot. It keeps the parts that are in A and not B.


More advanced cases can use for example Lucid.Core.MapPixelsFormula to combine multiple images also using arbitrary formulas. All the basic logical operations can be written using mathematical operators, and more complex formulas can even combine three or more inputs at once.

Multi-value masks

Another advanced scenario is combining multiple binary objects like A B and C into a multi-valued image. The Lucid.Core.Combine takes multiple inputs and overlays them into a composite image.