Skip to content

Segment Image Using Laplacian Threshold

SUMMARY

Segment Image Using Laplacian Threshold segments an image's edge-rich regions using the Laplacian operator.

It applies the Laplacian operator — a second-derivative edge detector sensitive to intensity changes in any direction — and thresholds the result to separate high-detail/edge-rich regions from smooth ones. Unlike segment_image_using_threshold or segment_image_using_otsu_threshold, which threshold on raw intensity, this thresholds on local edge strength. There are no tunable parameters.

Use this Skill when you want to isolate textured or detailed regions (e.g. engraved text, scratches, fine mechanical parts) rather than bright or dark ones.

The Skill

python
from telekinesis import cornea

segmented_image = cornea.segment_image_using_laplacian_threshold(image=image)
API Reference
Full parameter and return type documentation for segment_image_using_laplacian_threshold.
View 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
"""
Demonstrates Laplacian threshold segmentation.
"""

from loguru import logger
import rerun as rr

from telekinesis import cornea, datatypes

def segment_image_using_laplacian_threshold_example():
    """Uses the Laplacian operator to segment edge-rich areas."""
    # ===================== Load Image ==========================================
    image_url = "https://assets.telekinesis.ai/examples/v1/images/mechanical_parts_gray.png"
    image = datatypes.Image.from_url(url=image_url)

    # ===================== Run Skill ==========================================
    segmented_image = cornea.segment_image_using_laplacian_threshold(image=image)

    # ===================== Log ================================================
    logger.success(f"Segmented {image} using the Laplacian threshold method.")
    logger.success(f"Results: {segmented_image}")
    logger.info(f"Segmented image label codes: {segmented_image.label_codes}")
    logger.info(f"Segmented image number of labels: {segmented_image.number_of_labels}")
    logger.info(f"Segmented image shape: {segmented_image.shape}")
    logger.info(f"Segmented image dtype: {segmented_image.dtype}")

    # ===================== Visualization  (Optional) ======================
    rr.init("segment_image_using_laplacian_threshold_example", spawn=True)
    datatypes.visualize(image, entity_path="/input_image")
    datatypes.visualize(segmented_image, entity_path="/segmented_image")


if __name__ == "__main__":
    segment_image_using_laplacian_threshold_example()

Runnable examples are available in the Telekinesis examples repository.

Follow the README in that repository to set up the environment, run this specific example with:

bash
cd telekinesis-examples
python examples/segmentation/segment_image_using_laplacian_threshold.py

Parameter Configuration

KeyTypeDefaultDescription
imagedatatypes.Image | np.ndarrayrequiredInput image to segment, shape (H, W) or (H, W, 3)

Returns

TypeDescription
datatypes.SegmentationImageA per-pixel label map, shape (H, W), where edge-rich and smooth pixels are assigned distinct labels. Use .data for the raw label array, .label_codes for the sorted array of unique ids present, .number_of_labels for how many distinct labels were found, and .shape/.dtype for its size and label dtype.

Raises

ExceptionCondition
TypeErrorA parameter's value does not match its expected type (see the Parameter Configuration table above)
ConfigurationErrorThe TELEKINESIS_API_KEY environment variable is not set
SerializationErrorThe request input failed to serialize, or the response failed to deserialize
RequestTimeoutErrorThe request to the Cornea service timed out
TransportErrorA network failure occurred before a response was received
ClientErrorThe Cornea service rejected the request due to invalid input, invalid data, or another unexpected 4xx response
AuthenticationErrorThe API key was rejected as invalid or expired
AuthenticationServiceErrorThe authentication service was unavailable
ServerErrorThe Cornea service returned a 5xx or otherwise unexpected error response

How to Tune the Parameters

segment_image_using_laplacian_threshold takes only image — there is nothing to tune. It applies a fixed second-derivative (Laplacian) edge operator and thresholds the result, so the same edge-strength criterion is used every time; there is no threshold value, block size, or comparison mode to choose.

If you need to isolate regions by raw pixel intensity instead of local edge strength, use segment_image_using_threshold (manual value) or segment_image_using_otsu_threshold/segment_image_using_yen_threshold (automatic value) instead.

Where to Use the Skill

Common pipelines include:

  • Textured/detailed region detection – Picking out engraved text, scratches, or fine mechanical parts by their edge density rather than brightness
  • Object boundary detection – Finding where high-frequency edge content marks object outlines
  • Quality control – Flagging edge-rich defects (scratches, cracks, tool marks) that a plain intensity threshold would miss
  • Shape analysis – Isolating fine detail ahead of filter_segments_by_area/filter_segments_by_mask

Alternative Skills

Skillvs. Segment Image Using Laplacian Threshold
segment_image_using_thresholdThresholds on raw pixel intensity with a manually chosen value, rather than on local edge strength. Use Laplacian threshold for textured/detailed regions, manual threshold for known bright/dark regions.
segment_image_using_otsu_thresholdAlso thresholds on raw intensity, but picks the value automatically. Use Otsu for intensity-based segmentation, Laplacian threshold for edge-based segmentation.
segment_image_using_yen_thresholdSame intensity-vs-edge distinction as Otsu, with a different automatic-threshold criterion.
segment_image_using_adaptive_thresholdThresholds raw intensity per local neighborhood rather than edge strength. Use adaptive threshold for uneven lighting, Laplacian threshold for edge-rich texture.

When Not to Use the Skill

Do not use Segment Image Using Laplacian Threshold when:

TIP

Because the Laplacian responds to edges in any direction, it's well suited to picking out fine, directionless texture (engravings, scratches, fine parts) that a single global or per-neighborhood intensity threshold would treat as indistinguishable from their surroundings.