StrataQuest Home StrataQuest Glossary Bitwise logical operations
Image Processing & Correction

Bitwise logical operations

Set operations, executed pixel by pixel — the algebra of mask combination

Definition
Bitwise logical operations apply a per-pixel truth-table function to one or two binary inputs and produce a binary output. AND outputs foreground only where both inputs are foreground (set intersection). OR outputs foreground where either input is foreground (set union). NOT takes a single input and flips foreground and background (set complement). XOR outputs foreground where the two inputs disagree — exactly one is foreground (symmetric difference). The with value variants of AND, OR, and XOR replace the second input image with a single binary value, which is operationally equivalent to comparing every pixel to that constant. On non-binary inputs, the engines act bit by bit — useful for extracting individual bit planes from a grayscale image, though the binary-mask use case is far more common.
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 is symmetric, but conventions aren't
Inverting a mask changes which side is foreground

Where logical operations earn their place — common uses

The logical engines are pure plumbing: they don't produce information, they combine it. Their value comes from how cleanly they let multi-criterion analyses compose. A few representative cases:

Restrict detection to a region of interest. One mask defines the ROI; one mask is the unrestricted detection result. AND gives detection-within-ROI — equivalent to having run detection only inside the ROI to begin with, but achievable cleanly when the ROI is decided after detection.

Multi-marker positive cells. Two thresholding passes on two channels produce 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. A naive way to compute "cells outside the tumor region" is: take the all-cells mask, AND it with the NOT of the tumor mask. The result is the set difference: cells minus tumor.

Compare two methods. Two segmentation algorithms run on the same image produce two masks. XOR shows where they differ; AND shows where they agree. The relative areas of these two outputs quantify methodological agreement.

Validation against ground truth. A manual annotation mask and an algorithmic-detection mask of the same field — XOR shows the disagreements (false positives + false negatives combined into a single mask), AND shows the true positives. Pixel counts of these regions become the components of standard segmentation metrics.

The with value variants are useful in narrower cases — bit-plane extraction from grayscale images, masking out specific bit-flag values — and rarely appear in routine workflows. The image-image variants are where the family lives.

Share This Term
Term Connections