A simulation method for weft knitted fabrics based on image processing
Through an image-based method, using a relative full variation model and an adaptive K-means clustering algorithm, combining coil shape and light shadow template matrix, the direct conversion from pattern pictures to fabric simulation is achieved, solving the problems of design complexity and inspiration dependence in the existing technology, and achieving convenient simulation of personalized fabric design.
Patent Information
- Application Number
- CN202211543892.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-03
- Publication Date
- 2025-07-08
- Estimated Expiration
- 2042-12-03
AI Technical Summary
Existing CAD systems are difficult to meet the needs of textile designers for product design, especially in achieving the DIY needs of consumers' personalized pattern patterns. Designers need high-level design inspiration to simulate fabric effects.
Using an image processing-based method, a relatively fully variable model and an improved adaptive K-means clustering algorithm are used to extract structure and color information from the flower pattern pictures, and combined with the coil shape and light shadow template matrix to simulate the real fabric effect.
It realizes that the pattern designs are designed manually by designers, and directly simulates the patterns that consumers like onto the fabric, simplifying the design process and improving the convenience and accuracy of personalized design.
Smart Images

Figure CN115937342B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of fabric simulation, and more specifically, to a method for simulating weft knitted fabrics based on image processing. Background Art
[0002] With the development of science and technology, current CAD systems cannot meet the design requirements of textile designers for products. Most CAD systems require designers to manually design pattern designs and finally simulate the effects of actual fabrics. This places high demands on the design inspiration of designers. Since consumers have high requirements for the patterns on clothing, the design ideas of designers cannot meet the needs of consumers. Therefore, this method enables consumers to DIY their favorite pattern designs and can knit their favorite pattern designs onto their own clothes, rather than using other methods such as heat transfer to print patterns onto clothes. Summary of the Invention
[0003] The technical problem to be solved by the present invention is to provide a method for simulating weft knitted fabrics based on image processing, which uses computer image processing technology to extract the pattern designs desired by designers and uses a template matrix to simulate the effects of real fabrics.
[0004] To solve the above technical problems, the present invention adopts the following technical solutions:
[0005] A method for simulating weft knitted fabrics based on image processing, comprising the following steps:
[0006] Step 1: Use a relative total variation model to extract the pattern structure from the pattern design picture to be simulated, and obtain a pattern design picture after removing the texture;
[0007] Step 2: Perform color clustering on the pattern design picture after removing the texture through an improved adaptive K-means clustering algorithm to obtain a picture after color clustering;
[0008] Step 3: Establish a coil shape color template matrix and a lighting and shadow template matrix according to the shape and style of real coils. The coil shape color template matrix and the lighting and shadow template matrix are arrays with the same number of rows and columns composed of multiple pixel points;
[0009] The coil shape color template matrix includes an upper region and a lower region. The upper region is an inverted isosceles triangle and is exactly located in the groove above the lower region. The values of the pixel points in the upper region correspond to the colors of the lower ends of the upper coils of two adjacent coils, and the values of the pixel points in the lower region correspond to the colors of the upper ends of the lower coils of two adjacent coils;
[0010] In the light and shadow template matrix, the value in each pixel represents the brightness of the pixel at the corresponding position, and the value range is [0, 1]. The larger the value, the brighter the color. The light and shadow template matrix is assigned values according to the uneven shadow effect caused by light in the weft knitted fabric.
[0011] Step 4: Divide the image after color clustering into multiple coil units according to the sizes of the coil shape color template matrix and the light and shadow template matrix, and determine the value of the pixel in the coil shape color template matrix corresponding to each coil unit according to the color at the corresponding position.
[0012] Step 5: Perform image simulation on the position of each coil unit according to the corresponding coil shape color template matrix and light and shadow template matrix to obtain a simulation diagram of the weft knitted fabric.
[0013] Further, the relative total variation model formula in Step 1 is:
[0014]
[0015] In the formula, m represents a certain pixel, p represents the index of the two-dimensional image pixel, S p represents the processed structural information image, I p represents the original image to be processed, WTV x (m) and WTV y (m) are the window total variations of the pixel m in the horizontal direction x and the vertical direction y respectively. ε is a constant value and ε > 0, and λ represents the weight.
[0016] Further, in Step 2, the specific steps of the adaptive color clustering method are as follows:
[0017] Step 2.1: Convert the pattern image after removing the texture from the RGB color space to the HSV color space, calculate the histograms of the H, S, and V components respectively, find the peaks in the histograms, find the best peaks according to the preset best peak range and find their quantities, and determine the RGB pixel values corresponding to these K peaks as the initial clustering centers. The clustering centers are {c1, c2, c3,..., c k}}, and convert the image to the Lab color space.
[0018] Step 2.2: Calculate the geometric distances from all other pixels in the image to all clustering centers.
[0019] Step 2.3: Select the clustering center with the shortest geometric distance as the category of the corresponding pixel.
[0020] After classifying all pixels, according to the formula
[0021]
[0022] Update all the cluster centers again;
[0023] Step 2.5: Repeat Steps 2.2 - 2.4 until the geometric distance is less than a certain threshold ε and no longer changes, determine that the clustering ends, and obtain the final clustering image;
[0024] Step 2.6: Convert the final clustering image to the RGB color space to obtain the image after color clustering.
[0025] Furthermore, the geometric distance is the Euclidean distance, Mahalanobis distance, or Manhattan distance. The clustering results obtained in Step 2.5 include the corresponding clustering results obtained when using three different distance types, and finally, the clustering result with the largest retained structural information is selected as the final clustering image.
[0026] Furthermore, both the number of rows and columns of the coil shape color template matrix and the illumination and shadow template matrix are 8 and 11 respectively.
[0027] Furthermore, in the coil shape color template matrix, the upper region includes all the pixel points in the first and second rows, all the pixel points in the third row except the first and last columns, all the pixel points in the fourth row except the first, second, tenth, and eleventh columns, the pixel points in the fourth, fifth, sixth, seventh, and eighth columns of the fifth row, and the pixel point in the sixth column of the sixth row; the lower region includes all the pixel points except the upper region.
[0028] Furthermore, in the illumination and shadow template matrix, the values in the first row are 0.7, 0.8, 0.85, 1, 0.95, 0.79, 0.95, 1, 0.85, 0.8, 0.68; the values in the second row are 0.8, 0.6, 0.85, 1, 0.85, 0.79, 0.85, 1, 0.85, 0.6, 0.8; the values in the third row are 0.85, 0.75, 0.75, 1, 0.8, 0.7, 0.8, 1, 0.85, 0.75, 0.85; the values in the fourth row are 0.75, 0.8, 0.59, 0.9, 0.8, 0.74, 0.8, 0.9, 0.59, 0.8, 0.7; the values in the fifth row are 0.7, 0.9, 0.9, 0.61, 0.75, 0.55, 0.75, 0.55, 0.9, 0.9, 0.7; the values in the sixth row are 0.75, 0.95, 1, 0.89, 0.75, 0.55, 0.7, 0.89, 1, 0.95, 075; the values in the seventh row are 0.8, 0.9, 1, 0.95, 0.61, 0.55, 0.6, 0.95, 1, 0.9, 0.8; the values in the eighth row are 0.78, 0.7, 0.9, 1, 0.9, 0.56, 0.8, 1, 0.9, 0.7, 0.5.
[0029] After the present invention adopts the above technical solutions, compared with the prior art, it has the following advantages:
[0030] Currently, the methods of fabric simulation are all based on the loop function, with relatively complex simulation and large computational amount. At the same time, they can only simulate the situation of single-color yarns and cannot realize the patterns on DIY clothes. Most CAD systems require designers to manually design the flower patterns and finally simulate the actual fabric effect, which requires high design inspiration from designers.
[0031] The present invention uses image processing technology to simulate the real effect of the fabric. At the same time, the patterns on the fabric do not need to be redesigned by designers. One can select a favorite picture, extract the pattern on the picture and simulate it on the fabric to achieve personalized design. At the same time, it is more convenient to use the two-dimensional simulation effect instead of the three-dimensional simulation.
[0032] The present invention will be described in detail below with reference to the drawings and embodiments. Description of the Drawings
[0033] Figure 1 is a schematic diagram of the overall process flow of the method of the present invention;
[0034] Figure 2 is a matrix diagram of the coil shape color template;
[0035] Figure 3 is a schematic diagram of the illumination shadow template matrix;
[0036] Figure 4 is a picture of the flower pattern to be simulated;
[0037] Figure 5 is a picture of the flower pattern after removing the texture;
[0038] Figure 6 is a picture after color clustering;
[0039] Figure 7 is a simulation diagram of weft knitted fabric. Detailed Embodiment
[0040] The principles and features of the present invention will be described below with reference to the drawings. The examples given are only for explaining the present invention and are not intended to limit the scope of the present invention.
[0041] As Figure 1 shown, a method for simulating weft knitted fabric based on image processing includes the following steps:
[0042] 1. As Figure 4 shown, use the relative total variation model to extract the flower pattern structure in the picture of the flower pattern to be simulated, and obtain the picture of the flower pattern after removing the texture (Figure 5 )。The formula of the relative total variation model is as follows
[0043]
[0044] In the above formula, m is a certain pixel point, p represents the index of two-dimensional image pixels, S p represents the processed structural information image, and I p represents the original image to be processed, WTV x (m) and WTV y (m) are the window total variations of pixel point m in the horizontal direction x and the vertical direction y respectively. ε is a constant value (and ε > 0), and its function is to ensure that the denominator of each term in the above formula is not zero, enabling each pixel point to perform operations on the relative total variation model. The first term arg min S ∑ p (S p -I p ) 2 functions to ensure that the processed structural information image does not have too large a difference from the original image. In the second term, represents the regularization term, which is also a method introduced in the relative total variation model to solve the problem of removing texture information and extracting structural information. λ represents the weight, controlling the proportion of the regularization term.
[0045] 2. Perform color clustering on the flower pattern image after removing texture through the adaptive color clustering algorithm to obtain the image after color clustering ( Figure 6 ), and use the clustering algorithm with the fewest colors while maximizing the retention of structural color information. The specific steps of the clustering method are as follows:
[0046] Step 2.1: Convert the flower pattern image after removing texture from the RGB color space to the HSV color space, calculate the histograms of the H, S, and V components respectively, find the peaks in the histograms, and find the best peak and its quantity according to the preset best peak range. Define the RGB pixel values corresponding to these K peaks as the initial clustering centers, and the clustering centers are {c1, c2, c3,..., c k}}, and convert the image to the Lab color space;
[0047] Step 2.2: Calculate the geometric distances from all other pixel points in the image to all clustering centers. The geometric distance is the Euclidean distance, Mahalanobis distance, or Manhattan distance;
[0048] Step 2.3: Select the clustering center with the shortest geometric distance as the category of the corresponding pixel point;
[0049] Step 2.4: After classifying all pixel points, according to the formula
[0050]
[0051] Update all the cluster centers again;
[0052] Step 2.5: Repeat Steps 2.2 - 2.4 until the geometric distance is less than a certain threshold ε and no longer changes, determine that the clustering ends, and obtain the corresponding clustering results when using three different distance types respectively. Finally, select the clustering result with the largest retained structural information as the final clustering picture;
[0053] Step 2.6: Convert the final clustering picture into the RGB color space to obtain the picture after color clustering.
[0054] 3. According to the shape and style of the real coil, establish two 8×11 template matrices, namely the coil shape color template and the lighting shadow template.
[0055] Figure 2 The left figure shows the correspondence between the template and the fabric physical photo. It can be seen that each template corresponds to a coil. The coil shape color template is as Figure 2 shown in the middle figure. However, since the calculation is complex during the process of traversing the entire picture and simulating using this template matrix, it is adjusted to Figure 2 the style shown in the right figure. The number 1 in the figure represents the color of the template matrix above this template matrix, and the number 2 represents the color of the template matrix below this template matrix, so as to ensure that the color of each coil is the same.
[0056] The lighting shadow template is as Figure 3 shown. The numbers in it are the V values of the template matrix in the HSV color space. V represents the lightness and darkness of the color, and the value range is [0, 1]. Within this range, the larger the value, the brighter the color. When the lightness is 0, it represents pure black, and the color is the darkest at this time. By modifying the V value, the uneven shadow effect caused by lighting in the actual weft knitted fabric is shown.
[0057] 4. Divide the picture after color clustering into multiple coil units according to the sizes of the coil shape color template matrix and the lighting shadow template matrix, and determine the pixel values in the coil shape color template matrix and the lighting shadow template matrix corresponding to each coil unit according to the color and lightness at the corresponding positions;
[0058] 5. Perform image simulation according to the coil shape color template matrix and the lighting shadow template matrix corresponding to each coil unit to obtain the simulation diagram of the weft knitted fabric ( Figure 7 ).
[0059] The above are examples of the best implementation modes of the present invention, and the parts not described in detail are all common general knowledge in the art. The protection scope of the present invention shall be subject to the content of the claims, and any equivalent transformation based on the technical inspiration of the present invention is also within the protection scope of the present invention.
Claims
1. A simulation method for weft knitted fabrics based on image processing, characterized in that, Including the following steps: Step 1: Use the relative total variation model to extract the pattern structure from the pattern picture to be simulated, and obtain the pattern picture after removing the texture; Step 2: Perform color clustering on the pattern picture after removing the texture through the adaptive color clustering algorithm to obtain the picture after color clustering; Step 3: Establish a coil shape color template matrix and a lighting and shadow template matrix according to the shape and style of the real coil. The coil shape color template matrix and the lighting and shadow template matrix are arrays with the same number of rows and columns composed of multiple pixel points; The coil shape color template matrix includes an upper region and a lower region. The upper region is an inverted isosceles triangle and is exactly located in the groove above the lower region. The value in the pixel points of the upper region corresponds to the color of the lower end of the upper coil of two adjacent coils, and the value in the pixel points of the lower region corresponds to the color of the upper end of the lower coil of two adjacent coils; In the lighting and shadow template matrix, the value of each pixel point represents the brightness of the pixel point at the corresponding position, and the value range is [0, 1]. The larger the value, the brighter the color. The lighting and shadow template matrix is assigned according to the uneven shadow effect caused by lighting in the weft knitted fabric; Step 4: Divide the picture after color clustering into multiple coil units according to the sizes of the coil shape color template matrix and the lighting and shadow template matrix, and determine the value of the pixel point in the coil shape color template matrix corresponding to each coil unit according to the color at the corresponding position; Step 5: Perform image simulation on the position of each coil unit according to the corresponding coil shape color template matrix and lighting and shadow template matrix to obtain a simulation diagram of the weft knitted fabric.
2. The method for simulating weft knitted fabrics based on image processing according to claim 1, characterized in that, The formula of the relative total variation model in Step 1 is: In the formula, m represents a certain pixel point, p represents the index of the two-dimensional image pixel, S p represents the processed structural information image, I p represents the original image to be processed, WTV x (m) and WTV y (m) are the window total variation of the pixel point m in the horizontal direction x and the vertical direction y respectively, ε is a constant value and ε > 0, and λ represents the weight.
3. The weft knitted fabric simulation method based on image processing according to claim 1, wherein In Step 2, the specific steps of the adaptive color clustering method are: Step 2.1: Convert the flower pattern image after texture removal from the RGB color space to the HSV color space, calculate the histograms of the H, S, and V components respectively, find the peaks in the histograms, find the best peak according to the preset optimal peak range and its quantity, and define the RGB pixel values corresponding to the K peaks here as the initial clustering centers, and the clustering centers are {c1, c2, c3,..., c k}}, and convert the image to the Lab color space; Step 2.2: Calculate the geometric distances from all other pixel points in the picture to all cluster centers; Step 2.3: Select the cluster center with the shortest geometric distance as the category of the corresponding pixel point; Step 2.4: After classifying all pixel points, according to the formula Update all cluster centers again; Step 2.5: Repeat Steps 2.2 - 2.4 until the geometric distance is less than a certain threshold ε and no longer changes, judge that the clustering ends, and obtain the final clustered picture; Step 2.6: Convert the final clustered picture into the RGB color space to obtain the picture after color clustering.
4. The weft knitted fabric simulation method based on image processing according to claim 1, characterized in that, Both the number of rows of the coil shape color template matrix and the lighting and shadow template matrix is 8, and the number of columns is 11.
5. The method for simulating weft knitted fabric based on image processing according to claim 4, characterized in that In the coil shape color template matrix, the upper region includes all pixel points in the first row and the second row, all pixel points in the third row except the first column and the last column, all pixel points in the fourth row except the first, second, tenth, and eleventh columns, pixel points in the fourth, fifth, sixth, seventh, and eighth columns of the fifth row, and the pixel point in the sixth column of the sixth row; the lower region includes all pixel points except the upper region.
6. The method for simulating weft knitted fabrics based on image processing according to claim 1, characterized in that In the light and shadow template matrix, the values in the first row are 0.7, 0.8, 0.85, 1, 0.95, 0.79, 0.95, 1, 0.85, 0.8, 0.68; the values in the second row are 0.8, 0.6, 0.85, 1, 0.85, 0.79, 0.85, 1, 0.85, 0.6, 0.8; the values in the third row are 0.85, 0.75, 0.75, 1, 0.8, 0.7, 0.8, 1, 0.85, 0.75, 0.85; the values in the fourth row are 0.75, 0.8, 0.59, 0.9, 0.8, 0.74, 0.8, 0.9, 0.59, 0.8, 0.7; the values in the fifth row are 0.7, 0.9, 0.9, 0.61, 0.75, 0.55, 0.75, 0.55, 0.9, 0.9, 0.7; the values in the sixth row are 0.75, 0.95, 1, 0.89, 0.75, 0.55, 0.7, 0.89, 1, 0.95, 075; the values in the seventh row are 0.8, 0.9, 1, 0.95, 0.61, 0.55, 0.6, 0.95, 1, 0.9, 0.8; the values in the eighth row are 0.78, 0.7, 0.9, 1, 0.9, 0.56, 0.8, 1, 0.9, 0.7, 0.
5.
7. The weft knitted fabric simulation method based on image processing according to claim 3, wherein The geometric distance is Euclidean distance, Mahalanobis distance or Manhattan distance. The clustering results obtained in step 2.5 include the corresponding clustering results obtained when three different distance types are used. Finally, the clustering result with the largest retained structural information is selected as the final clustering picture.