In my research, I have developed a comprehensive method for measuring the parameters of a straight spur gear by leveraging the power of MATLAB image processing. The entire workflow begins with a machine vision system that captures the gear image, followed by a series of digital processing steps including grayscale conversion, noise removal, and binarization. I then apply an 8-neighborhood search to locate and remove the gear hole region, after which the Canny operator is used for edge detection. The diameter of the gear hole is determined by calculating the dimensions of the smallest bounding rectangle that contains the hole contour. Subsequently, I obtain a single-pixel outer contour of the gear through an 8-neighborhood boundary tracking method. The crucial step of classifying the outer contour points into addendum (tooth tip) and dedendum (tooth root) positions is accomplished using a neural network. With these classified points, I apply the least squares circle fitting method to compute the diameters of the addendum circle and the dedendum circle. The number of teeth is found by performing a dilation operation on the addendum or dedendum image and then counting the 8-connected regions. Finally, the module is calculated using the addendum circle formula. I developed a dedicated gear parameter measurement software and successfully tested it on six different straight spur gear samples. The comparison between measured and theoretical values confirms the rationality and accuracy of my proposed method.

Introduction
The straight spur gear is one of the most fundamental mechanical components used for transmitting motion and power in various machines. With the increasing demand for high precision and automation in modern equipment, accurate measurement of gear parameters becomes essential. Traditional mechanical measuring instruments such as single-mesh testers, dual-mesh testers, and universal gear testers have gradually evolved into more sophisticated CNC gear measuring centers, coordinate measuring machines, and laser gear measuring instruments. However, these advanced devices are often expensive and require skilled operators, limiting their widespread adoption in smaller enterprises. In parallel, research has focused on numerical models to predict gear wear, yet obtaining actual dimensional data remains critical for both quality inspection and wear assessment. Image-based non-contact measurement technology offers a promising alternative due to its simplicity, low cost, high efficiency, and potential for in-line monitoring. In this work, I present a complete solution for measuring key parameters of a straight spur gear using MATLAB image processing tools, covering hardware setup, calibration, preprocessing, and algorithms for extracting geometric features.
Hardware and System Setup
The measurement system I built consists of a JHSM1400 camera (14 MP, 1/2.3-inch CMOS sensor), a USB 2.0 interface for data transfer, appropriate lens, and an image acquisition card. A controlled lighting environment is used to ensure consistent image quality. The captured images are processed on a computer running MATLAB. The gear specimen is placed on a flat platform, and the camera is positioned perpendicular to the gear plane to avoid perspective distortion.
Camera Calibration
To convert pixel measurements into real-world dimensions, I performed camera calibration. I used a standard reference object of known length \(L\). After capturing its image, I detected its contour and counted the number of pixels \(N\) spanning the known length. The pixel-to-millimeter conversion factor \(L_p\) is given by:
$$L_p = \frac{L}{N}$$
This simple approach is sufficient for planar measurements where only two-dimensional information is needed. An example of the reference object image and its edge detection result is provided in the original paper. The calibration step ensures that all subsequent pixel-based dimensions can be converted into metric units.
Image Preprocessing
Grayscale Conversion: The raw image from the camera is an RGB image. While RGB provides rich color information, it also introduces large data volume and slows down processing. I converted the image to grayscale using the rgb2gray function in MATLAB, reducing each pixel from 24 bits to 8 bits. This step retains sufficient information for edge detection while significantly accelerating computation.
Noise Removal: Noise inevitably arises from the camera sensor or lighting conditions. Median filtering is particularly effective at removing salt-and-pepper noise while preserving edge sharpness. I applied the medfilt2 function to the grayscale image.
Binarization: To separate the gear from the background, I performed binarization using Otsu’s method to automatically determine the threshold \(T\). The binarized image \(b(x,y)\) is defined as:
$$
b(x,y) =
\begin{cases}
1 & g(x,y) > T \\
0 & g(x,y) \le T
\end{cases}
$$
where \(g(x,y)\) is the grayscale value. I used the graythresh function to compute \(T\) and im2bw to create the binary image. The resulting binary image clearly separates the gear body (white) from the background (black).
Parameter Measurement Methods
The core of my work lies in extracting four key parameters of a straight spur gear: the gear hole diameter, the addendum circle diameter, the dedendum circle diameter, the number of teeth, and the module. Each step is detailed below.
4.1 Gear Hole Diameter
Step 1: Connected Component Analysis. Using the bwlabel function with 8-connectivity, I identified all connected regions in the binary image. Initially, many small regions appeared due to noise or artifacts. I then used label2rgb to color each region for visualization. By examining a magnified view, I could see multiple colored spots that needed removal.
Step 2: Removing Small Regions. I computed the area of each connected component using regionprops and kept only the two largest regions. The larger region corresponds to the gear body filled with hole, while the smaller region is the gear hole itself. By subtracting the hole region from the gear body region, I obtained a filled gear image (Figure 7a in the original paper) and a pure hole image (Figure 7b).
Step 3: Edge Detection of the Hole. For the hole image, I applied the Canny edge detector using the edge function. Canny is preferred because of its low error rate, good localization, and suppression of false edges. The resulting edge image shows the boundary of the gear hole.
Step 4: Diameter Calculation. I computed the bounding box of the hole contour using regionprops and the property BoundingBox. Let the bounding box dimensions be \(w\) and \(h\) (in pixels). Then the equivalent pixel diameter \(D_{pixel}\) is the average of \(w\) and \(h\):
$$D_{pixel} = \frac{w + h}{2}$$
The actual diameter \(D_{hole}\) is:
$$D_{hole} = D_{pixel} \times L_p$$
Table 1 summarizes the measured hole diameters for six tested straight spur gear samples.
| Gear No. | Theoretical Value (mm) | Measured Value (mm) | Absolute Error (mm) |
|---|---|---|---|
| 1 | 10.0 | 10.0978 | 0.0978 |
| 2 | 12.0 | 12.0103 | 0.0103 |
| 3 | 6.0 | 6.0492 | 0.0492 |
| 4 | 7.0 | 6.9905 | 0.0095 |
| 5 | 5.0 | 5.0677 | 0.0677 |
| 6 (reference) | 12.0 | 11.9874 | 0.0126 |
4.2 Addendum and Dedendum Circle Diameters
Step 1: Single-Pixel Outer Contour Extraction. Starting from the filled gear image (hole removed), I scanned from top-left to bottom-right to find the first black pixel (gear body). From that point, I performed an 8-neighborhood clockwise boundary tracking to extract the single-pixel outer contour of the gear. This contour contains both addendum and dedendum points.
Step 2: Gear Center. I used regionprops with the property Centroid on the outer contour to obtain the gear center coordinates \((x_c, y_c)\). This center serves as the reference for distance measurements.
Step 3: Feature Vector Construction. Let the theoretical addendum diameter be \(d_a^{th}\). I computed the corresponding pixel value: \(d_a^{pix} = d_a^{th} / L_p\). I extracted all contour points and calculated their Euclidean distances to the gear center, forming a vector \(\mathbf{D}\). Using randperm, I randomly selected 2000 points from \(\mathbf{D}\) to create \(\mathbf{DP}\). I then divided each element of \(\mathbf{DP}\) by \(d_a^{pix}\) and applied a threshold of 0.96: values greater than 0.96 are labeled as 1 (addendum candidate), otherwise 0. This creates the target vector \(\mathbf{DT}\).
Step 4: Neural Network Classifier. I trained a BP (backpropagation) neural network using MATLAB’s Neural Network Toolbox. The input is \(\mathbf{DP}\) and the target is \(\mathbf{DT}\). After training (with 1000 epochs), I simulated the network on the full vector \(\mathbf{D}\) to obtain output \(\mathbf{RESULT}\). A threshold of 0.62 is applied: if \(\mathbf{RESULT}(i) > 0.62\), the point is classified as an addendum point; otherwise, it is a dedendum point. The indices of points classified as 1 are found using find, and their coordinates are stored.
Step 5: Circle Fitting Using Least Squares. Let the classified addendum points be \((x_i, y_i)\) for \(i=1,\dots,n\). The least squares circle fitting minimizes the sum of squared residuals:
$$
f(a,b,R) = \sum_{i=1}^{n} \left( \sqrt{(x_i – a)^2 + (y_i – b)^2} – R \right)^2
$$
The solution yields the center \((a,b)\) and radius \(R\) in pixels. The addendum diameter is then:
$$d_a = 2 R \times L_p$$
The same procedure is repeated for dedendum points to obtain \(d_f\). Tables 2 and 3 show the measurement results for six straight spur gear samples.
| Gear No. | Theoretical Value (mm) | Measured Value (mm) | Absolute Error (mm) |
|---|---|---|---|
| 1 | 30.0 | 29.9219 | 0.0781 |
| 2 | 27.0 | 26.9269 | 0.0731 |
| 3 | 24.0 | 23.9704 | 0.0296 |
| 4 | 21.0 | 20.9375 | 0.0625 |
| 5 | 18.0 | 17.9079 | 0.0921 |
| 6 (reference) | 38.0 | 37.9264 | 0.0736 |
| Gear No. | Theoretical Value (mm) | Measured Value (mm) | Absolute Error (mm) |
|---|---|---|---|
| 1 | 23.25 | 23.3644 | 0.1144 |
| 2 | 20.25 | 20.4645 | 0.2145 |
| 3 | 17.25 | 17.5143 | 0.2643 |
| 4 | 14.25 | 14.4185 | 0.1685 |
| 5 | 11.25 | 11.2553 | 0.0053 |
| 6 (reference) | 29.0 | 29.2702 | 0.2702 |
4.3 Number of Teeth
After extracting the addendum points (as described in Section 4.2, Step 4), I obtained a binary image showing only the tooth tips. I inverted this image and applied a morphological dilation operation using a disk structuring element of radius 10 pixels. The dilated image causes the isolated tip regions to merge into connected components. Using bwlabel with 8-connectivity, I counted the number of connected components, which directly equals the number of teeth \(z\). The result is exactly correct for all tested gears, as shown in Table 4.
| Gear No. | Theoretical Value | Measured Value | Error |
|---|---|---|---|
| 1 | 18 | 18 | 0 |
| 2 | 16 | 16 | 0 |
| 3 | 14 | 14 | 0 |
| 4 | 12 | 12 | 0 |
| 5 | 10 | 10 | 0 |
| 6 (reference) | 17 | 17 | 0 |
4.4 Module Calculation
The module \(m\) of a straight spur gear is derived from the addendum circle diameter \(d_a\) and the number of teeth \(z\). For standard gears with addendum coefficient \(h_a^* = 1\), the relationship is:
$$m = \frac{d_a}{z + 2h_a^*} = \frac{d_a}{z + 2}$$
Table 5 lists the module measurements for all six gears.
| Gear No. | Theoretical Value (mm) | Measured Value (mm) | Absolute Error (mm) |
|---|---|---|---|
| 1 | 1.5 | 1.4961 | 0.0039 |
| 2 | 1.5 | 1.4959 | 0.0041 |
| 3 | 1.5 | 1.4981 | 0.0019 |
| 4 | 1.5 | 1.4955 | 0.0045 |
| 5 | 1.5 | 1.4923 | 0.0077 |
| 6 (reference) | 2.0 | 1.996 | 0.004 |
Graphical User Interface
To make the measurement system user-friendly, I developed a graphical user interface (GUI) in MATLAB. The GUI displays the original image, intermediate processing steps (e.g., binarized image, edge detection, neural network classification) and the final numerical results. An example interface for a straight spur gear with a pitch circle diameter of 34 mm is shown in the original paper. The measured values are displayed in real-time, allowing operators to verify the results instantly.
Experimental Results and Discussion
I tested the proposed method on six straight spur gear samples with different sizes. The reference gear (No. 6) has a pitch diameter of 34 mm, while the others have pitch diameters of 27, 24, 21, 18, and 15 mm, numbered 1 through 5 respectively. Tables 1–5 summarize the measurement errors. The number of teeth was correctly identified for all gears, achieving zero error. The gear hole diameter had errors ranging from 0.0095 mm to 0.0978 mm. The addendum circle diameter errors were between 0.0296 mm and 0.0921 mm. The dedendum circle diameter errors ranged from 0.0053 mm to 0.2643 mm, with the largest error observed for gear No. 3 (0.2643 mm). The module errors were all below 0.008 mm, demonstrating high accuracy.
These experimental results validate that the image-based approach can reliably measure the parameters of a straight spur gear with sufficient precision for industrial inspection purposes. The largest error in the dedendum circle is likely due to the morphological differences between the theoretical and actual tooth root shape, as well as the limitations of the neural network classification near the root region. Nevertheless, the overall performance meets practical engineering requirements.
Conclusion
In this work, I have presented a comprehensive method for measuring the geometric parameters of a straight spur gear using MATLAB image processing. Key algorithms include:
- Gear hole diameter measurement via bounding rectangle of the hole contour.
- Addendum and dedendum circle diameters extracted using single-pixel contour tracking, neural network classification of contour points, and least squares circle fitting.
- Tooth count determined by morphological dilation and connected component analysis.
- Module calculated from the addendum circle diameter and tooth count.
I developed a dedicated software with a graphical interface and validated the method on six gears. The results show that the number of teeth is always correct, and dimensional errors are within hundredths of a millimeter for hole and addendum diameters, and within tenths of a millimeter for dedendum diameters. The module error is less than 0.01 mm. These accuracies are acceptable for common engineering measurement tasks. The proposed technique offers a cost-effective, non-contact, and efficient solution for straight spur gear inspection, with potential for integration into automated production lines.
