1 Introduction

Surface roughness is an important indicator of workpiece quality and greatly affects its fatigue strength, wear resistance, service life, and other characteristics. Therefore, efficient and high-precision detection of surface roughness is essential for modern engineering applications. Existing methods for measuring workpiece surface roughness include contact and non-contact processes. Contact methods suffer from drawbacks such as low efficiency, strict detection conditions, and susceptibility to damage to the measuring head. Non-contact methods include optical, ultrasonic, and visual measurements. Among non-contact measurement methods, visual measurement offers the advantages of lower costs and higher efficiency compared to optical and ultrasonic measurement methods [1, 2].

In machine vision-based methods, the roughness image of the workpiece surface is captured using a CCD camera. Texture feature parameters are then extracted from the image to determine the correlation between these features and roughness and create a model for predicting roughness in unknown samples [3, 4]. Texture extraction methods involve frequency- and spatial-domain analyses. Frequency domain-based approaches involve grayscale processing of the image followed by Fourier transform to determine the correlation between amplitude parameters and roughness in the frequency domain. This method is mainly used for samples with distinct texture characteristics [5]. When the surface features of samples are difficult to distinguish, the performance of texture extraction algorithms based on the frequency domain decreases. Texture extraction algorithms based on the spatial domain include non-statistical indicators that focus on extracting geometric structure features and statistical indicators that calculate histograms, grayscale variance, and grayscale co-occurrence matrix (GLCM) [6]. However, geometric feature indicators are not suitable for measuring the surface of samples processed through highly random machining processes such as grinding. Statistical indicators such as histograms and GLCM offer a wide application range and high measurement accuracy. As opposed to other statistical indicators, GLCM considers pixel brightness and the position information between pixel pairs. Therefore, it can comprehensively characterize the texture features of the sample surface. Liu et al. [7] proposed a method for measuring the roughness of deep hole surfaces by using the fusion of grayscale co-occurrence matrix and SVM (GLCM-SVM) and obtained high measurement accuracy and strong applicability for irregularly textured machined workpiece surfaces. Yi et al. [8,9,10,11] proposed a color difference algorithm based on RGB and a color image singular value entropy-based evaluation index to construct a grinding surface roughness prediction model to study roughness-related indicators within the mathematical structure of the image. Lu et al. [12] proposed the pure color energy index and the area index of the mixing area of two light sources to establish a corresponding relational model with roughness. To evaluate the surface roughness, Rifai et al. [13] proposed a convolutional neural network (CNN) by integrating feature extraction into the neural network without separate processing. They analyzed five loss functions to improve the prediction accuracy of the model. Tian et al. [14, 15] characterized surface roughness by calculating texture and shape features and demonstrated the feasibility of machine vision-based roughness parameter measurement. Nammi et al. [16] demonstrated the importance of considering workpiece orientation in machine vision-based roughness measurement by extracting image features from low-carbon steel milling samples at different angles. Patel et al. [17, 18] implemented a non-contact roughness measurement method for turning surfaces by using the grayscale co-occurrence matrix algorithm and a machine vision system for texture feature extraction. Jayabarathi et al. [19, 20] determined the correlation between surface roughness and laser speckle images by using He Ne and diode lasers and a camera. They extracted image contrast, correlation, energy, entropy, mean value, standard deviation, and other texture feature values and calculated the coefficient of determination. Patil et al. [21] proposed singular value decomposition for surface roughness detection to determine the correlation between the exponential decay function of the singular value of the speckle pattern and the roughness. Tootooni et al. [22] converted surface images into an undirected network graph without weights and used a regression model to calculate the correlation between the image Federer’s number and surface roughness, with a measurement error within 15%. Yi et al. [3] evaluated the metal surface roughness based on the sharpness of color images and established a correlation model between sharpness and roughness by considering the effect of the texture of the grinding surface on the sharpness. Zhang et al. [4] proposed a method based on inductive transfer learning that utilizes only the knowledge of the area index of the red–green mixing area to transfer simulation data and enables establishing a roughness prediction model with fewer training samples. In the case of insufficient training samples, this method achieves an average error of 12.57%. Liu et al. [23] proposed a color distribution statistical matrix and overlap index based on green and red color spaces. They established a correlation model between the overlap index and roughness. This measurement method yields high accuracy and has a wide measurement range. Wedyan et al.[24] proposed a virtual sample generation method to overcome the problem of small sample sizes in the diagnostic process. Olesen et al. [25] created the life ratio index based on actual faults and particle swarm optimization faults. They generated virtual samples and experimentally verified the accuracy of the life assessment model. Cui et al. [26] proposed a virtual sample generation method based on the generative adaptive fuzzy neural network for industrial testing process data and experimentally verified the feasibility of the method, providing a theoretical basis for online measurement of key performance indicators in industrial processes. Li et al. [27, 28] used different methods for facial virtual sample reconstruction and generated virtual samples based on facial structure, perturbation, sample distribution, and sample viewpoints to improve the facial recognition accuracy. Lu et al. [29] proposed an improved combination virtual sample classification method based on linear representation. They used an alternating minimization algorithm to optimize the objective function and improve the facial recognition accuracy.

In summary, research on non-contact roughness measurement methods has mainly focused on simple textures such as turning and milling. However, due to the higher complexity of ground surface textures compared to the surface finish of turning and milling, the detection accuracy is low when the number of samples is small. The virtual sample generation method, which is commonly used in fault diagnosis, life prediction, and face recognition, provides a new research direction for non-contact measurement of roughness. Therefore, in this paper, we proposed a workpiece surface roughness measurement method by using QR and SVM. The QR method is used to generate samples and expand the sample size, whereas SVM is used to establish a roughness prediction model for studying machined surface roughness measurement and analysis.

2 Material and method

2.1 QR decomposition

The original image is transformed into a grayscale image represented by a two-dimensional matrix. For a given training sample G(x,y), a reasonable sample G′(x′,y′) (also referred to as a virtual sample) is obtained by transforming T.

The QR decomposition algorithm is generally used to reconstruct virtual samples for facial recognition [30, 31]. This algorithm uses partial information from Q and R to construct virtual samples with certain differences from the original image, thereby increasing the effective features of possible changes in the image and expanding the training sample set. In this paper, the results of the collaborative representation of virtual samples and real samples were combined using weighted fusion, the optimal weight combination was selected, and the recognition accuracy was improved. The method of QR reconstruction weighted fusion is shown in Eqs. (1)–(4). First, QR decomposition is performed for Il and Ir of two pictures captured under the same rough surface.

$$I_{l} = Q_{l} \left( \begin{gathered} R_{l} \hfill \\ 0 \hfill \\ \end{gathered} \right) = Q_{l} R_{l}$$
(1)
$$I_{r} = Q_{r} \left( \begin{gathered} R_{r} \hfill \\ 0 \hfill \\ \end{gathered} \right) = Q_{r} R_{r}$$

In Eq. (1), Ql, Rl, Qr, and Rr are the matrices obtained by decomposing Il and Ir.

Using reconstruction coefficients to process the obtained matrices Ql, Rl, Qr, and Rr sparse reconstruction matrices are obtained; the calculation method is shown in Eq. (2).

$$Q_{l\omega } = Q_{{lN*\left( {N*\omega } \right)}}$$
(2)
$$R_{l\omega } = R_{{lN*\left( {N*\omega } \right)}}$$
$$Q_{r\omega } = Q_{{rN*\left( {N*\omega } \right)}}$$
$$R_{r\omega } = R_{{rN*\left( {N*\omega } \right)}}$$

In Eq. (2), Q, R, Q, and R are sparse reconstruction matrices, and ω is the reconstruction coefficient.

The reconstruction coefficient quantifies the information contained in a sparse reconstruction matrix containing the original samples. Different types of virtual samples can be generated by using different reconstruction coefficients. In this study, five reconstruction coefficients were used (0.2, 0.4, 0.6, 0.8, and 1.0) to generate various types of virtual samples, each representing different information levels. The method of obtaining left and right information graphs from the sparse reconstruction matrix is shown in Eq. (3).

$$I_{l\omega } = Q_{l\omega } \times R_{l\omega }$$
(3)
$$I_{r\omega } = Q_{r\omega } \times R_{r\omega }$$

In Eq. (3), I and I are the left and right information graphs, respectively.

For I and I, virtual samples after fusion are obtained, as shown in Eq. (4).

$$I_{\omega } = \frac{{I_{l\omega } + I_{r\omega } }}{2}$$
(4)

In Eq. (4), Iω is a virtual sample. When obtaining sparse reconstruction matrices, the left and right matrices use the same reconstruction coefficients; thus, the same weight is used to fuse the left and right information graphs during the calculation process. This method can generate 100 virtual samples from a set of 10 raw samples.

2.2 Sample image preprocessing and texture feature extraction methods

Efficient and accurate extraction of image texture features requires the use of appropriate image preprocessing techniques. Common preprocessing methods include image denoising and enhancement.

2.2.1 Image filtering

In the CCD image acquisition system, Gaussian noise is the predominant noise type affecting acquired images. Linear filtering methods effectively reduce Gaussian noise. Linear filtering can be categorized as mean filtering and Gaussian filtering. Gaussian filtering offers better noise reduction compared to mean filtering. The two-dimensional Gaussian filtering function is shown in Eq. (5).

$$g_{\sigma } \left( {x,y} \right) = \frac{1}{{2\pi \sigma^{2} }}e^{{ - \left( {x^{2} + y^{2} } \right)/\left( {2\sigma^{2} } \right)}}$$
(5)
$$\frac{{e^{{ - x^{2} /\left( {2\sigma^{2} } \right)}} }}{{\sqrt {2\pi } \sigma }}\frac{{e^{{ - y^{2} /\left( {2\sigma^{2} } \right)}} }}{{\sqrt {2\pi } \sigma }} = g_{\sigma } \left( x \right)g_{\sigma } \left( y \right)$$

In the equation, σ is the standard deviation.

Due to the symmetrical and interchangeable mathematical properties of two-dimensional Gaussian filtering functions, Eq. (5) can be written in the form of Eq. (6).

$$\left\{ \begin{gathered} g_{x} = g_{\sigma }{\prime} \left( x \right)g_{\sigma }^{{}} \left( y \right) \hfill \\ g_{y} = g_{\sigma }^{{}} \left( x \right)g_{\sigma }{\prime} \left( y \right) \hfill \\ \end{gathered} \right.$$
(6)

In the filtering operation, if σ is too small, two-dimensional Gaussian filtering will transform the image to perform a point operation, and the noise removal effect is not satisfactory. If σ is too large, Gaussian filtering will act like mean filtering. By analyzing the relationship between the output image edge gradient and the actual edge gradient, a one-dimensional filtering function can be obtained, as shown in Eq. (7).

$$\left\{ \begin{gathered} g_{x} = g_{\sigma }{\prime} \left( x \right)g_{\sigma }^{{}} \left( y \right) \hfill \\ g_{y} = g_{\sigma }^{{}} \left( x \right)g_{\sigma }{\prime} \left( y \right) \hfill \\ \end{gathered} \right.$$
(7)

2.2.2 Image enhancement

To enhance image contrast, adjustments need to be made based on its histogram, which is a statistical representation of the frequency of different grayscale levels in an image. For example, consider an image with four grayscale levels (0, 1, 2, and 3), with each grayscale level occurring 4, 3, 6, and 3 times, respectively, as shown in Fig. 1.

Fig. 1
figure 1

Histogram image

Histogram equalization [32, 33] is a common image enhancement technique used to improve contrast, especially in images with a small grayscale range. It can handle images with uneven lighting, which reduces the grayscale range of the image. In this technique, the histogram corresponding to the original image is transformed into a uniformly distributed histogram, thereby expanding the dynamic range of the image’s gray values and enhancing its overall contrast.

The grayscale histogram of an image can be represented as a one-dimensional discrete function, as shown in Eq. (8).

$$h(k) = nk \, k = 0,1,...,L - 1$$
(8)

In Eq. (8), k is the grayscale level, and h(k) is the number of occurrences of that grayscale level.

Equation (8) can be written as a normalized probability expression, as shown in Eq. (9).

$$P_{s} \left( {s_{k} } \right){ = }\frac{{n_{k} }}{n} \, 0 \le s_{k} \le 1$$
(9)

In Eq. (9), sk is the kth grayscale value of the image f(x,y), n is the total number of pixels in the image, nk is the number of times the corresponding kth grayscale value appears in the image, and ps(sk) represents an estimate of the probability of sk occurrence. The proportion of the number of pixels with each grayscale value in the image is obtained by normalizing the total number of pixels in the image.

During histogram equalization, the gray value of the original pixel is transformed. If the grayscale transformation function is EH, where s and t represent the grayscale values of f(x,y) and g(x,y) at positions (x,y), respectively, the grayscale transformation expression can be written as follows:

$$t = E_{H} (s)$$
(10)

The grayscale transformation function must meet the following requirements: EH(s) is a single-valued single increasing function within the range of 0 ≤ s ≤ 1; For 0 ≤ s ≤ 1, 0 ≤ EH(s) ≤ 1.

The first condition ensures that the grayscale levels of the image histogram maintain their sorting order from black to white after transformation. The second condition ensures that a consistent dynamic range of grayscale values is maintained in the image before and after the transformation.

The cumulative distribution function (CDF) is commonly used as the transfer function for histogram equalization. Under the action of the CDF, the cumulative distribution of s is the cumulative histogram of the original image histogram, and its formula is as follows:

$$t_{k} = E_{H} (s) = \sum\nolimits_{i = 0}^{k} {\frac{{n_{i} }}{n}} = \sum\nolimits_{i = 0}^{k} {p_{s} } (s_{k} ) \, 0 \le s_{k} \le 1$$
(11)

2.2.3 Image texture feature extraction method

Grayscale co-occurrence matrix (GLCM) [34, 35] is a statistical method used to analyze grayscale information in an image. It accurately predicts and reflects grayscale values and gradients in various directions.

The feature parameter extracted by the GLCM is obtained by processing the scalar values of each gray level calculation in the image. For image P with a size of M × N, the grayscale co-occurrence matrix is shown in Eq. (12):

$$\begin{gathered} P\left( {I,J} \right) = \left\{ {\left( {i,j} \right),\left( {i + a,j + b} \right) \in M \times N} \right. \hfill \\ \begin{array}{*{20}c} {} & {} & {} \\ \end{array} \left. {\left| {Gray\left( {i,j} \right) = I\& Gray\left( {i + a,j + b} \right) = J} \right.} \right\} \hfill \\ \end{gathered}$$
(12)

In Eq. (12), the grayscale value of point (i, j) is I, and the grayscale value of point (i + a, j + b) is J.

The feature parameters include contrast, energy, entropy, correlation, and inverse moment, which reflect different aspects of the image’s texture.

Contrast represents the grayscale contrast of the image and is calculated using Eq. (13):

$$CON = \sum\limits_{N = 0}^{L - 1} {N^{2} \left\{ {\sum\limits_{I} {\sum\limits_{J} {P\left( {I,J} \right)} } } \right\}}$$
(13)

Energy represents the image texture distribution and gray level distribution and is calculated using Eq. (14):

$$ASM = \sum\limits_{I}^{{}} {\sum\limits_{J}^{{}} {P^{2} \left( {I,J} \right)} }$$
(14)

Entropy represents the randomness and complexity of image gray distribution; its calculation formula is as follows:

$$ENT = \sum\limits_{I} {\sum\limits_{J} {P\left( {I,J} \right)\log P\left( {I,J} \right)} }$$
(15)

Correlation reflects the similarity between rows or columns in a matrix. When the matrix elements are uniformly equal, the correlation is high. In this study, because the texture was mainly vertical, only the correlation in this direction was calculated. The calculation formula is shown in Eq. (16):

$$COR = \frac{{\sum\limits_{I} {\sum\limits_{J} {\left( {I \times J \times P\left( {I,J} \right)} \right)} } - \mu_{x} \mu {}_{y}}}{{\sigma_{x} \sigma_{y} }}$$
(16)

Inverse moment represents the complexity of the spatial distribution of the image; its calculation formula is shown in Eq. (17):

$$IDM = \sum\limits_{I} {\sum\limits_{J} {\left( {\frac{{P\left( {I,J} \right)}}{{1 + \left( {I - J} \right)^{2} }}} \right)} }$$
(17)

In Eq. (17), N represents the number of grayscale levels of the image,\(\sigma_{x}\) and \(\sigma_{y}\), respectively, represent the mean values of the horizontal and vertical directions of the matrix P(I,J), and \(\mu_{x}\) and \(\mu_{y}\), respectively, represent the variance in the horizontal and vertical directions of matrix P(I,J).

2.3 SVM algorithm

In balanced data classification, SVMs and other classification methods have been extensively studied and successfully applied in various fields [36, 37]. However, traditional methods have numerous limitations when handling imbalanced datasets. Although these methods aim to create a high-accuracy model that matches the training data well, they exhibit poor performance in imbalanced classification problems as these often ignore the accuracy of minority class samples. To address this problem, in this study, we used a large number of virtual samples to improve the classification accuracy.

SVM classification involves creating a plane to separate different data types and maximizing the distance between the data and the plane. The calculation formula is as follows:

$$wx - b = 0$$
(18)

where x is the vector on the hyperplane, w is the normal vector of the hyperplane, and b is the intercept of the hyperplane.

By solving the quadratic optimization problem, the values of w and b are obtained:

$$\begin{gathered} \mathop {\min }\limits_{w,\xi ,b} \frac{1}{2}\left\| w \right\| + \frac{1}{cn}\sum\limits_{i = 1}^{n} {\xi_{i} } - b \hfill \\ s.t.(wx_{i} ) > b - \xi_{i} ,\xi_{i} \ge 0,i = 1,2, \cdot \cdot \cdot ,n \hfill \\ \end{gathered}$$
(19)

where c is the penalty function with a value range of (0,1], n is the number of samples, \(\xi\) is the relaxation variable (the value is greater than 0), and b is the intercept of the hyperplane.

By using the Lagrange multiplier method, the discriminant function of the classification model is finally obtained, as shown in Eq. (20):

$$f(x) = {\text{sgn}} (\sum\limits_{i = 1}^{n} {a_{i} } K(x_{i} ,x) - b)$$
(20)

where \(K(x_{i} ,x)\) is the kernel function and can be expressed as follows:

$$K(x_{i} ,x) = \exp ( - \left\| {x_{i} - x} \right\|^{2} /2g^{2} )$$
(21)

where g is the total number of samples.

3 Experiment

A testing platform was constructed for machining surfaces by using CCD cameras, ball screws, zoom lenses, light sources, controllers, etc., as shown in Fig. 2. The testing platform can move along the x, y, and z axes and allows lens focal length adjustment, camera movement control, and image capture of processed surfaces. The image acquisition resolution was set as 1200 × 1600 pixels. We processed surfaces with different roughness levels using grinding. To measure the roughness of the machined surface, we used a contact roughness tester TR200 and extracted roughness parameters by scanning the sample with a 0.8-mm sampling length. The experimental results were used to produce a dataset of nine different roughness values for ground workpieces. The sample material was GCr15, with a size of φ65 mm × 5 mm and a roughness of 0.60 µm. The grinding process parameters were as follows: grinding wheel speed = 30 m/s, feed depth = 20 µm, feed rate = 1 m/min, and particle size = 80#. The grinding sample block was produced by grinding on the grinding machine based on the process parameters and the particle size of the grinding wheel.

Fig. 2
figure 2

Test platform

4 Results and discussion

4.1 Processing flat images

By using an image acquisition system, we captured images of surfaces processed using different techniques and measured their roughness levels using a contact roughness detector, as shown in Fig. 3.

Fig. 3
figure 3

Machined surface samples

4.2 Virtual sample generation

We converted the collected images to grayscale and reconstructed the processed surface samples by using reconstruction coefficients of 0.2, 0.4, 0.6, 0.8, and 1.0. The resulting samples are shown in Fig. 4.

Fig. 4
figure 4

Virtual sample grayscale images generated by different reconstruction coefficients

4.3 Characteristic parameters of images

We used the GLCM to extract texture feature values, namely correlation, contrast, energy, homogeneity, and entropy, from the images and then determined the correlations between these feature values and the roughness of the machined surface. The relationship between the original samples and the virtual samples with different reconstruction coefficients and roughness is shown in Figs. 5 and 6.

Fig. 5
figure 5

Relationship between the feature values of images and the roughness of machined surfaces

Fig. 6
figure 6

Relationship between virtual samples with different reconstruction coefficients and roughness

As can be seen in Fig. 5, the feature values (correlation, contrast, energy, entropy, and homogeneity) of the processed surface showed a linear correlation with roughness. Furthermore, the correlation decreased with increasing roughness, contrast increased with increasing roughness, energy decreased with increasing roughness, entropy increased with increasing roughness, and second-order angle moment decreased with increasing roughness.

As can be seen in Fig. 6, the correlation between the texture feature values and roughness of the processed image generated by the virtual sample was consistent with the trend of the original sample; however, the determination coefficient of the linear regression between the virtual sample and roughness for its reasonable reconstruction coefficient was higher than that of the original sample, improving the accuracy of detection. The virtual samples generated using different reconstruction coefficients have different determination coefficients for roughness, as shown in Table 1.

Table 1 Correlation coefficients between texture feature values and roughness of virtual samples with different reconstruction coefficients

As can be observed from Table 1, when the reconstruction coefficient was 0.8, the determination coefficient of the linear regression model between the generated samples and roughness was the highest. The determination coefficients between the correlation, contrast, energy, entropy, homogeneity, and roughness of the original sample and the QR virtual sample were 0.87978 and 0.96646, 0.89549 and 0.97318, 0.87505 and 0.96084, 0.90607 and 0.98296, and 0.87978 and 0.96646, respectively. Furthermore, the correlation, contrast, energy, entropy, entropy, homogeneity, and roughness of the feature values of QR virtual samples were 9.852%, 8.676%, 9.804%, 8.486%, and 9.852%, respectively, higher than those of the original samples. Thus, it can be concluded that compared with the coefficients of the original sample, the determination coefficient of the linear regression model between the feature value parameters and roughness of the virtual sample generated by QR improved, and the generated virtual sample improved the accuracy of detection.

4.4 Result analysis

The virtual samples generated using the QR reconstruction method were added to the training of the recognition model, and the accuracy P of the virtual samples generated by QR decomposition was compared with the accuracy P without virtual samples, as shown in Fig. 7.

Fig. 7
figure 7

Accuracy and coefficients of the original sample with different reconstruction coefficients

As can be seen from Fig. 7, the grinding surface roughness can be predicted using SVM; however, when the sample data size is small, the accuracy is average. The average accuracy was found to be 80.6%, and the average coefficient of determination was 0.870. After expanding the sample size through QR reconstruction weighted fusion, the measurement accuracy and determination coefficient of SVM improved considerably. The average value of the determination coefficient exceeded 87%, and the average accuracy was over 0.90. When the QR reconstruction coefficient is 0.8, the roughness detection effect is the best, with an average determination coefficient of 0.984 and an accuracy average of 96.5%, which is 19.7% higher than the accuracy of the original image sample.

5 Conclusion

To overcome the challenge of obtaining large sample sizes for non-contact grinding surface roughness measurement, we proposed a virtual sample generation method that enhances detection accuracy by generating a large number of virtual samples and uses the SVM method for accurate measurement of non-contact grinding surface roughness. The findings of this study are listed as follows.

  1. (1)

    A machine vision detection system was developed to capture images of different processed surfaces, and a correlation model between roughness and texture features was established to perform non-contact roughness measurement; however, its accuracy is not high.

  2. (2)

    A QR reconstruction weighted fusion method was proposed for generating virtual samples with similar texture features to the original samples, and the measurement accuracy was improved by determining the correlations between texture feature values (correlation, contrast, entropy, energy, and homogeneity) and roughness.

  3. (3)

    The use of the QR reconstruction weighted fusion method to generate virtual samples increased the determination coefficients between the texture features, namely, correlation, contrast, energy, entropy, homogeneity, and roughness by 9.825%, 8.676%, 9.804%, 8.486%, and 9.852%, respectively, compared to the original samples, thus demonstrating its effectiveness.

  4. (4)

    Expanding the sample size considerably improved the accuracy of roughness measurement. The highest measurement accuracy, averaging 96.5% in multiple experiments, was achieved with a reconstruction coefficient of 0.8, a 19.7% increase over the accuracy of the original sample. This validates the feasibility of the proposed method and provides a theoretical basis for in-machine detection of surface roughness in small sample processing.