Method, device, computer equipment and storage medium for measuring fabric texture cycle
By calculating the displacement vector and grayscale difference of pixel points in fabric images, statistical probability distribution, and directly determining the fabric texture period, the complex and inconsistent problems of the existing technology are solved, and the simplified texture period measurement and the effect of improving detection reliability is achieved. .
Patent Information
- Application Number
- CN202111664108.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-30
- Publication Date
- 2025-01-17
- Estimated Expiration
- 2041-12-30
AI Technical Summary
The existing fabric texture period detection methods are complex, and the fabric texture period cannot be intuitively determined. They are greatly affected by experience and subjective factors, and lack consistency and reliability.
By obtaining the original image of the fabric, calculate the displacement vector and grayscale difference of any two pixel points, count the probability distribution of the displacement vector, calculate the homogeneity parameters, determine the texture period, and directly use the displacement vector of the maximum value of the homogeneity parameter as the texture Periods, simplify the calculation process, and avoid complex steps such as Fourier transform.
The simplified fabric texture period measurement process is realized, which improves the reliability and consistency of detection. Users can intuitively understand the relationship between texture period and displacement vector, and the calculation method is simple and clear.
Smart Images

Figure CN114332044B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to a method, device, computer equipment and storage medium for measuring a fabric texture period. Background Art
[0002] Fabric defect detection has become an important part of fabric quality control, and defect detection methods play an important role in improving product quality.
[0003] At present, fabric defect detection is mainly carried out by naked eye observation by fabric inspectors. This method consumes a lot of manpower, and the test results are affected by the experience, proficiency and some subjective factors of the inspectors, lacking consistency and reliability. Machine vision detection has gradually been applied in a small range and is expected to become a trend in the future. When using machine vision for detection, measuring the texture periodicity of fabrics is an important step in machine vision fabric defect detection. In the prior art, the periodicity detection of fabric texture usually requires filtering and Fourier transforming the fabric image to obtain the spectrum and phase, so as to determine the period of fabric texture based on the spectrum and phase. This method has a complex calculation process and cannot intuitively obtain the texture period of the fabric. Summary of the invention
[0004] Based on this, it is necessary to provide a method, device, computer equipment and storage medium for measuring the fabric texture period that can simplify the calculation process of the fabric texture period in order to solve the above technical problems.
[0005] In a first aspect, the present application provides a method for measuring a fabric texture period, the method comprising:
[0006] Acquire an original image of the fabric, and acquire the coordinates and grayscale value of each pixel in the original image;
[0007] Calculate the displacement vector of any two pixels in the horizontal direction and / or the vertical direction, and calculate the gray level difference between any two pixels according to the gray values of the any two pixels;
[0008] According to the displacement vectors and level differences between any two pixels in the horizontal direction and / or the vertical direction, statistically analyzing the probability distribution of the level differences corresponding to each displacement vector in the horizontal direction and / or the vertical direction;
[0009] Calculating homogenization parameters corresponding to each displacement vector in the horizontal direction and / or the vertical direction according to the probability distribution of the level difference;
[0010] The maximum value of the homogenization parameters corresponding to each displacement vector in the horizontal direction and / or the vertical direction is determined, and the displacement vector corresponding to the maximum value is used as the texture period of the fabric in the horizontal direction and / or the vertical direction.
[0011] In one embodiment, determining the maximum value of the homogenization parameters corresponding to the displacement vectors in the horizontal direction and / or the vertical direction, and using the displacement vector corresponding to the maximum value as the texture period of the fabric in the horizontal direction and / or the vertical direction, comprises:
[0012] Determine the maximum value of the homogenization parameters corresponding to each displacement vector in the horizontal direction and / or the vertical direction;
[0013] The displacement vector corresponding to the minimum value among the maximum values is used as the texture period of the fabric in the horizontal direction and / or the vertical direction.
[0014] In one embodiment, determining the maximum value of the homogenization parameters corresponding to the displacement vectors in the horizontal direction and / or the vertical direction, and using the displacement vector corresponding to the maximum value as the texture period of the fabric in the horizontal direction and / or the vertical direction, comprises:
[0015] Obtaining a relationship curve diagram between the displacement vector and the homogenization parameter according to the homogenization parameter corresponding to each displacement vector in the horizontal direction and / or the vertical direction;
[0016] Determine the first peak value in the relationship curve diagram corresponding to the horizontal direction and / or the vertical direction, and use the displacement vector corresponding to the first peak value in the horizontal direction and / or the vertical direction as the texture period of the fabric in the horizontal direction and / or the vertical direction.
[0017] In one embodiment, the statistical probability distribution of the level difference corresponding to each displacement vector in the horizontal direction and / or the vertical direction according to the displacement vector and the level difference between any two pixels in the horizontal direction and / or the vertical direction includes:
[0018] According to the displacement vectors and level differences between any two pixels in the horizontal direction and / or the vertical direction, a distribution histogram of the level differences corresponding to each displacement vector in the horizontal direction and / or the vertical direction is obtained;
[0019] The distribution histogram is normalized to obtain the probability distribution of the level difference corresponding to each displacement vector in the horizontal direction and / or the vertical direction.
[0020] In one embodiment, calculating the homogenization parameter corresponding to each displacement vector in the horizontal direction and / or the vertical direction according to the probability distribution of the level difference includes:
[0021] Calculate the probability distribution of the level difference corresponding to each displacement vector in the horizontal direction and / or vertical direction and the first ratio of the level difference, and calculate the sum of the first ratios corresponding to each displacement vector in the horizontal direction and / or vertical direction to obtain the homogenization parameter of each displacement vector in the horizontal direction and / or vertical direction.
[0022] In one embodiment, the homogenization parameter of each displacement vector in the horizontal direction and / or the vertical direction is calculated by the following formula:
[0023]
[0024] Where v represents the displacement vector, a represents the gray level difference between the two pixels corresponding to the displacement vector v, and P v (a) represents the probability that the gray level difference between two pixels whose relative position relationship is vector v is a.
[0025] In one embodiment, the step of calculating the grayscale difference between any two pixels according to the grayscale values of any two pixels comprises:
[0026] The difference between the grayscale values of any two pixels is calculated, and the difference is used as the grayscale difference between the two pixels.
[0027] In one embodiment, the step of calculating the grayscale difference between any two pixels according to the grayscale values of any two pixels further includes:
[0028] Determine the grayscale of two pixels according to the grayscale values of any two pixels;
[0029] Calculate the gray level difference between two pixels to obtain the gray level difference between the two pixels.
[0030] In a second aspect, the present application also provides a device for measuring a fabric texture period. The device comprises:
[0031] An acquisition module, used to acquire an original image of the fabric, and acquire the coordinates and grayscale value of each pixel in the original image;
[0032] A first calculation module is used to calculate the displacement vector and grayscale difference between any two pixels in the horizontal direction and / or vertical direction;
[0033] A statistical module, for calculating the probability distribution of the grayscale difference corresponding to each displacement vector in the horizontal direction and / or the vertical direction according to the displacement vector and the grayscale difference between any two pixels in the horizontal direction and / or the vertical direction;
[0034] A homogenization parameter calculation module, used to calculate the homogenization parameter corresponding to each displacement vector in the horizontal direction and / or vertical direction according to the probability distribution of the gray value;
[0035] The texture period calculation module is used to calculate the maximum value of the homogenization parameters corresponding to each displacement vector in the horizontal direction and / or the vertical direction, and use the maximum value as the texture period of the fabric in the horizontal direction and / or the vertical direction.
[0036] In a third aspect, the present application further provides a computer device. The computer device includes a memory and a processor, the memory stores a computer program, and the processor implements the following steps when executing the computer program:
[0037] Acquire an original image of the fabric, and acquire the coordinates and grayscale value of each pixel in the original image;
[0038] Calculate the displacement vector of any two pixels in the horizontal direction and / or the vertical direction, and calculate the gray level difference between any two pixels according to the gray values of the any two pixels;
[0039] According to the displacement vectors and level differences between any two pixels in the horizontal direction and / or the vertical direction, statistically analyzing the probability distribution of the level differences corresponding to each displacement vector in the horizontal direction and / or the vertical direction;
[0040] Calculating homogenization parameters corresponding to each displacement vector in the horizontal direction and / or the vertical direction according to the probability distribution of the level difference;
[0041] The maximum value of the homogenization parameters corresponding to each displacement vector in the horizontal direction and / or the vertical direction is calculated, and the displacement vector corresponding to the maximum value is used as the texture period of the fabric in the horizontal direction and / or the vertical direction.
[0042] In a fourth aspect, the present application further provides a computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the following steps are implemented:
[0043] Acquire an original image of the fabric, and acquire the coordinates and grayscale value of each pixel in the original image;
[0044] Calculate the displacement vector of any two pixels in the horizontal direction and / or the vertical direction, and calculate the gray level difference between any two pixels according to the gray values of the any two pixels;
[0045] According to the displacement vectors and level differences between any two pixels in the horizontal direction and / or the vertical direction, statistically analyzing the probability distribution of the level differences corresponding to each displacement vector in the horizontal direction and / or the vertical direction;
[0046] Calculating homogenization parameters corresponding to each displacement vector in the horizontal direction and / or the vertical direction according to the probability distribution of the level difference;
[0047] The maximum value of the homogenization parameters corresponding to each displacement vector in the horizontal direction and / or the vertical direction is calculated, and the displacement vector corresponding to the maximum value is used as the texture period of the fabric in the horizontal direction and / or the vertical direction.
[0048] In a fifth aspect, the present application further provides a computer program product. The computer program product includes a computer program, and when the computer program is executed by a processor, the following steps are implemented:
[0049] Acquire an original image of the fabric, and acquire the coordinates and grayscale value of each pixel in the original image;
[0050] Calculate the displacement vector of any two pixels in the horizontal direction and / or the vertical direction, and calculate the gray level difference between any two pixels according to the gray values of the any two pixels;
[0051] According to the displacement vectors and level differences between any two pixels in the horizontal direction and / or the vertical direction, statistically analyzing the probability distribution of the level differences corresponding to each displacement vector in the horizontal direction and / or the vertical direction;
[0052] Calculating homogenization parameters corresponding to each displacement vector in the horizontal direction and / or the vertical direction according to the probability distribution of the level difference;
[0053] The maximum value of the homogenization parameters corresponding to each displacement vector in the horizontal direction and / or the vertical direction is calculated, and the displacement vector corresponding to the maximum value is used as the texture period of the fabric in the horizontal direction and / or the vertical direction.
[0054] The above-mentioned fabric texture period measurement method, device, computer equipment and storage medium obtain an original image of the fabric, and obtain the coordinates and grayscale values of each pixel in the original image; calculate the displacement vector of any two pixels in the horizontal direction and / or vertical direction, and calculate the grayscale level difference of any two pixels according to the grayscale values of any two pixels; based on the displacement vector and level difference of any two pixels in the horizontal direction and / or vertical direction, statistically calculate the probability distribution of the level difference corresponding to each displacement vector in the horizontal direction and / or vertical direction; calculate the homogenization parameter corresponding to each displacement vector in the horizontal direction and / or vertical direction according to the probability distribution of the level difference; calculate the maximum value among the homogenization parameters corresponding to each displacement vector in the horizontal direction and / or vertical direction, and use the displacement vector corresponding to the maximum value as the texture period of the fabric in the horizontal direction and / or vertical direction. The method first obtains an image of the fabric, calculates the displacement vector and the grayscale value difference between any two pixel points of the image in the horizontal direction or the vertical direction, calculates the homogenization parameters corresponding to each displacement vector according to the probability distribution of the difference corresponding to the displacement vector, and determines the cyclic unit of the fabric image according to the displacement vector corresponding to the maximum value of the homogenization parameter, without the need to perform Fourier transform and frequency domain conversion on the image. The application uses a probabilistic method to calculate the homogenization parameter to determine the cyclic unit, i.e., the texture period. The calculation method is simple, and the displacement vector can intuitively reflect the texture period of the fabric. BRIEF DESCRIPTION OF THE DRAWINGS
[0055] Figure 1 A diagram showing an application environment of a method for measuring a fabric texture period in one embodiment;
[0056] Figure 2 A schematic flow chart of a method for measuring a fabric texture period in one embodiment;
[0057] Figure 3 is a schematic diagram of an original image of a fabric in one embodiment;
[0058] Figure 4 is a schematic diagram of a curve showing the relationship between each displacement vector and a homogenization parameter in the horizontal direction and the vertical direction in one embodiment;
[0059] Figure 5 A schematic diagram of a texture division result of a fabric in one embodiment;
[0060] Figure 6 Schematic diagram of probability distribution of some displacement vectors in the horizontal direction in one embodiment;
[0061] Figure 7 is a structural diagram of a device for measuring a fabric texture period in one embodiment;
[0062] Figure 8 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0063] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0064] The fabric texture period measurement method provided in the embodiment of the present application can be applied to Figure 1In the application environment shown. Among them, the image acquisition terminal 102 communicates with the measuring terminal 103. The image acquisition terminal 102 is a terminal with an image sensor, which can acquire the original image of the fabric, and the measuring terminal 103 measures the texture period of the original image of the fabric sent by the image acquisition terminal 102. The image acquisition terminal 102 can also be integrated in the measuring terminal 103, or the fabric texture period measurement method provided in the embodiment of the present application is applied to a measuring terminal with an image sensor. When the measuring terminal 103 receives a texture period measurement request, the original image of the fabric is acquired from the image acquisition terminal 102, and the texture period of the fabric is measured according to the original image. Among them, the image acquisition terminal 102 can be but not limited to various terminals with image sensors such as tablet computers, smart phones, and laptop computers, and the measuring terminal 103 can be but not limited to various terminals or servers with image processing capabilities such as personal computers, laptop computers, smart phones, tablet computers, and portable wearable devices.
[0065] At present, in the visual detection of the texture period of the fabric, the image of the fabric is Fourier transformed to obtain the image power spectrum and phase, and then the texture period of the fabric is determined based on the spectrum and phase. The calculation method through Fourier transform is relatively complicated, and at the user level, it is impossible to intuitively see the relationship between the calculation process and the texture period. The present application calculates the homogenization parameters of the displacement vectors of any two pixels in the horizontal and / or vertical directions, thereby determining that the displacement vector corresponding to the maximum value of the homogenization parameter is the texture period. The user can intuitively determine the relationship with the texture period in the horizontal and / or vertical direction based on the displacement vector, and the homogenization parameter is calculated based on the statistical gray value difference, and the calculation process is relatively simple compared to Fourier transform.
[0066] In one embodiment, Figure 2 As shown, a method for measuring the texture period of a fabric is provided, and the method is applied to Figure 1 Taking the measurement terminal 103 in the example as an example, the following steps are included:
[0067] Step 201: obtaining an original image of the fabric, and obtaining the coordinates and grayscale values of each pixel in the original image.
[0068] The original image of the fabric may be acquired by an image sensor integrated on the measuring terminal, or may be acquired by the measuring terminal from an image acquisition terminal.
[0069] The measuring terminal can obtain the original image of the fabric through the image sensor or through the image acquisition terminal according to the measurement instruction sent by the external device. As another embodiment, the measuring terminal can also automatically obtain the image of the fabric when detecting the presence of new fabric in the photo area. Then, the coordinates and grayscale values of each pixel in the original image are obtained according to the pre-established coordinate system. Specifically, a corresponding coordinate system is established according to the original image. In this application, in order to facilitate subsequent calculations, since the texture of the fabric generally extends in the horizontal direction or vertical direction of the fabric, the coordinates of one corner of the original image are used as the points of the coordinate system in this embodiment, and the horizontal coordinates of the coordinates are parallel or perpendicular to one side of the original image, so that the coordinates of each pixel in the image can be obtained according to the coordinate system. As an embodiment, the process of establishing the coordinate system may include but is not limited to: first placing the original image in a position parallel to the horizontal direction, and then using the coordinates of one corner of the original image as the points of the coordinate system to establish the corresponding coordinate system.
[0070] Step 202, calculating the displacement vector between any two pixels in the horizontal direction and / or the vertical direction, and calculating the gray level difference between any two pixels according to the gray values of the any two pixels.
[0071] In this embodiment, a variable is predefined as a displacement vector, which is the difference between the horizontal coordinates or vertical coordinates of any two pixels in the horizontal direction or in the vertical direction. Figure 3 As shown, if the size of the original fabric image is 768*512, the displacement vector of any two pixels in the horizontal direction can be a value among (1,0), (2,0)…(765,0); the displacement vector of any two pixels in the vertical direction can be a value among (0,1), (0,2)…(0,511).
[0072] In actual use, the technical solution of the present application can be used to measure the texture period of the fabric in the horizontal direction or the vertical direction, or in the horizontal direction and the vertical direction.
[0073] In the horizontal direction, after the measuring terminal obtains the coordinates and grayscale values of the original image of the fabric, it calculates the horizontal coordinate difference between any two pixel coordinates as the displacement vector (if it is calculated in the vertical direction, the vertical coordinate difference between any two pixel coordinates is used as the displacement vector). And the grayscale difference between any two pixel points is calculated according to the grayscale values of the two pixel points.
[0074] If it is necessary to measure the texture period of the fabric in the horizontal and vertical directions, the displacement vector and level difference of any two pixel points in the horizontal and vertical directions are calculated simultaneously.
[0075] Specifically, as an embodiment, calculating the grayscale difference between any two pixels according to the grayscale values of the two pixels includes:
[0076] The difference between the grayscale values of any two pixels is calculated, and the difference is used as the grayscale difference between the two pixels.
[0077] In this embodiment, the grayscale difference between the two pixels is directly calculated based on the grayscale values of the two pixels, and the difference is used as the grayscale level difference of the two pixels. For example, if the grayscale value of the current image is 0 to 255, the grayscale difference between any two pixels can be any value between -255 and 255.
[0078] As another embodiment, calculating the grayscale difference between any two pixels according to the grayscale values of the two pixels includes:
[0079] Determine the grayscale of two pixels according to the grayscale values of any two pixels;
[0080] Calculate the gray level difference between two pixels to obtain the gray level difference between the two pixels.
[0081] Specifically, the grayscale is defined in this embodiment. For example, the grayscale value of 0 to 8 corresponds to grayscale 1; 9 to 16 corresponds to grayscale 2; and so on. After obtaining the grayscale value of each pixel, the grayscale of the two pixels is first determined according to the grayscale values of the two pixels, and then the difference in the grayscale of the two pixels is calculated as the grayscale difference of the two pixels.
[0082] Step 203: According to the displacement vectors and level differences between any two pixels in the horizontal direction and / or the vertical direction, the probability distribution of the level differences corresponding to the displacement vectors in the horizontal direction and / or the vertical direction is statistically calculated.
[0083] Statistics are performed based on the displacement vectors of any two pixels in the horizontal direction and / or the vertical direction and the level difference between any two pixels obtained in step 202, and the probability distribution of the level difference corresponding to each displacement vector in the horizontal direction and / or the vertical direction is statistically calculated. Exemplarily, the size of the original image of the fabric is 768*512, if the texture period in the horizontal direction of the fabric is measured, the displacement vector of any two pixels in the horizontal direction can be a value among (1,0), (2,0) ... (765,0), and the probability distribution of the level difference corresponding to the displacement vectors (1,0), (2,0) ... (765,0) is statistically calculated; if the texture period in the vertical direction is calculated, the displacement vector of any two pixels in the vertical direction can be a value among (0,1), (0,2) ... (0,511), and the probability distribution of the level difference corresponding to the displacement vectors (0,1), (0,2) ... (0,511) is statistically calculated.
[0084] Step 204: Calculate the homogenization parameters corresponding to the displacement vectors in the horizontal direction and / or the vertical direction according to the probability distribution of the level difference.
[0085] According to the probability distribution of the level difference corresponding to each displacement vector in the horizontal direction, or the probability distribution of the level difference corresponding to each displacement vector in the vertical direction counted in step 203, the homogenization parameters corresponding to each displacement vector in the horizontal direction and / or vertical direction are calculated, and the rules of each displacement vector can be found through the homogenization parameters.
[0086] Furthermore, the step of calculating the homogenization parameters corresponding to the displacement vectors in the horizontal direction and / or the vertical direction according to the probability distribution of the level difference includes:
[0087] According to the probability distribution and level difference calculation of the level difference corresponding to each displacement vector in the horizontal direction and / or vertical direction, the ratio corresponding to each displacement vector in the horizontal direction and / or vertical direction is obtained, and the sum of the ratios corresponding to each displacement vector in the horizontal direction and / or vertical direction is calculated to obtain the homogenization parameter of each displacement vector in the horizontal direction and / or vertical direction.
[0088] Specifically, each displacement vector corresponds to at least one level difference and a probability distribution of each level difference, and a ratio is calculated according to the level difference of each displacement vector in the horizontal direction and / or the vertical direction and the probability distribution of the level difference, and the sum of multiple ratios corresponding to each displacement vector in the horizontal direction and / or the vertical direction is calculated, thereby obtaining a homogenization parameter of each displacement vector in the horizontal direction and / or the vertical direction. As an embodiment, the homogenization parameter of each displacement vector in the horizontal direction and / or the vertical direction is calculated by the following formula:
[0089]
[0090] Where v represents the displacement vector, a represents the gray level difference between the two pixels corresponding to the displacement vector v, and P v (a) represents the probability that the gray level difference between two pixels whose relative position relationship is vector v is a.
[0091] Step 205, determining the maximum value of the homogenization parameters corresponding to the displacement vectors in the horizontal direction and / or the vertical direction, and using the displacement vector corresponding to the maximum value as the texture period of the fabric in the horizontal direction and / or the vertical direction.
[0092] According to step 204, the homogenization parameters corresponding to the displacement vectors in the horizontal direction and / or the vertical direction are calculated. If the texture period in the horizontal direction needs to be calculated, the maximum value among the homogenization parameters corresponding to the displacement vectors is determined in the horizontal direction; if the texture period in the vertical direction needs to be calculated, the maximum value among the homogenization parameters corresponding to the displacement vectors is determined in the vertical direction. The displacement vector corresponding to the maximum value is used as the texture period in the horizontal direction and / or the vertical direction of the fabric.
[0093] As an embodiment, determining the maximum value of the homogenization parameters corresponding to each displacement vector in the horizontal direction and / or the vertical direction, and using the displacement vector corresponding to the maximum value as the texture period of the fabric in the horizontal direction and / or the vertical direction includes:
[0094] Determine the maximum value of the homogenization parameters corresponding to each displacement vector in the horizontal direction and / or the vertical direction;
[0095] The minimum displacement vector corresponding to the maximum value is used as the texture period of the fabric in the horizontal direction and / or the vertical direction.
[0096] Specifically, when the displacement vector is an integer multiple of the texture period, the homogenization parameter reaches its maximum value. That is, there are multiple homogenization parameter maximum values, and the displacement vector corresponding to the homogenization parameter maximum value is an integer multiple of the texture period. Therefore, the minimum value determined among the displacement vectors corresponding to the multiple homogenization parameter maximum values is the texture period.
[0097] As another embodiment, determining the maximum value of the homogenization parameters corresponding to the displacement vectors in the horizontal direction and / or the vertical direction, and using the displacement vector corresponding to the maximum value as the texture period of the fabric in the horizontal direction and / or the vertical direction includes:
[0098] Obtaining a relationship curve diagram between the displacement vector and the homogenization parameter according to the homogenization parameter corresponding to each displacement vector in the horizontal direction and / or the vertical direction;
[0099] Determine the first peak value in the relationship curve diagram corresponding to the horizontal direction and / or the vertical direction, and use the displacement vector corresponding to the first peak value in the horizontal direction and / or the vertical direction as the texture period of the fabric in the horizontal direction and / or the vertical direction.
[0100] Specifically, in practical applications, the maximum values of the calculated homogenization parameters may decrease successively. In this embodiment, after the homogenization parameters corresponding to the displacement vectors in the horizontal direction and / or the vertical direction are calculated, a relationship curve diagram between the displacement vectors and the homogenization parameters is obtained according to the homogenization parameters corresponding to the displacement vectors in the horizontal direction and / or the vertical direction. For example, Figure 4As shown, the first peak value in the relationship curve corresponding to the horizontal direction and / or the vertical direction is determined from the relationship curve, as shown by the arrow in the figure, and the displacement vector corresponding to the first peak value in the horizontal direction and / or the vertical direction is used as the texture period of the fabric in the horizontal direction and / or the vertical direction. The texture period in the horizontal direction is 64, and the texture period in the vertical direction is 63. According to the texture period result, the following can be used to determine the texture period of the fabric: Figure 3 The original image shown is divided, and the division result is as follows Figure 5 shown.
[0101] The above-mentioned method for measuring the texture period of the fabric is as follows: obtaining an original image of the fabric, and obtaining the coordinates and grayscale values of each pixel in the original image; calculating the displacement vector of any two pixels in the horizontal direction and / or the vertical direction, and calculating the grayscale level difference of any two pixels according to the grayscale values of any two pixels; according to the displacement vector and the level difference of any two pixels in the horizontal direction and / or the vertical direction, statistically analyzing the probability distribution of the level difference corresponding to each displacement vector in the horizontal direction and / or the vertical direction; calculating the homogenization parameter corresponding to each displacement vector in the horizontal direction and / or the vertical direction according to the probability distribution of the level difference; calculating the maximum value among the homogenization parameters corresponding to each displacement vector in the horizontal direction and / or the vertical direction, and taking the displacement vector corresponding to the maximum value as the texture period of the fabric in the horizontal direction and / or the vertical direction. The method first obtains an image of the fabric, calculates the displacement vector and the grayscale value difference between any two pixel points of the image in the horizontal direction or the vertical direction, calculates the homogenization parameters corresponding to each displacement vector according to the probability distribution of the difference corresponding to the displacement vector, and determines the cyclic unit of the fabric image according to the displacement vector corresponding to the maximum value of the homogenization parameter, without the need to perform Fourier transform and frequency domain conversion on the image. The application uses a probabilistic method to calculate the homogenization parameter to determine the cyclic unit, i.e., the texture period. The calculation method is simple, and the displacement vector can intuitively reflect the texture period of the fabric.
[0102] In an optional embodiment, the method of calculating the probability distribution of the level difference corresponding to each displacement vector in the horizontal direction and / or the vertical direction according to the displacement vector and the level difference between any two pixels in the horizontal direction and / or the vertical direction includes:
[0103] According to the displacement vectors and level differences between any two pixels in the horizontal direction and / or the vertical direction, a distribution histogram of the level differences corresponding to each displacement vector in the horizontal direction and / or the vertical direction is obtained;
[0104] The distribution histogram is normalized to obtain the probability distribution of the level difference corresponding to each displacement vector in the horizontal direction and / or the vertical direction.
[0105] Specifically, in this embodiment, based on the displacement vector and level difference between any two pixels in the horizontal direction and / or vertical direction, a distribution histogram of the level difference corresponding to each displacement vector in the horizontal direction and / or vertical direction is obtained. As an embodiment, obtaining the distribution histogram of the level difference corresponding to each displacement vector in the horizontal direction and / or vertical direction may include: using each displacement vector and level difference as the horizontal coordinate and vertical coordinate of the distribution histogram, respectively, and filling the distribution histogram with the numerical value corresponding to the level difference; as another embodiment, based on the displacement vector and level difference between any two pixels in the horizontal direction and / or vertical direction, a histogram formation interface (for example, a histogram formation interface in an Excel table) can be called to form a distribution histogram of the level difference corresponding to each displacement vector in the horizontal direction and / or vertical direction.
[0106] Then, the distribution histogram of the level difference corresponding to each displacement vector in the horizontal direction is normalized and each histogram is subjected to noise reduction to improve the accuracy of the result. Figure 6 As shown, Figure 6 A schematic diagram of the probability distribution of multiple displacement vectors ranging from 1 to 767 in the horizontal direction is given in FIG.
[0107] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0108] Based on the same inventive concept, the embodiment of the present application also provides a fabric texture period measurement device for implementing the fabric texture period measurement method involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in the embodiments of one or more fabric texture period measurement devices provided below can refer to the limitations of the fabric texture period measurement method above, and will not be repeated here.
[0109] In one embodiment, Figure 7 As shown, a device for measuring a fabric texture period is provided, comprising: an acquisition module 701, a first calculation module 702, a statistical module 703, a homogenization parameter calculation module 704 and a texture period calculation module 705, wherein:
[0110] An acquisition module 701 is used to acquire an original image of the fabric, and acquire the coordinates and grayscale value of each pixel in the original image;
[0111] A first calculation module 702 is used to calculate the displacement vector and grayscale difference between any two pixels in the horizontal direction and / or vertical direction;
[0112] A statistical module 703 is used to calculate the probability distribution of the grayscale difference corresponding to each displacement vector in the horizontal direction and / or the vertical direction according to the displacement vector and the grayscale difference between any two pixels in the horizontal direction and / or the vertical direction;
[0113] A homogenization parameter calculation module 704, configured to calculate a homogenization parameter corresponding to each displacement vector in the horizontal direction and / or the vertical direction according to the probability distribution of the gray value;
[0114] The texture period calculation module 705 is used to determine the maximum value of the homogenization parameters corresponding to each displacement vector in the horizontal direction and / or the vertical direction, and use the maximum value as the texture period of the fabric in the horizontal direction and / or the vertical direction.
[0115] In an optional embodiment, the texture period calculation module 705 is further used for:
[0116] Determine the maximum value of the homogenization parameters corresponding to each displacement vector in the horizontal direction and / or the vertical direction;
[0117] The displacement vector corresponding to the minimum value among the maximum values is used as the texture period of the fabric in the horizontal direction and / or the vertical direction.
[0118] In an optional embodiment, the texture period calculation module 705 is further used to: obtain a relationship curve diagram between the displacement vector and the homogenization parameter according to the homogenization parameter corresponding to each displacement vector in the horizontal direction and / or the vertical direction;
[0119] Determine the first peak value in the relationship curve diagram corresponding to the horizontal direction and / or the vertical direction, and use the displacement vector corresponding to the first peak value in the horizontal direction and / or the vertical direction as the texture period of the fabric in the horizontal direction and / or the vertical direction.
[0120] In an optional embodiment, the statistics module 703 is further used for:
[0121] According to the displacement vectors and level differences between any two pixels in the horizontal direction and / or the vertical direction, a distribution histogram of the level differences corresponding to each displacement vector in the horizontal direction and / or the vertical direction is obtained;
[0122] The distribution histogram is normalized to obtain the probability distribution of the level difference corresponding to each displacement vector in the horizontal direction and / or the vertical direction.
[0123] In an optional embodiment, the homogenization parameter calculation module 704 is also used to obtain the ratio corresponding to each displacement vector in the horizontal direction and / or vertical direction based on the probability distribution and difference calculation of the difference corresponding to each displacement vector in the horizontal direction and / or vertical direction, and calculate the sum of the ratios corresponding to each displacement vector in the horizontal direction and / or vertical direction to obtain the homogenization parameter of each displacement vector in the horizontal direction and / or vertical direction.
[0124] In an optional embodiment, the homogenization parameter calculation module 704 calculates the homogenization parameter of each displacement vector in the horizontal direction and / or the vertical direction by the following formula:
[0125]
[0126] Where v represents the displacement vector, a represents the gray level difference between the two pixels corresponding to the displacement vector v, and P v (a) represents the probability that the gray level difference between two pixels whose relative position relationship is vector v is a.
[0127] In an optional embodiment, the first calculation module 702 is further configured to calculate a difference in grayscale values between any two pixels, and use the difference as a grayscale level difference between the two pixels.
[0128] In an optional embodiment, the first calculation module 702 is further configured to determine the grayscale of two pixels according to the grayscale values of any two pixels;
[0129] Calculate the gray level difference between two pixels to obtain the gray level difference between the two pixels.
[0130] Each module in the above-mentioned fabric texture cycle measurement device can be implemented in whole or in part by software, hardware and a combination thereof. Each of the above-mentioned modules can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute the operations corresponding to each of the above modules.
[0131] In one embodiment, a computer device is provided. The computer device may be a terminal / server. The computer device has image processing capability. Its internal structure diagram may be as shown in FIG. Figure 8As shown. The computer device includes a processor, a memory, a communication interface, a display screen and an input device connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be achieved through WIFI, a mobile cellular network, NFC (near field communication) or other technologies. When the computer program is executed by the processor, a method for measuring a fabric texture cycle is implemented. The display screen of the computer device can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covered on the display screen, or a button, a trackball or a touch pad set on the computer device housing, or an external keyboard, touch pad or mouse, etc.
[0132] Those skilled in the art will understand that Figure 8 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0133] In one embodiment, a computer device is provided, including a memory and a processor. The memory stores a computer program. When the processor executes the computer program, the steps of each embodiment of the method for measuring the fabric texture period are implemented, which will not be repeated here.
[0134] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of each embodiment of the method for measuring the fabric texture period are implemented, which will not be repeated here.
[0135] In one embodiment, a computer program product is provided, including a computer program. When the computer program is executed by a processor, the steps of each embodiment of the above fabric texture period measurement method are implemented, which will not be repeated here.
[0136] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.
[0137] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0138] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be construed as limiting the scope of the present application. It should be noted that, for a person of ordinary skill in the art, several modifications and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A method for measuring a fabric texture period, characterized in that: The method comprises: Acquire an original image of the fabric, and acquire the coordinates and grayscale value of each pixel in the original image; Calculate the displacement vector of any two pixels in the horizontal direction and / or the vertical direction, determine the grayscale of the two pixels according to the grayscale values of the two pixels, calculate the difference of the grayscale of the two pixels, and obtain the grayscale difference of the two pixels, wherein the grayscale includes a plurality of continuously changing grayscale values; According to the displacement vectors and level differences between any two pixels in the horizontal direction and / or the vertical direction, statistically analyzing the probability distribution of the level differences corresponding to each displacement vector in the horizontal direction and / or the vertical direction; Calculating homogenization parameters corresponding to each displacement vector in the horizontal direction and / or the vertical direction according to the probability distribution of the level difference; Determine the maximum value of the homogenization parameters corresponding to the displacement vectors in the horizontal direction and / or the vertical direction, and use the displacement vector corresponding to the maximum value as the texture period of the fabric in the horizontal direction and / or the vertical direction; The step of determining the maximum value of the homogenization parameters corresponding to the displacement vectors in the horizontal direction and / or the vertical direction, and taking the displacement vector corresponding to the maximum value as the texture period of the fabric in the horizontal direction and / or the vertical direction, comprises: Determine a maximum value among homogenization parameters corresponding to each displacement vector in the horizontal direction and / or the vertical direction, wherein the displacement vector corresponding to the maximum value of the homogenization parameter is an integer multiple of the texture period; The minimum displacement vector corresponding to the maximum value is used as the texture period of the fabric in the horizontal direction and / or the vertical direction.
2. The method according to claim 1, characterized in that The step of determining the maximum value of the homogenization parameters corresponding to the displacement vectors in the horizontal direction and / or the vertical direction, and taking the displacement vector corresponding to the maximum value as the texture period of the fabric in the horizontal direction and / or the vertical direction, comprises: Obtaining a relationship curve diagram between the displacement vector and the homogenization parameter according to the homogenization parameter corresponding to each displacement vector in the horizontal direction and / or the vertical direction; Determine the first peak value in the relationship curve diagram corresponding to the horizontal direction and / or the vertical direction, and use the displacement vector corresponding to the first peak value in the horizontal direction and / or the vertical direction as the texture period of the fabric in the horizontal direction and / or the vertical direction.
3. The method according to claim 1, characterized in that The method of calculating the probability distribution of the level difference corresponding to each displacement vector in the horizontal direction and / or the vertical direction according to the displacement vector and the level difference between any two pixels in the horizontal direction and / or the vertical direction includes: According to the displacement vectors and level differences between any two pixels in the horizontal direction and / or the vertical direction, a distribution histogram of the level differences corresponding to each displacement vector in the horizontal direction and / or the vertical direction is obtained; The distribution histogram is normalized to obtain the probability distribution of the level difference corresponding to each displacement vector in the horizontal direction and / or the vertical direction.
4. The method according to claim 1, characterized in that: Calculating the homogenization parameters corresponding to each displacement vector in the horizontal direction and / or the vertical direction according to the probability distribution of the level difference includes: According to the probability distribution and level difference calculation of the level difference corresponding to each displacement vector in the horizontal direction and / or vertical direction, the ratio corresponding to each displacement vector in the horizontal direction and / or vertical direction is obtained, and the sum of the ratios corresponding to each displacement vector in the horizontal direction and / or vertical direction is calculated to obtain the homogenization parameter of each displacement vector in the horizontal direction and / or vertical direction.
5. A device for measuring fabric texture period, characterized in that: The device comprises: An acquisition module, used to acquire an original image of the fabric, and acquire the coordinates and grayscale value of each pixel in the original image; A first calculation module is used to calculate the displacement vector of any two pixels in the horizontal direction and / or the vertical direction, and determine the grayscale of the two pixels according to the grayscale values of the two pixels, calculate the difference of the grayscale of the two pixels, and obtain the grayscale difference of the two pixels, wherein the grayscale includes a plurality of continuously changing grayscale values; A statistical module, for calculating the probability distribution of grayscale differences corresponding to each displacement vector in the horizontal direction and / or the vertical direction according to the displacement vector and the range between any two pixels in the horizontal direction and / or the vertical direction; A homogenization parameter calculation module, used to calculate the homogenization parameter corresponding to each displacement vector in the horizontal direction and / or vertical direction according to the probability distribution of the gray value; A texture period calculation module, used to determine the maximum value of the homogenization parameters corresponding to each displacement vector in the horizontal direction and / or the vertical direction, and use the maximum value as the texture period of the fabric in the horizontal direction and / or the vertical direction; The texture period calculation module is also used to determine the maximum value of the homogenization parameters corresponding to each displacement vector in the horizontal direction and / or the vertical direction, and the displacement vector corresponding to the maximum value of the homogenization parameter is an integer multiple of the texture period; the minimum displacement vector corresponding to the maximum value is used as the texture period of the fabric in the horizontal direction and / or the vertical direction.
6. The device according to claim 5, characterized in that The texture cycle calculation module is also used for: Obtaining a relationship curve diagram between the displacement vector and the homogenization parameter according to the homogenization parameter corresponding to each displacement vector in the horizontal direction and / or the vertical direction; Determine the first peak value in the relationship curve diagram corresponding to the horizontal direction and / or the vertical direction, and use the displacement vector corresponding to the first peak value in the horizontal direction and / or the vertical direction as the texture period of the fabric in the horizontal direction and / or the vertical direction.
7. The device according to claim 5, characterized in that The statistics module is also used for: According to the displacement vectors and level differences between any two pixels in the horizontal direction and / or the vertical direction, a distribution histogram of the level differences corresponding to each displacement vector in the horizontal direction and / or the vertical direction is obtained; The distribution histogram is normalized to obtain the probability distribution of the level difference corresponding to each displacement vector in the horizontal direction and / or the vertical direction.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 4 are implemented.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 4 are implemented.