An edge image can show the correct feature clearly while still producing unreliable endpoint coordinates. Thickened edges, tiny branches, corners and gaps all create misleading candidates. For inspection developers, the first task is defining which endpoint should win, rather than choosing a stronger edge filter.
The method below separates topology from measurement. You will extract candidates from a thin edge map, rank them using an explicit center-distance rule, and refine the selected position against the original grayscale image. A validation procedure then checks whether the result stays within five pixels on each image axis.
1. Define what counts as the nearest endpoint
Two requirements that sound similar can produce different coordinates:
- Nearest endpoint: find all valid endpoints, then select the endpoint closest to the image center.
- Endpoint of the nearest component: find the connected edge component closest to the center, then select a valid endpoint belonging to that component.
For the second rule, define component distance explicitly. A practical choice is the minimum distance from the center to any pixel belonging to that component. Its centroid is a different measurement and can favor the wrong curve.
Also define what an endpoint represents physically. An open boundary, a scratch termination and the end of a dark stripe are different features. A dark stripe can produce a closed outline around its tip, leaving no topological endpoint at all.
Specify these additional rules before processing images:
- Whether endpoints created by image borders or masks are eligible.
- Whether short, disconnected fragments can be targets.
- How to choose between equally plausible candidates.
- Whether missing evidence produces a failure result rather than a coordinate.
2. Preserve the original image and coordinate system
Keep three separate representations: the original grayscale image, the binary edge map used for analysis, and a display overlay. Thicken only the display overlay. Dilation changes connectivity and moves apparent boundaries; it is not a harmless visualization step when its output feeds endpoint detection.
A practical preparation sequence is:
- Decode the image into a known grayscale pixel format.
- Record its width, height, crop origin and any scaling already applied.
- Apply only the smoothing needed to suppress unstable fine texture.
- Extract edges using documented, fixed settings for the initial evaluation.
- Preserve that undilated edge map before any thinning or pruning.
Do not assume an edge detector always returns a perfect single-pixel curve. Inspect bends, diagonal sections, weak transitions and closely spaced boundaries at pixel scale.
Resizing also changes the meaning of your tolerance. A five-pixel allowance in a reduced image is not five pixels in the original image. The guide to antialiasing during downsampling and image warping explains why resampling can change fine structures before detection even begins.
Use coordinates consistently: image arrays usually address a pixel as row, column, while geometry commonly uses x, y. Store the selected result in one documented convention.
3. Extract candidates from a thin connectivity graph
Apply topology-preserving thinning if the edge map contains thick runs or small blocks. Thinning should reduce width without deliberately joining separate components. Keep its output separate because it can shift or shorten the endpoint you ultimately want to measure.
For a clean one-pixel curve, an endpoint has one connected neighbor. Using eight-neighbor connectivity allows diagonal curves to remain connected.
Raw neighbor counting is only a starting point. Near a right-angle bend, diagonal adjacency can create a shortcut across the corner. That can make an ordinary curve pixel look like a junction.
One practical graph convention is to retain horizontal and vertical connections, but suppress a diagonal connection when its two pixels already connect through a shared foreground pixel horizontally and vertically. This removes redundant corner shortcuts while preserving a genuinely diagonal run. Apply the rule consistently throughout component labeling and branch tracing.
The extraction sequence is:
- Thin the analysis edge map where necessary.
- Build the pixel graph using your chosen connectivity convention.
- Label connected components on that graph.
- Mark pixels with graph degree one as endpoint candidates.
- Trace each candidate along its component to identify branch length and nearby junctions.
- Save the component identifier and trace with each candidate.
A closed loop has no degree-one pixels. A junction can have several branches and therefore several endpoints. Neither case is automatically an error; the feature specification determines whether it is acceptable.
4. Reject noise and short branches without deleting the target
Use several weak tests together rather than treating one threshold as proof of a real endpoint.
Component length: reject components that are too short to represent the intended feature. As an initial experiment, you might remove fragments shorter than 12 pixels. That value is a tuning example, not a general limit. It is wrong when the target itself can be shorter.
Short terminal branches: trace from each endpoint until reaching another endpoint or a junction. For a small spur attached to a longer curve, remove the terminal trace but retain the junction. Rebuild degrees after pruning because the graph has changed.
Measure trace length along the graph rather than by counting pixels alone:
A starting spur limit of 4 pixels may remove small protrusions, but it can also remove a genuine short feature. Review every removed branch on representative images before accepting that threshold.
Border and mask exclusion: mark candidates near image boundaries or excluded regions. A cropped curve can look exactly like an open endpoint. Use a guard distance based on the processing neighborhood and the required measurement region.
Original-image support: require a plausible intensity transition along the retained branch. A binary fragment without corresponding grayscale evidence is a poor measurement target.
A local neighborhood imbalance score can help propose candidates, but it also responds to tight corners. Use it as supporting evidence, not as a replacement for connectivity. A genuine corner normally continues in two directions along the graph; an open endpoint does not.
The related guide to separating cracks from image noise addresses the upstream segmentation problem. Endpoint ranking cannot repair an edge map that repeatedly breaks the intended feature.
5. Rank endpoints and components separately
For an image with width W and height H, use the center of its pixel-coordinate extent:
Squared distance gives the same ordering as Euclidean distance without requiring a square root for every comparison.
Consider a 640 × 480 image. Its center is (319.5, 239.5). Suppose one component runs vertically through the center region, while another starts slightly to its right.
| Measurement | Component A | Component B |
|---|---|---|
| Closest component pixel | (320, 240) | (326, 240) |
| Closest component distance squared | 0.5 | 42.5 |
| Nearest valid endpoint | (320, 190) | (326, 240) |
| Nearest endpoint distance squared | 2450.5 | 42.5 |
The endpoint calculation for component B is:
Selecting the nearest endpoint returns component B. Selecting the nearest component first returns component A, whose nearest endpoint is much farther away.
Rank only candidates that passed the validity checks. Keep the runner-up distance and candidate identifiers in the result record. If small image changes repeatedly swap the leading candidates, classify the selection as ambiguous rather than hiding the instability behind a deterministic tie-break.
6. Refine the selected endpoint against grayscale evidence
The skeleton provides a candidate location, not an automatically accurate physical measurement. Its terminal pixel depends on thresholding, smoothing and thinning decisions.
Take a small patch around the candidate from the original image. Trace backward along approximately 6–12 graph pixels to estimate the local tangent, using fewer points if the curve bends sharply. Then inspect grayscale evidence along and across that direction.
Refinement must match the feature definition:
- For a terminating line, fit a local intensity model that includes its termination along the tangent.
- For an open boundary, verify that the transition continues behind the candidate and ends ahead of it.
- For a stripe tip with a closed outline, measure the tip from the outline geometry or grayscale model instead of demanding a graph endpoint.
Fitting a straight line to edge pixels can improve the boundary position perpendicular to the line. It does not, by itself, determine where that line ends. The tangential endpoint needs its own measurement model.
The guide to subpixel peak localization for spacing measurements explains a related distinction between locating a sampled response and assigning a physically meaningful coordinate. Its peak-fitting approach is not a direct substitute for an endpoint model.
Retain both the raw candidate and refined coordinate. If refinement moves the point outside the expected neighborhood, reject the measurement for review instead of accepting the new position silently.
7. Verify the five-pixel tolerance on held-out images
Define the acceptance metric before tuning. An allowance of five pixels horizontally and vertically means:
This is not the same as a radial error limit of five pixels. A point displaced by five pixels on both axes satisfies the axis-wise rule, but its radial error is approximately 7.1 pixels.
Establish reference coordinates using a consistent endpoint definition. If repeated annotations disagree substantially, resolve that ambiguity before judging the algorithm.
Separate parameter-tuning images from validation images. Include weak edges, bright backgrounds, nearby corners, short branches, near-tied candidates and examples with no valid target. Also test image borders and deliberately cropped features.
Record at least:
- Correct component selection and correct endpoint selection.
- Absolute horizontal and vertical errors.
- Missed detections, false detections and ambiguous outcomes.
- Maximum observed error, not only the mean.
- Sensitivity to exposure, focus and edge thresholds.
Repeated frames of one stationary part test repeatability. Different parts, orientations and contrast conditions test whether the rule generalizes. Neither dataset alone establishes both.
To translate pixel error into object-space error, use measured image coverage. For example, 80 mm across 1600 pixels gives 0.05 mm per pixel. Five pixels then represents 0.25 mm on that axis, assuming a planar view with sufficiently uniform scale.
8. Choose acquisition hardware and check integration limits
Stable acquisition usually matters more than a more elaborate endpoint score. Compare area scan cameras when you need host-based image access and control over the processing pipeline. Use the camera finder to narrow the acquisition options after defining coverage, motion and contrast requirements.
The LS-CMR-0166 is an area scan candidate for evaluation. Confirm software compatibility and access to the required pixel format before selecting it for your pipeline.
- Sensor format
- 1/1.7"
- Interface
- USB3
- Resolution
- 12 MP
- Shutter
- Rolling
Consider smart cameras and vision sensors when on-device inspection is preferred. Check the actual inspection tools, scripting access and export options; an edge tool does not necessarily expose skeleton connectivity or custom branch pruning.
The LS-SMC-0063 is a smart-camera candidate. Its category alone does not establish support for this endpoint-processing sequence.
- Interface
- GigE
- Resolution
- Up to 3 MP
Before ordering or commissioning, complete this short checklist:
- Target definition: distinguish an open endpoint from a closed stripe tip.
- Selection rule: document endpoint-first or component-first ranking.
- Image access: confirm grayscale data, coordinate conventions and crop offsets.
- Processing: preserve undilated edges and log pruning decisions.
- Measurement: refine against the original image, not a display overlay.
- Validation: test independent images against the stated axis-wise tolerance.
- Failure handling: return an explicit invalid or ambiguous status when evidence is insufficient.
Start the camera configuration process with your field coverage, motion conditions and image-access requirements. For help selecting acquisition hardware, send those requirements and representative images through application support.
Questions
Should endpoint detection use a dilated edge image?
Use the undilated edge map for topology and keep any thickened version only for display. Dilation can merge nearby curves, close small gaps and turn narrow branches into wider regions. If thinning is required, preserve the original grayscale image so the final coordinate can be checked against real intensity evidence.
Is the nearest endpoint always on the nearest edge component?
They are different selection rules. Endpoint-first ranking compares valid endpoints directly. Component-first ranking first chooses a connected curve using a defined component-distance metric, then searches that curve for an endpoint. A curve passing through the center can have endpoints farther away than those of another curve.
Can corners be mistaken for edge endpoints?
They can, especially when detection uses neighborhood imbalance, curvature or raw neighbor counts. Use a consistent connectivity graph and trace the curve through each candidate. A corner usually has continuation on both sides; an open endpoint has only one retained continuation after topology cleanup.
What should happen when the selected component has no endpoint?
Check whether the feature should actually have an open boundary. A closed object outline or stripe tip may have no topological endpoint. Other possibilities include excessive gap closing or neighboring structures merging together. Return a missing-endpoint status unless the specification defines another valid measurement method.
Does subpixel refinement guarantee five-pixel accuracy?
Subpixel fitting can improve a coordinate only when the underlying feature model and image evidence support it. Demonstrating a five-pixel requirement needs reference annotations, independent validation images and the correct error metric. Wrong-component selection, unstable segmentation and ambiguous physical endpoints remain failures even with decimal-valued coordinates.

