Remove Small Connected Components

Overview

This transform removes small, isolated groups of pixels (connected components) from a binary mask, which is useful for cleaning up noise or irrelevant objects.

Detailed Description

In image analysis, particularly with binary masks, it’s common to have small, spurious regions of interest that are not relevant to the main analysis. This transform uses a connected components algorithm to identify all distinct, contiguous regions of pixels in the mask. It then filters out any region whose total number of pixels is below a specified threshold.

This process helps to isolate and preserve only the most significant structures in the mask, making subsequent analysis, such as object tracking or morphological measurement, more robust. The connectivity analysis considers pixels to be connected if they touch at their edges or corners (8-connectivity).

This transform takes a mask as input and produces a new, cleaned-up mask as output.

Neuroscience Use Cases

  • Calcium Imaging Cleanup: In two-photon or wide-field calcium imaging, masks representing active neurons or regions of interest (ROIs) can be noisy. This transform can remove small, spurious signals that are unlikely to be true neuronal activity, ensuring that only significant ROIs are kept for analysis.
  • Behavioral Tracking: When tracking an animal’s position or posture using video, the resulting binary masks can contain noise from lighting changes or background artifacts. Removing small connected components can clean up the mask of the animal, leading to more accurate tracking of its centroid or body shape.
  • Histology and Morphology: When analyzing images of tissue slices, automated segmentation can produce small, artifactual regions. This transform can be used to filter out these artifacts, leaving only the larger, more relevant structures like cell bodies or labeled tracts.

Parameters

This transform has a single parameter:

  • threshold: An integer value that specifies the minimum number of pixels a connected component must have to be preserved. Any component with a pixel count smaller than this value will be removed from the mask.

Example Configuration

Here is a complete example of a JSON configuration file that could be used to run this transformation. This example loads a mask, removes all connected components with fewer than 3 pixels, and saves the result.

[
{
    "transformations": {
        "metadata": {
            "name": "Mask Connected Component Pipeline",
            "description": "Test connected component analysis on mask data",
            "version": "1.0"
        },
        "steps": [
            {
                "step_id": "1",
                "transform_name": "Remove Small Connected Components",
                "phase": "analysis",
                "input_key": "test_mask",
                "output_key": "filtered_mask",
                "parameters": {
                    "threshold": 3
                }
            }
        ]
    }
}
]