Publications / 2025 / Fast Shape Retrieval Based on Differential Chain Code Descriptor and Fuzzy Contour Matching

Fast Shape Retrieval Based on Differential Chain Code Descriptor and Fuzzy Contour Matching

Wei Pan, Li Ning, Tang Wenming, Lu Lei
Computer-Aided Design and Applications, 23(2):222-233
Multi-target matching experiment: model contours in the left column and test images containing several rotated parts. Fig. 10 of the paper.

In one sentenceEncodes how a contour turns as a short code sequence and matches it in segments so noise cannot spread, giving lower mean distance than Halcon and the Smart baseline on all eight test images.

The problem

Matching a known shape in an image is a basic step in industrial inspection and measurement. Feature-based methods such as SIFT, SURF and ORB describe key points, but they perform poorly under heavy noise, blur or strong viewpoint change, and the many feature points make them computationally intensive. Template-based methods compare image patches directly, which is costly over large search spaces and sensitive to scale, rotation and illumination. This paper therefore matches contours, using the structural and topological information they carry.

A chain code turns a contour into a sequence of direction changes, so two similar shapes produce similar sequences and matching becomes sequence comparison. The catch is that the sequence is ordered: one noise point shifts the correspondence of the points after it, and the longer the code, the more points are misaligned and the larger the error.

Point set P with a noise point p6 lifted above an otherwise straight line, point set Q below it, and four number sequences: the differential codes of P with 1, 2, 1 at the noise point, the all-zero codes of Q, the matching cost array, and the sliding-window result.
P is the template point set and Q the point set to be matched. A single noise point (p6) in P turns three consecutive differential codes into 1, 2, 1. Sliding the short code of Q along P gives the matching cost array, which a sliding window of size 3 then processes. Fig. 6 of the paper.

How it works

The method first turns each contour into an ordered, evenly spaced point set and encodes it as differential chain codes. It then matches the local contour against the model in short segments, so that a noise point only disturbs the segment it falls in, and finally checks each candidate position geometrically.

  1. Extract, smooth and resample the contour. Run-length encoding of the binary image, a connectivity analysis and a depth-first search give the outer and inner contours, with points about 1 pixel apart. The points are smoothed with the mean of their neighbours and then sampled at a fixed distance, which reduces their number while keeping the shape.
  2. Encode the turning angles. Instead of computing an ordinary chain code first, each point and its two neighbours form two vectors, and the rotation angle between them is quantised into a differential code. The contour becomes a code sequence that does not change when the shape is translated.
  3. Match short segments. The code of the local contour is divided into short segments. Each segment slides along the longer model code, and at every position the cost is the sum of absolute code differences. Each segment produces one cost array as long as the model code.
  4. Combine the costs and pick candidates. A sliding window writes the minimum cost inside the window into its centre, which absorbs small shifts of the best position. The segment cost arrays are then combined into one total cost. The total forms valleys; positions with small cost are kept, and the centre of each valley becomes a candidate starting position.
  5. Verify with SVD. Fuzzy matching can also return look-alike or wrong positions. For each candidate, the local points are paired with the model points, a transformation is estimated by singular value decomposition (SVD), and the mean distance between the transformed pairs scores the match. The positions with the smallest mean distance are kept. An optional ICP step refines the final alignment.
Left: three points p1, p2, p3 joined by two green arrows, and the angle theta between vectors p1p2 and p2p3. Right: an octagon divided into eight sectors at plus and minus 22.5, 67.5, 112.5 and 157.5 degrees, labelled with codes 0 to 4.
How a differential code is computed: (a) the angle θ between the vectors p₁p₂ and p₂p₃; (b) the eight angle sectors and their codes. Fig. 3 of the paper.
A local point set is split into Partial 1 and Partial 2; each is matched against a dotted model point set inside a green bracket, producing costarray1 and costarray2.
Segmented fuzzy matching: the local point set is split into parts, and matching each part against the model point set gives one cost array per part. Fig. 4 of the paper.

Results

The test material is CAD drawings captured with the SmartFlash-2020 one-click measurement sensor, an instrument for large flat products with a measurement range of up to 300 × 200 mm. Each original image was rotated clockwise by 30°, 60°, 90°, 120° and 150° and matched against the original, and further experiments test matching under multi-target interference. For the quantitative comparison, Table 1 reports the mean distance and standard deviation between the matched contour and the ground truth on eight test images, for Halcon, a baseline referred to as Smart, the proposed method, and the proposed method followed by ICP.

The proposed method has the lowest mean distance of the three methods on every image; on test image 2, for example, it is 0.426, against 1.027 for Halcon and 0.715 for Smart. ICP refinement lowers the mean distance on seven images and leaves it unchanged on image 6 (0.376), with the largest reductions on images 8, 5 and 4 (0.601 → 0.372, 0.581 → 0.391 and 0.578 → 0.419). As future work, the authors plan more advanced smoothing, an improved fuzzy matching algorithm and the use of deep learning.

Eight rows of part cross-sections. The first column shows each original drawing in black; the other five columns show rotated copies with the matched contour overlaid in blue.
Matching results on rotated images: each row is one part, with the original drawing in the first column and rotated copies with the matched contour (blue) in the others. Fig. 11 of the paper.
Three rows of part drawings. Each row starts with one large profile drawing, followed by three scenes that each contain several different profiles at various rotations.
Multi-target matching results: scenes that contain several different parts at various rotations. Fig. 10 of the paper.

Cite

@article{wei2025fast,
  title={Fast Shape Retrieval Based on Differential Chain Code Descriptor and Fuzzy Contour Matching},
  author={Wei, Pan and Ning, Li and Wenming, Tang and Lei, Lu},
  journal={Computer-Aided Design and Application},
  volume={23},
  number={2},
  pages={222--233},
  url={https://www.cad-journal.net/files/vol\_23/CAD\_23(2)\_2026\_222-233.pdf},
  year={2025},
  doi={10.14733/cadaps.2026.222-233}
}
Type
Article Journal
Topic
Computational Design
Venue
Computer-Aided Design and Applications, 23(2):222-233
Year
2025
DOI