# Enhanced Curvature-Based Fabric Defect Detection:
## 3 Curvature Algorithm
### Discrete Curvature Algorithm  
Discrete curvature is a mathematical approach used to measure the curvature in an image by employing discrete techniques. It calculates the change in direction of individual pixels and aggregates these changes to form a continuous curvature measurement. Traditional methods for calculating discrete curvatures have relied on finite difference schemes; however, these methods often produce spurious oscillations along horizontal and vertical lines due to their dependence on grid values. Before applying the algorithm that utilizes these formulas, edge detection and contouring operations must first be performed. The contours derived from these processes are subsequently used to execute the discrete curvature function, which calculates the appropriate curvature values. Figure 2: Defect data-set type hole, none, needle break, Iycra, may (**left** to **right**). The methodology involves discretizing a continuous level line, where each level line is represented as a polygon defined by its ordered vertices. For simplicity, and to reduce dependence on specific variables, a level line is generally denoted as \(\sum=P_{j}(x_{j},y_{j})\mid j=0,1,\ldots,N\), with the condition that \(P_{0}=P_{N}\). Here, each vertex \(P_{j}\) represents a point in the plane with coordinates \((x_{j},y_{j})\). At any vertex \(P_{j}\), the curvature \(\kappa(P_{j})\) can be calculated as the inverse of the constrained radius. More precisely, for each \(j\in 0,1,\ldots,N\), three consecutive points, \(P_{j-1}\), \(P_{j}\), and \(P_{j+1}\), define a triangle. The radius \(r_{j}\) of the circle inscribed in this triangle is then computed, yielding the (signed) discrete curvature [14]. The (signed) discrete curvature at \(P_{j}\) is given by the following:  
\[K(P_{j})\ =\pm 1/r_{j}. \tag{1}\]  
The discrete curvature at point \(P_{j}\) is given as follows:  
\[K(P_{j})\ =\frac{-2 sin\theta_{j}}{\|P_{j}P_{j-1}\|}=\frac{-2 sin(det(P_{j}P_{j-1} ),P_{j}P_{j+1})}{\|P_{j-1}P_{j}\|\|P_{j}P_{j+1}\|\|P_{j-1}P_{j+1}\|}. \tag{2}\]  
where \(\theta_{j}\angle(P_{j}P_{j-1}P_{j}P_{j+1})\) is the angle and the numerator of the right side contains the term. \[det(P_{j}P_{j-1}P_{j}P_{j+1})\ =det( \begin{matrix}x_{j-1}-x_{j}&x_{j+1}-x_{j} \\ y_{j-1}-y_{j}&y_{j+1}-y_{j}\end{matrix} ). \tag{3}\]  
The center of the circumscribed circle of the triangle is \(C\) and \(\theta_{j}=\angle(P_{j}P_{j+1},P_{j}C)\). Since point \(C\) is on two perpendicular bisectors, by the cosine theorem,  
\[r_{j}^{2}=r_{j}^{2}+r_{+}^{2}-2r_{j}^{2}r_{+}^{2}cos(\theta). \tag{4}\]  
The distance between consecutive vertices \(P_{j}\) and \(P_{j+1}\) is denoted as \(r_{+}=|P_{j}P_{j+1}|\). This can be simplified as follows:  
\[r_{j}cos(\theta)=\frac{\|P_{j}P_{j+1}\|}{2}. \tag{5}\]  
where \(r_{j}\) is the radius of the inscribed circle, and \(\theta\) is the angle formed by the vertices. Additionally, the following relationship between the radii can be derived:  
\[r_{j}^{2}=r_{j}^{2}+r_{-}^{2}-2r_{j}^{2}r_{-}^{2}\cos(\theta+\theta_{j}), \tag{6}\]  
where \(r_{-}=|P_{j-1}P_{j}|\) represents the distance between the previous pair of vertices, \(P_{j-1}\) and \(P_{j}\). Simplifying further, we have the following:  
\[r_{j}cos(\theta+\theta_{j})\ =\ \frac{\|P_{j-1}P_{  
If we combine the law of cosine with the last equation, we obtain  
\[\frac{1}{K(P_{j})}=r_{j}=\frac{\|(P_{j-1})(P_{j+1})\|}{2|sin(\theta_{j})|}. \tag{11}\]  
The last equality of the proposition comes from the vector product property. \[det(P_{j}P_{j-1}P_{j}P_{j+1})\ =r_{+}r_{-}sin(\theta_{j}). \tag{12}\]  
In the initial stage, the defective fabric image is captured using the proposed setup, as illustrated in Figure 3. As a pre-processing step, the Canny edge detection algorithm is applied, as depicted in Figure 4. The resulting edges are utilized as sub-contours within the contour algorithm. Following this, curvature values are computed using these sub-contours and 3-point structures within the discrete curvature function.