Skip to content

PCB Segmentation with SAM

SUMMARY

This section demonstrates how to use the Cornea module for PCB (Printed Circuit Board) segmentation in electronics manufacturing and inspection environments.

PCB segmentation is the task of identifying and isolating individual PCBs or regions of interest on a panel, even when they are densely packed, partially occluded, or contain complex patterns. Traditional methods often fail due to varying colors, silkscreen markings, and overlapping components.

segment_image_using_sam is used to robustly extract accurate masks for each PCB or region, enabling downstream inspection, pick-and-place, or quality control tasks.

Details on the skill, code, and practical usage are provided below.

Raw Sensor Input
PCB Segmentation Input
Raw sensor input showing a single PCB.
Segmentation and Masks
PCB Segmentation Output
Segmented image showing masks and bounding box for components on the PCB.

The Skill

For electronics manufacturing, it is critical to accurately isolate each PCB or region of interest for inspection, pick-and-place, or defect detection.

Bounding boxes alone are insufficient for complex layouts or when PCBs are closely packed. segment_image_using_sam provides pixel-accurate masks that define the exact extent of each PCB, even in the presence of silkscreen, solder, or overlapping components.

This segmentation mask enables industrial applications such as:

  1. Automated optical inspection (AOI)
  2. Pick-and-place targeting
  3. Defect and anomaly detection
  4. Quality control and traceability

See below for a code example demonstrating how to load a PCB panel image, segment the PCBs using SAM, and access the resulting annotations for further processing or visualization.

The Code

python
from telekinesis import cornea
from datatypes import io

# 1. Load a PCB panel image
image = io.load_image(filepath="pcb_panel.jpg")

# 2. Define bounding boxes for regions of interest 
bounding_boxes = [[x_min, y_min, x_max, y_max], ...]

# 3. Segment objects using SAM
result = cornea.segment_image_using_sam(image=image, bbox=bounding_boxes)

# 4. Access COCO-style annotations for visualization and processing
annotations = result["annotation"].to_list()

This code demonstrates how to load a PCB panel image, segment the PCBs using segment_image_using_sam, and access the resulting masks and bounding boxes for further processing or visualization.

Going Further: From Segmentation to Inspection

Once the PCBs are segmented, the following steps enable advanced inspection and automation:

  1. Region-of-interest extraction: Use the segmentation mask to crop or focus on individual PCBs for detailed analysis.
  2. Defect detection: Apply inspection algorithms to each segmented region to identify missing components, solder defects, or anomalies.
  3. Pick-and-place guidance: Use the mask to determine safe pick points for robotic handling.
  4. Traceability: Assign unique IDs to each PCB for tracking through the manufacturing process.

Key takeaway

PCB segmentation transforms a visually complex panel into explicit, actionable regions for inspection, automation, and quality control.

Other Typical Applications

  • Automated optical inspection (AOI)
  • Pick-and-place
  • Defect and anomaly detection
  • Quality control and traceability
  • Panelization and depanelization
  • Component counting
  • segment_image_using_sam
  • segment_using_rgb
  • segment_using_hsv

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 a similar example with:

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