StrataQuest Home › StrataQuest Glossary › Bitwise logical operations
BOM Operation

Bitwise logical operations

Set operations, pixel by pixel: the algebra of masks

Definition
Each engine applies a truth table to each bit of every pixel value; on masks the result is a mask. AND marks foreground where both inputs are foreground. OR where either is, XOR where exactly one is. NOT swaps foreground and background in a single input. The with value variants of AND, OR and XOR combine each pixel, bit by bit, with an entered number instead of a second image.
Four functions, four set operations
Mask algebra in one truth table
AND is the everyday combination
Most multi-criterion detection ends in an AND
XOR finds where masks disagree
Useful for change detection and validation
NOT flips which side counts
Inverting a mask changes which side is foreground

Common uses of logical operations

The logical engines produce no new information; they combine the information other engines produce, so an analysis can be built from several criteria. A few cases:

Restrict detection to a region of interest. One mask defines the ROI; the other is the unrestricted detection result. AND gives detection within the ROI, the same as running detection only inside the ROI from the start. The difference is that you can decide on the ROI after detection.

Multi-marker positive cells. Threshold two channels and you have two masks: positive for marker A, positive for marker B. AND gives the double-positive subset. LabelingLoading... the AND result and counting gives the double-positive cell count directly.

Subtract one detection from another. To find the cells outside the tumor region, AND the all-cells mask with the NOT of the tumor mask. The result is the set difference: cells minus tumor.

Compare two methods. Run two segmentation algorithms on the same image. XOR marks where they differ and AND where they agree. The relative areas of those two outputs measure how well the methods agree.

Validation against ground truth. Take a manual annotation mask and an algorithmic detection mask of the same field. XOR shows every disagreement, false positives and false negatives together in one mask, and AND shows the true positives. The pixel counts of these regions are the components of standard segmentation metrics.

On non-binary images the engines work bit by bit. That is where the with value variants do their narrower jobs: extracting bit planes from a grayscale image, or masking out specific bit-flag values. A with-value engine combines every pixel with its constant bit by bit: AND with a value keeps only the bits set in the value, OR sets them, and XOR flips them. Routine workflows rarely need them; the image-with-image variants are the ones in common use.

Share This Term
Term Connections