A dark defect can be easy to see while still producing the wrong measurement. Binary analysis measures whichever pixels are foreground, including wafer edges, shadows and unrelated marks. Dilation can make the defect easier to select while changing the dimensions you intended to report.
For a stationary wafer inspection, separate defect selection from defect measurement. Define the allowed search region, make dark defect pixels foreground, label the connected components, and select the intended component explicitly. Then measure its original segmented pixels using a calibrated scale. This workflow also exposes cases where the image cannot support a reliable area or perimeter measurement.
1. Stabilize the image before segmenting
Start with an image in which the defect is distinguishable from the surrounding wafer. More processing will not reliably separate a defect from a reflection having the same intensity and shape.
Fix exposure, gain, focus and illumination during measurement. Automatic adjustments can move the apparent boundary even when the physical defect remains unchanged. The guide to contour position jitter under automatic exposure explains this boundary movement.
For flat, reflective surfaces, coaxial lights are worth evaluating because their illumination travels along the viewing direction. They are not a universal answer: local slopes, surface films and patterned regions can produce contrast that resembles damage. Use the lighting finder to compare candidates, then test representative acceptable and defective samples.
The LS-CXL-0092 is a coaxial-light candidate for that evaluation. Confirm the illuminated field, viewing clearance and exposure experimentally rather than treating its housing dimensions as usable optical coverage.
- Size
- 50-100 mm
- Voltage
- 24 V
Keep an unmodified grayscale image with every measurement. It is the reference for deciding whether a reported boundary follows the defect or an imaging artifact.
2. Define a search region without creating a new background
A region of interest, or ROI, should express where the defect is allowed to occur. It should not merely hide unwanted measurements after they have already entered the analysis.
Use a rectangular search region when the wafer position is repeatable. Use a wafer-interior mask when the outer edge creates dark background regions. If the wafer moves, locate it first and express the search region relative to that location.
For an illustrative image measuring 1600 × 1200 pixels, a validated search window might span columns 200–1399 and rows 100–599. Those coordinates are application assumptions, not general wafer-inspection settings. The search region must include all permitted defect positions and sufficient surrounding material to judge the boundary.
Do not paint pixels outside the ROI black and then threshold for dark objects. That operation creates a large artificial foreground region. Instead, threshold the original grayscale image and intersect the resulting mask with the ROI.
Flag any selected component touching the ROI boundary. It may be clipped, so its measured area is incomplete. Automatically discarding such components is acceptable only when the inspection specification deliberately excludes that boundary zone.
3. Make defect pixels foreground, then label them
For a dark defect on a brighter background, the intended binary convention is:
- Defect candidate: true, or foreground.
- Acceptable background: false.
- Pixels outside the search region: false.
A bright-object threshold often produces the opposite convention. Inspect a binary overlay before interpreting any component measurements. The live binary image preview guide describes how to make threshold behavior visible during setup.
Use this numbered sequence:
- Convert the image to a documented grayscale representation if necessary.
- Define the permitted search-region mask.
- Mark pixels darker than the chosen threshold as candidate foreground.
- Intersect the candidate mask with the search-region mask.
- Label connected foreground pixels using an explicit connectivity rule.
- Select a component using validated location, size and shape criteria.
The following is language-neutral pseudocode. The function names describe operations rather than a particular software interface.
gray = convert_to_grayscale(image)
roi = make_search_region(gray)
raw_mask = (gray < threshold) AND roi
labels = label_components(raw_mask, connectivity=8)
candidates = describe_components(labels)
selected_id = select_component(candidates, acceptance_rules)
selected_mask = (labels == selected_id)
In a two-dimensional image, 4-connectivity joins pixels sharing an edge. Eight-connectivity also joins pixels meeting diagonally. Choose the rule deliberately: a diagonal chain can become one object under one rule and several objects under the other.
Never assume the first returned component is the defect. Label order is an implementation detail, not an inspection criterion.
4. Select the defect with explicit acceptance rules
Thresholding generates candidates; it does not identify which candidate matters. Record each component's area, centroid, bounding box and contact with the search boundary before selecting it.
Apply permissive filters first, then more specific checks. An illustrative selection specification might require an area between 80 and 1200 pixels, a centroid inside the expected defect zone, and no contact with an excluded wafer-edge band. These values must come from representative samples and the smallest defect you need to detect.
| Selection method | Useful when | Main failure mode |
|---|---|---|
| Largest connected component | The defect is consistently larger than every nuisance mark | A shadow or wafer edge becomes the selected object |
| Area interval | Defect sizes have validated limits | A genuine small defect falls below the cutoff |
| Centroid or bounding-box location | The permitted defect zone is known | Part movement moves the defect outside the zone |
| Seed-point membership | A trusted location falls inside the defect | The seed lands on background or another mark |
| Combined location and size rules | Several nuisance objects survive thresholding | Overly tight rules reject unfamiliar defects |
If the inspection expects exactly one component, treat zero or multiple qualifying components as explicit inspection states. Do not silently select whichever object happens to appear first.
A boundary outline is useful for display, but it is not the same as a filled defect region. Measuring a thin edge image reports the pixels in that edge, not the enclosed defect area.
5. Keep morphology separate from the measurement mask
Dilation, erosion, opening and closing change the segmented geometry. They can help connect fragments or remove isolated noise, but those changes affect the reported area and perimeter.
Keep two masks when morphology is needed:
- A selection mask, which may be cleaned or expanded to locate the defect.
- A measurement mask, which preserves the boundary definition required by the inspection specification.
For an isolated defect, you can select a component in a dilated mask and then recover its original pixels by intersecting that component with the raw mask. If dilation merged separate marks, however, that intersection retains all merged marks. It does not recover the intended identity automatically.
Consider an ideal filled rectangle measuring 20 × 10 pixels. Dilation with a centered, full 5 × 5 square expands each side by 2 pixels, provided no image boundary clips the expansion.
These perimeter values describe ideal pixel-edge rectangles. A library using another digital perimeter estimator can report different values. The example demonstrates geometric bias, not a universal software output.
Hole filling also changes area. Decide whether bright islands inside a dark defect belong to the defect footprint or should remain excluded. Neither interpretation is automatically correct.
6. Measure only the selected component
Pass the selected component label or its isolated Boolean mask to the measurement operation. Do not pass the entire candidate mask and assume a single returned value refers to the desired defect.
Define the outputs before comparing measurements:
- Area: foreground pixel count, a weighted digital-area estimate, or another documented estimator.
- Perimeter: outer boundary only, or outer boundary plus internal hole boundaries.
- Geometry: raw segmented pixels or an explicitly specified processed mask.
- Connectivity: the same documented rule used during component selection.
For a uniform, square-pixel object-plane scale, conversion is straightforward:
If horizontal and vertical scales differ, area uses their product. Perimeter requires scaling boundary coordinates or segment lengths separately; multiplying by an average scale introduces an avoidable error.
Use a reference at the inspection plane. The guide to camera calibration for length measurement covers establishing image-to-object scale. For measurements across a wider field, also check distortion correction accuracy.
If distortion correction resamples the image, document whether segmentation occurs before or after that transformation. Resampling can alter threshold crossings and therefore the measured boundary.
7. Work through a calibrated example
Suppose a calibration reference spans 10 mm and measures 2000 pixels in the image. Assume the scale is uniform over the defect and the selected component contains 200 foreground pixels. Its chosen perimeter estimator reports 60 pixel lengths.
Store both the pixel-domain measurements and the converted measurements. That separation helps distinguish a segmentation change from a calibration change.
Check sampling before choosing hardware. For example, a 20 mm-wide field sampled by 4000 pixels gives:
Ten pixels across a feature is a starting point for evaluation, not proof of perimeter accuracy. Optical blur, contrast and boundary roughness still matter. Use the resolution calculator to explore the sampling requirement.
The guide to choosing camera resolution for dimensional inspection explains why pixel count alone does not establish measurement capability.
8. Verify the boundary and diagnose common mistakes
Overlay the selected boundary on the original grayscale image. Display the ROI, selected label and rejected candidates separately. A plausible numeric result is not sufficient evidence that the intended object was measured.
| Symptom | Likely cause | Test and correction |
|---|---|---|
| Reported area covers most of the image | Reversed polarity or dark padding outside the ROI | Inspect true pixels; threshold first, then intersect with the ROI |
| Several measurement records appear | The complete candidate mask was measured | Isolate the accepted component before measurement |
| Area increases after cleanup | Dilation, closing or hole filling changed the geometry | Compare raw and processed masks and report the specified version |
| Perimeter changes sharply while area changes little | Boundary noise or threshold instability | Inspect the overlay and test nearby thresholds |
| Defect measurements stop at a straight line | The ROI clipped the component | Expand the search region or reject the clipped measurement |
As an illustrative sensitivity test on an 8-bit image, compare thresholds of 90, 95 and 100. Record component identity, area and perimeter at each setting. A sudden jump can indicate merging with another mark rather than gradual boundary movement.
Repeat the acquisition without moving the wafer, then repeat after normal repositioning. These tests separate capture repeatability from placement sensitivity. If reference subtraction supplies the candidate mask, address image-subtraction contour artifacts before attributing every residual region to a defect.
9. Check the imaging parts and release criteria
Choose area scan cameras for adequate sampling and suitable acquisition behavior, not simply the largest pixel count. The camera finder helps narrow the options.
The LS-CMR-0053 is a rolling-shutter, C-mount camera candidate for a stationary inspection trial. Confirm that the wafer remains still throughout acquisition; motion can alter the apparent defect geometry.
- Sensor format
- 1/1.7"
- Lens mount
- C-mount
- Interface
- GigE
- Resolution
- 12 MP
Select machine vision lenses for sensor coverage, required field, working distance and usable contrast. The LS-FFL-0567 is a C-mount lens candidate to evaluate against those requirements. Use the lens finder and the machine vision lens selection guide before committing to a camera-and-lens combination.
- Type
- Machine vision fixed
- Sensor format
- 1.1"
- Mount
- C-mount
- Resolution
- 16-25 MP
Before releasing the measurement, confirm:
- The original image and calibration record are retained.
- The defect is foreground and outside-ROI pixels are background.
- Component selection does not depend on label order.
- Clipped, missing and multiple-component cases produce defined outcomes.
- Morphology and hole handling match the written measurement definition.
- Area and perimeter estimators are documented separately.
- Threshold sensitivity and repeatability meet the application's acceptance limits.
A dark-pixel workflow is the wrong method when acceptable wafer patterns share the defect's intensity, or when the defect appears mainly through texture or directional scattering. Change the imaging method or classification strategy rather than forcing a threshold to separate indistinguishable regions.
Start the camera configuration with your required field and smallest defect, or request application support with representative images, expected defect locations and the required measurement tolerance.
Questions
Why does my defect measurement include the background?
Binary measurement tools analyze foreground pixels, not the visual meaning of a region. Reversed threshold polarity, dark pixels outside the search region, or measuring every connected component can include background. Inspect the mask, restrict it to the valid wafer region, and pass only the selected component to measurement.
Should I always measure the largest connected component?
Only when size is a validated distinguishing feature. A wafer edge, shadow or unrelated mark can be larger than the defect. Combine size with permitted location, boundary contact and other justified criteria. Define what happens when no component qualifies or several components qualify.
Can dilation improve wafer defect measurements?
Dilation can make fragmented objects easier to select, but it also expands boundaries and can join unrelated objects. Keep a separate original measurement mask where possible. If processed geometry is the required output, document the operation and validate its bias against reference measurements.
Why does perimeter vary more than area?
Perimeter depends strongly on the detailed boundary, including small notches, diagonal steps and internal holes. Area can remain similar while those details change. Compare boundary overlays, threshold sensitivity, connectivity and perimeter estimator definitions before deciding that the physical defect has changed.
How do I convert defect pixel area into square millimeters?
Calibrate image distance against a known length at the inspection plane. For uniform square-pixel sampling, multiply pixel count by the squared length-per-pixel scale. Check distortion and perspective across the measurement region; a single scale is insufficient when magnification changes appreciably with position.


