Skip to content

Segment Image Using Laplacian Threshold

SUMMARY

Segment Image Using Laplacian Threshold performs Laplacian threshold segmentation.

Laplacian threshold segmentation uses the Laplacian operator to detect edges and then applies thresholding. This method is useful for segmenting objects with strong edges and can be effective for images where edge information is important.

Use this Skill when you want to segment objects using Laplacian-based edge detection and thresholding.

The Skill

python
from telekinesis import cornea

result = cornea.segment_image_using_laplacian_threshold(
    image=image)

API Reference

Example

Input Image

Input image

Original image for Laplacian threshold segmentation

Output Image

Output image

Segmented image using Laplacian-based edge detection

The Code

python
import pathlib

from telekinesis import cornea
from datatypes import io

DATA_DIR = pathlib.Path("path/to/telekinesis-data")

# Load image as grayscale
filepath = str(DATA_DIR / "images" / "mechanical_parts_gray.png")
image = io.load_image(filepath=filepath, as_gray=True)

# Perform Laplacian threshold segmentation
result = cornea.segment_image_using_laplacian_threshold(
    image=image,
)

# Access results
annotation = result["annotation"].to_dict()
mask = annotation['labeled_mask']

The Explanation of the Code

Laplacian threshold segmentation applies the Laplacian operator to detect edges and then thresholds the result to create a binary segmentation mask.

The code begins by importing the required modules and loading a grayscale image:

python
import pathlib

from telekinesis import cornea
from datatypes import io

DATA_DIR = pathlib.Path("path/to/telekinesis-data")
filepath = str(DATA_DIR / "images" / "mechanical_parts_gray.png")
image = io.load_image(filepath=filepath, as_gray=True)

Laplacian threshold segmentation is applied. No parameters need to be specified:

python
result = cornea.segment_image_using_laplacian_threshold(
    image=image,
)

The function returns a dictionary containing an annotation object in COCO panoptic format. Extract the mask as follows:

python
annotation = result["annotation"].to_dict()
mask = annotation['labeled_mask']

Running the Example

Runnable examples are available in the Telekinesis examples repository. Follow the README in that repository to set up the environment. Once set up, you can run this specific example with:

bash
cd telekinesis-examples
python examples/cornea_examples.py --example segment_image_using_laplacian_threshold

How to Tune the Parameters

The segment_image_using_laplacian_threshold Skill has no tunable parameters.

TIP

Best practice: Laplacian threshold works best with images that have strong, clear edges. For images with weak edges, consider using other segmentation methods.

Where to Use the Skill in a Pipeline

Segment Image Using Laplacian Threshold is commonly used in the following pipelines:

  • Edge-based segmentation - When edges are strong and clear
  • Object boundary detection - Finding object boundaries
  • Quality control - Edge-based defect detection
  • Shape analysis - When edge information is important

A typical pipeline for edge-based segmentation looks as follows:

python
from telekinesis import cornea
from datatypes import io

# 1. Load the image (as grayscale)
image = io.load_image(filepath=..., as_gray=True)

# 2. Apply Laplacian threshold (edge-based)
result = cornea.segment_image_using_laplacian_threshold(image=image)

# 3. Process segmented regions
annotation = result["annotation"].to_dict()
mask = annotation['labeled_mask']

Related skills to build such a pipeline:

  • load_image: Load images from disk

Alternative Skills

Skillvs. Segment Image Using Laplacian Threshold
segment_image_using_otsu_thresholdOtsu is intensity-based. Use Otsu for intensity, Laplacian for edge-based segmentation.

When Not to Use the Skill

Do not use Segment Image Using Laplacian Threshold when:

  • Edges are weak or noisy (Use other segmentation methods)
  • You need intensity-based segmentation (Use Otsu or manual threshold)
  • Speed is critical (Laplacian can be slower than simple thresholding)

TIP

Laplacian threshold is particularly effective for images with strong, well-defined edges where edge information is more important than intensity values.