# Research on O-ring Dimension Measurement Algorithm Based on Cubic Spline Interpolation
## 3 O-Ring Dimension Measurement Algorithm Design
### Pixel-Level Edge Algorithm Based on Noise-Resistant Mathematical Morphology  
A morphologically based whole-pixel edge detection algorithm that compared and analyzed through traditional edge detection algorithms was adopted. Morphology was described with the help of the language of set theory and was mainly applied in image processing, such as in image refinement, pixelation, edge detection, noise removal, etc. It is one of the most widely used techniques in image processing. The basic operations of morphology include erosion, expansion, open operations, and closed operations [8]. The corrosion operation on A using S is denoted as \(A\mathfrak{S}=\left\{\mathsf{z}|(S)_{z}\subseteq A\right\}\), corrosion can dissolve the boundary of an object. When selecting an appropriate size and shape of structural elements, it is possible to filter out all noise points that do not fully contain the structural elements. The expansion operation using S is denoted as \(A\oplus s=\left\{\mathsf{z}|\left(\hat{S}\right)_{z}\cap A\
eq\varphi\right\}\). In contrast to erosion, expansion expands the boundaries of objects, and is often used to bridge the same objects in an image that would otherwise be broken apart [9]. Both open and closed operations are compounded by corrosion and expansion; the open operation is corrosion followed by expansion, while the closed operation is expansion followed by corrosion. The open operation on A, using the structure element S, is denoted as \(A\circ S\) and can be expressed as \(A\circ S=\left(A\Theta S\right)\oplus S\). In general, the on operation makes the contour of the image smooth, breaks narrow connections and eliminates fine burrs, and the on-operation filters noise without significantly affecting the shape and contour of an object. The closed operation on A using structure element S is denoted as \(A\bullet S=\left(A\oplus S\right)\Theta S\). The closed operation also smooths the contour, but in contrast to the open operation, it usually bridges narrow interruptions and fills small holes [10]. These four basic operations are the basis for morphological edge detection [11]. The basic idea is to select the appropriate elements to perform mathematical morphological operations on a target image, and subtract the result from the original image to obtain the edge of the image. Let the image be represented by \(A\), \(S\) is a suitable structural element; first let \(A\) be corrupted by \(S\) and then let image \(A\) be the difference with it, then inner edge image \(D_{1}\) is obtained. \[D_{1}=  
The above morphological operations are combined for the suppression characteristics of different noises. The four morphological operations are combined and applied to edge detection to obtain a noise-resistant mathematical morphological edge detection algorithm, and can be expressed as Equation (6).  
\[R=(A\circ S)\oplus S-(A\bullet S)\Theta S \tag{6}\]  
Using mathematical morphology for image processing, in addition to the flexible combination of the four basic operations, different structural elements can also have an impact on edge detection [13]. Moreover, for the extraction of edges using expansion etching, a structural element will only significantly work on edges that are perpendicular to it. Therefore, we used a set of four-direction structure elements as morphological structure elements, as shown in Figure 2.  
(a), (b), (c), and (d) are used as structural elements, respectively, in the noise-resistant mathematical morphology edge detection algorithm. After four structure elements are calculated, the four structures are summed with average weights to obtain the final processed image. The expression for this is Equation (7).