StrataQuest Home › StrataQuest Glossary › Top-hat transform
BOM Operation

Top-hat transform

Subtract the opening; the small bright features remain

Definition
The top-hat transform is top-hat(image) = image − opening(image, structuring_element). The openingLoading... smooths out features smaller than the structuring element and keeps larger structures and the background. Subtracting the opening from the original gives back only what the opening removed. The element's size sets the scale: anything brighter than its surroundings and smaller than the element survives the subtraction, and everything else cancels.
Background separation by morphology
The opening estimates the slowly varying background
Element size sets the scale
Bigger element, larger features survive in the result
Dark features need a closing
The transform is asymmetric
Its place in a pipeline
Pre-Processing, before thresholding

When to use top-hat

Top-hat is most useful in fluorescence imaging when the field of view has a brightness gradient: illumination variation, broad autofluorescence, or any background that varies on a much larger scale than the cells you want to detect. The cells are bright spots, and the background is the slowly varying canvas beneath them. Top-hat separates the two.

Use a structuring element a few cell-diameters wide. The cells, small and bright, survive the subtraction; the gradient, large and slow, ends up in the opening and is removed. Thresholding the original would need a different value in every region, because its background varies. The top-hat result has a flat baseline, so a single thresholdLoading... works across the whole field.

The same logic holds in brightfield imaging, where small dark features such as dots or granules sit on a varying canvas. There the mirror image of top-hat, a closing minus the original, separates them the same way; in the BOM, build it from Close (dilate, erode) followed by Subtract images.

Share This Term
Term Connections