Machine Vision Measurement of Straight Spur Gears Using MATLAB Image Processing

In modern mechanical transmission systems, straight spur gears are indispensable components for power and motion transfer. Their manufacturing precision directly impacts the performance and reliability of equipment. Traditional contact measurement methods, such as single-flank and double-flank gear testers or universal gear measuring instruments, are accurate but expensive and require skilled operators. Non-contact measurement based on machine vision offers a low-cost, efficient, and flexible alternative that can be integrated into online inspection. In this work, I present a comprehensive approach to measure the key parameters of straight spur gears — including hub hole diameter, addendum circle diameter, dedendum circle diameter, number of teeth, and module — using MATLAB image processing techniques. The method is validated on six different straight spur gears, and the results demonstrate high accuracy and practical applicability.

Measurement System Setup

The measurement system consists of a CMOS camera (model JHSM1400, 14 MP, 1/2.3-inch sensor), a USB2.0 interface, a suitable lens, and an image acquisition card. The gear to be measured is placed on a flat platform under controlled lighting conditions. All image processing and parameter calculation are implemented in MATLAB. The system captures color images of the straight spur gears, which are then processed to extract dimensional information.

Camera Calibration

To convert pixel dimensions into real-world millimeters, I calibrated the camera using a reference object of known length. A standard workpiece with length \(L\) (in mm) is imaged, and its contour is detected. The number of pixels \(N\) spanning this length is counted. The pixel resolution \(L_p\) (mm/pixel) is then calculated as:

$$
L_p = \frac{L}{N}
$$

This simple yet effective method is sufficient for planar measurements where the object plane is parallel to the image sensor. Table 1 summarizes the calibration parameters used for all subsequent gear measurements.

Table 1. Camera calibration data
Parameter Value
Reference length \(L\) (mm) 50.00
Corresponding pixel count \(N\) 1024
Pixel resolution \(L_p\) (mm/pixel) 0.048828

Image Preprocessing

Raw RGB images contain redundant color information that slows processing. I first convert the image to grayscale using MATLAB’s rgb2gray function. Then, median filtering is applied to suppress noise while preserving edges. A 3×3 median filter effectively removes salt-and-pepper noise that often appears in industrial images.

Binary thresholding separates the gear region from the background. The Otsu algorithm, implemented via graythresh, determines an optimal threshold \(T\). The binary image \(b(x,y)\) is obtained by:

$$
b(x,y) = \begin{cases}
1 & \text{if } g(x,y) > T \\
0 & \text{if } g(x,y) \le T
\end{cases}
$$

where \(g(x,y)\) is the grayscale value at pixel \((x,y)\). This step produces a clear binary image where the gear appears as black (0) and the background as white (1), or vice versa depending on the lighting.

Gear Parameter Measurement

Hub Hole Diameter

The hub hole of straight spur gears is a critical dimension for shaft fitting. The measurement procedure is as follows:

  1. Connected component analysis: Using bwlabel with 8-connectivity, I identify all regions in the binary image. The gear body appears as a large black region, and the hub hole appears as a white (or black, depending on inversion) region inside the gear body. There may be small spurious regions due to noise; these are removed by area filtering, keeping only the two largest regions.
  2. Isolate the hole region: Subtract the filled gear region from the original binary image to extract only the hub hole.
  3. Edge detection: Apply the Canny edge detector (edge function) to obtain the hole boundary.
  4. Compute diameter: The bounding box of the hole contour is calculated via regionprops(..., 'BoundingBox'). If the bounding box has width \(w\) and height \(h\) in pixels, the hole diameter \(D_{\text{hole}}\) in millimeters is:

$$
D_{\text{hole}} = \frac{w + h}{2} \times L_p
$$

Table 2 shows the measured hub hole diameters for six straight spur gears.

Table 2. Hub hole diameter measurement results
Gear ID True value (mm) Measured value (mm) Absolute error (mm)
1 10.000 10.0978 0.0978
2 12.000 12.0103 0.0103
3 6.000 6.0492 0.0492
4 7.000 6.9905 0.0095
5 5.000 5.0677 0.0677
6 12.000 11.9874 0.0126

Addendum and Dedendum Circle Diameters

These are the most important geometry parameters for straight spur gears. The procedure involves:

  1. Extract single-pixel outer contour: Starting from the first black pixel in the filled gear image, I trace the outer boundary using 8-neighborhood chain code. This yields a set of contour points \((x_i, y_i)\).
  2. Find gear center: The centroid of the outer contour is computed via regionprops(..., 'Centroid'), which serves as the gear center \((x_c, y_c)\).
  3. Build distance vector: For each contour point, its Euclidean distance to the center is calculated:
    $$d_i = \sqrt{(x_i – x_c)^2 + (y_i – y_c)^2}$$
    This forms the vector \(\mathbf{D}\) of length equal to the number of contour pixels.
  4. Classify addendum points using neural network: I train a BP neural network to separate addendum points from dedendum points. First, a random subset of 2000 distances from \(\mathbf{D}\) is taken as \(\mathbf{DP}\). The true addendum circle diameter in pixels (from the known nominal value) is used to create a binary target vector \(\mathbf{DT}\): if \(d_i / D_{\text{addendum\_pixel}} > 0.96\), the point is classified as addendum (1); otherwise dedendum (0). The neural network (single hidden layer, 10 neurons) is trained with newff and train using \(\mathbf{DP}\) as input and \(\mathbf{DT}\) as target. After training, the entire distance vector \(\mathbf{D}\) is simulated to obtain outputs \(\mathbf{RESULT}\). A threshold of 0.62 converts \(\mathbf{RESULT}\) into binary classification. The coordinates corresponding to value 1 are the addendum points.
  5. Circle fitting: Using the identified addendum points, I apply least-squares circle fitting to compute the addendum circle radius \(R_a\) in pixels. The addendum diameter is:
    $$d_a = 2 R_a \times L_p$$
    The same process is repeated for dedendum points to obtain \(d_f\).

Table 3 lists the measured addendum and dedendum diameters for the six straight spur gears.

Table 3. Addendum and dedendum circle diameters
Gear ID True \(d_a\) (mm) Measured \(d_a\) (mm) Error \(d_a\) (mm) True \(d_f\) (mm) Measured \(d_f\) (mm) Error \(d_f\) (mm)
1 30.000 29.9219 0.0781 23.250 23.3644 0.1144
2 27.000 26.9269 0.0731 20.250 20.4645 0.2145
3 24.000 23.9704 0.0296 17.250 17.5143 0.2643
4 21.000 20.9375 0.0625 14.250 14.4185 0.1685
5 18.000 17.9079 0.0921 11.250 11.2553 0.0053
6 38.000 37.9264 0.0736 29.000 29.2702 0.2702

Number of Teeth

To count the teeth of straight spur gears, I first extract the addendum point image (binary, with white pixels representing addendum points). A morphological dilation operation using a disk structuring element of radius 10 connects adjacent addendum points into distinct blobs, each corresponding to one tooth. Then, I apply 8-connected component labeling (bwlabel) and count the number of connected components, which gives the tooth count \(z\). This method is robust against noise and partial occlusion near the root. As shown in Table 4, all six straight spur gears were correctly identified.

Table 4. Tooth count measurement
Gear ID True \(z\) Measured \(z\) Error
1 18 18 0
2 16 16 0
3 14 14 0
4 12 12 0
5 10 10 0
6 17 17 0

Module Calculation

For standard straight spur gears, the module \(m\) is derived from the addendum circle diameter and the number of teeth:

$$
m = \frac{d_a}{z + 2h_a^*}
$$

where \(h_a^* = 1\) is the addendum coefficient. Using the measured addendum diameter and the correctly counted tooth number, I compute the module for each gear. Table 5 presents the results. The maximum absolute error is 0.0077 mm, well within typical engineering tolerances.

Table 5. Module measurement results
Gear ID True \(m\) (mm) Measured \(m\) (mm) Absolute error (mm)
1 1.500 1.4961 0.0039
2 1.500 1.4959 0.0041
3 1.500 1.4981 0.0019
4 1.500 1.4955 0.0045
5 1.500 1.4923 0.0077
6 2.000 1.9960 0.0040

Graphical User Interface

To facilitate practical use, I developed a MATLAB GUI that integrates all processing steps. The interface allows the user to load an image of a straight spur gear, view intermediate results (e.g., binary image, contour, classified addendum/dedendum points), and display the final parameter measurements. Figure 1 (shown earlier in the article) illustrates the GUI layout and the measurement result for a gear with a pitch circle diameter of 34 mm.

Conclusion

In this study, I have presented a complete machine vision method for measuring the essential parameters of straight spur gears using MATLAB image processing. The key contributions include:

  • A robust hub hole measurement via bounding box of the hole contour.
  • A novel classification approach using a BP neural network to separate addendum and dedendum points from the gear outer contour, enabling accurate circle fitting via least squares for addendum and dedendum diameter determination.
  • Tooth counting by morphological dilation of addendum points and connected component analysis, which achieved 100% accuracy for all six test gears.
  • Module calculation using the standard addendum circle formula.

The measurement errors for hub hole diameter ranged from 0.0095 mm to 0.0978 mm; for addendum diameter from 0.0296 mm to 0.0921 mm; for dedendum diameter from 0.0053 mm to 0.2702 mm; and for module from 0.0019 mm to 0.0077 mm. These values are acceptable for many industrial applications and demonstrate the feasibility of using low-cost machine vision systems for straight spur gear inspection. Future work may extend the method to helical gears and incorporate sub-pixel edge detection to further improve accuracy.

Scroll to Top