A method for automatically generating sketch painting sequence sets
The sketch sequence set is generated through structural line extraction and edge processing, which solves the problem of high sample collection cost in hand-drawn sketch image retrieval, realizes efficient sketch sequence set generation, and is suitable for image retrieval model training and sketch learning.
Patent Information
- Application Number
- CN202210497284.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-09
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2042-05-09
AI Technical Summary
In hand-drawn sketch image retrieval, collecting incomplete sketch samples for training models requires a lot of manpower and time costs, and existing technologies cannot generate hand-drawn sketch sequence sets.
Through the pre-trained structural line extraction model, the structural line image is pre-processed, edge processed and expanded to generate an incomplete sketch sequence set in the sketch painting process, and the dot multiplication operation is performed with the complete sketch image to generate a sketch painting sequence set.
It reduces the labor and time costs of obtaining training samples for image retrieval models, provides a series of hand-drawn sketching process diagrams to help beginners understand the sketching process, and reduces the limitations of the technology to generate complete sketches of color images.
Smart Images

Figure CN114782586B_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the field of sketch painting sequence set generation, and in particular relates to a method for automatically generating a sketch painting sequence set. Background Art
[0002] With the widespread use of mobile devices with touch screen functions, hand-drawn sketch data has exploded. Each hand-drawn sketch has its corresponding target image. The problem of efficient image retrieval based on hand-drawn sketches has become a hot issue in the field of computer vision. However, drawing a complete sketch image requires not only a certain painting foundation, but also a long painting time. Therefore, the idea of how to use sketches with fewer strokes to retrieve target images came into being. Model training is constructed based on this idea. During the training process, a hand-drawn sketch sequence set consisting of a collection of incomplete sketches at different stages of the sketch painting process is required. However, collecting a hand-drawn sketch sequence set corresponding to a real picture for training is a very difficult task, which requires a lot of manpower and a very high time cost. In addition, the existing sketch generation technology can only generate corresponding complete sketches from the original color image, and there is no method to generate a hand-drawn sketch sequence set. Summary of the invention
[0003] In order to solve the problem of efficient image retrieval of hand-drawn sketches, the model used for image retrieval requires a large number of incomplete sketch samples for training, and collecting such training samples requires a lot of manpower, high cost and a long time. The present invention provides a method for automatically generating a sketch painting sequence set, which is used to generate an incomplete sketch painting sequence set in the sketch painting process, that is, incomplete sketches at various stages of sketch painting.
[0004] A method for automatically generating a sketch painting sequence set comprises the following steps:
[0005] S1. Obtaining a structure line image of the complete sketch image through a pre-trained structure line extraction model;
[0006] S2. Preprocessing the structure line image to obtain an edge line set;
[0007] S3. Perform edge processing on the edge line set to obtain a second edge sequence set;
[0008] S4. using the second edge sequence set to draw an edge sequence set, and performing expansion processing on the edge sequence set;
[0009] S5. Perform a dot multiplication operation on the expanded edge sequence set and the complete sketch image to obtain a sketch painting sequence set.
[0010] Furthermore, the preprocessing process in step S2 is:
[0011] S101. Binarize the structure line image to obtain a binary image, and use Gaussian filtering to remove noise from the binary image;
[0012] S102. Using the edge extraction operator Canny to process the binary image after Gaussian filtering, obtain an edge image;
[0013] S103. Based on the line extraction function, all edge lines of the edge image are obtained to form an edge line set, and the number of pixels contained in each edge line is recorded.
[0014] Furthermore, in step S101, an adaptive binarization algorithm is used to select an L×L square area with each pixel as the center, where the size L of the square area is an odd number, and the weighted sum of the adjacent areas of the square area is calculated as the threshold of the area. If the pixel is greater than the threshold, the pixel value is 255, and if the pixel is less than the threshold, the pixel value is 0.
[0015] Furthermore, after Gaussian filtering of the binary image, the maximum inter-class variance method is used to calculate the adaptive threshold, and 1 / F of the adaptive threshold is used as the minimum threshold, F is a hyperparameter, and the adaptive threshold is used as the maximum threshold. When using the Canny edge extraction operator, edge detection is performed based on the minimum threshold and the maximum threshold.
[0016] Furthermore, the process of obtaining the second edge sequence set is:
[0017] S201. Determine whether the number of pixels contained in the edge line exceeds the pixel threshold. If so, retain the edge line; otherwise, discard the edge line.
[0018] S202. Arrange the edge lines retained in S201 in descending order according to the number of pixels, and connect the retained edge lines together in sequence to form a first edge sequence;
[0019] S203. According to the total number N of pixels in the first edge sequence, the first edge sequence is evenly divided into M second edge sequences to form a second edge sequence set, where M is the total number of sketch drawing sequences required.
[0020] Furthermore, the process of step S4 includes:
[0021] S301. Generate a blackboard of the same size as the input complete sketch image;
[0022] S302. Use a drawing function to sequentially draw the second edge sequence in the second edge sequence set on the blackboard, and save the drawing image each time it is drawn;
[0023] S303. After the second edge sequence set is drawn, all the saved drawn images are combined into a drawn edge sequence set, and a dilation algorithm is used to perform dilation processing.
[0024] Beneficial effects of the present invention:
[0025] The present invention provides a method for automatically generating a sketch painting sequence set. The method for automatically generating a sketch painting sequence set refers to a method for taking a hand-drawn complete sketch image lacking color information as input, using a painting sequence set generation system to simulate a real sketch painting process, and outputting a set of incomplete sketches at different stages of the hand-drawn complete sketch image.
[0026] The present invention constructs a painting sequence set generation system, which uses graphics methods to simulate the real sketch painting process, thereby generating a series of process diagrams of hand-drawn sketches. The system processes the complete sketch through operations such as binarization and contour extraction algorithm, extracts its edge sequence, performs a series of processing on the edge sequence according to the number of pixels, removes redundant lines, and ensures the accuracy and clarity of the subsequent generated image. At the same time, it performs dot multiplication operation with the original corresponding complete sketch, thereby obtaining a drawing stage diagram of the complete sketch, which can be used for training image retrieval models, reducing the labor cost and time cost of obtaining image retrieval model training samples.
[0027] Previous technologies all generated complete sketches corresponding to color images, but there was no technology for generating sketch drawing sequence sets. In addition, this method can also allow people who do not understand painting to understand the general process of sketch painting, and can also help painting beginners to copy and learn sketch painting. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] Figure 1 A flowchart of the method for automatically generating a sketch painting sequence set of the present invention;
[0029] Figure 2 A schematic block diagram of a method for automatically generating a sketch painting sequence set according to the present invention;
[0030] Figure 3 Automatically generate a schematic diagram for a sketch painting sequence set according to an embodiment of the present invention;
[0031] Figure 4 FIG. 4 is a schematic diagram of expansion according to an embodiment of the present invention. DETAILED DESCRIPTION
[0032] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0033] A method for automatically generating a sketch painting sequence set, such as Figure 1 , 2 The method comprises the following steps:
[0034] S1. Obtaining a structure line image of the complete sketch image through a pre-trained structure line extraction model;
[0035] S2. Preprocessing the structure line image to obtain an edge line set;
[0036] S3. Perform edge processing on the edge line set to obtain a second edge sequence set;
[0037] S4. using the second edge sequence set to draw an edge sequence set, and performing expansion processing on the edge sequence set;
[0038] S5. Perform a dot multiplication operation on the expanded edge sequence set and the complete sketch image to obtain a sketch painting sequence set.
[0039] In one embodiment, a complete sketch is obtained from the FS2K data set, and the complete sketch is processed using the method of the present invention to obtain a sketch drawing sequence set corresponding to the complete sketch, that is, a set of incomplete sketches at various stages of drawing the complete sketch, such as Figure 3 As shown, the following steps are included:
[0040] S11. Use the pre-trained structure line extraction model to obtain the structure line image of the complete sketch, that is, use the pre-trained structure line extraction model to remove the blurred lines other than the clear structure lines in the complete image, and only retain the conceptual sketch without focusing on the perspective relationship, light and dark relationship, and details of the sketch, so that the subsequent process can focus on the content of the structure line;
[0041] S12. Binarizing the structure line image to obtain a binary image;
[0042] Specifically, an adaptive binarization algorithm is used, and an L×L square area is selected as the center for each pixel point, where L is an odd number, such as 3, 5, 7, etc. If the original image has more information, a larger value is selected, and if the original image has less information, a smaller value is selected. The weighted sum of the adjacent areas of the square area is calculated as the threshold of the area. If the pixel point is greater than the threshold, the pixel point takes a value of 255. If the pixel point is less than the threshold, the pixel point takes a value of 0. For different types of sketches, the size of the area selected when the pixel point is used as the center may be different.
[0043] Specifically, the weighted sum of adjacent areas is to multiply each pixel in the square area by the coefficient of the corresponding position in the weight template, and then accumulate all the products. The accumulated result is the weighted sum of the adjacent areas, which is also the threshold of the square area. The weight template is generated by calling the built-in function and only requires the value of the size L of the square area.
[0044] S13. Performing Gaussian filtering on the binary image to remove noise in the binary image, so as to ensure that the subsequently generated image focuses on the structural lines;
[0045] Specifically, the appropriate Gaussian filter is selected through parameter adjustment comparison to filter the binary image, eliminating the negative impact of noise in the blank area on the generated template. That is, when processing different images, the type of Gaussian filter used is flexibly adjusted. If the image contains more information, a small-scale Gaussian filter is used for processing, and if the image contains less information, a large-scale Gaussian filter is used for processing.
[0046] S14. Using the edge extraction operator Canny to process the binary image after Gaussian filtering to obtain an edge image;
[0047] Specifically, when using the Canny edge extraction operator for edge detection, the adaptive threshold is calculated through the binary image after Gaussian filtering, 1 / F of the adaptive threshold is used as the minimum threshold, the adaptive threshold is used as the maximum threshold, and the minimum threshold and the maximum threshold are used to select edge information. Among them, F is a hyperparameter, which is selected according to the characteristics of the processed image. In this embodiment, F=2 is used.
[0048] Specifically, pixels above the maximum threshold are considered edges, and pixels below the minimum threshold are considered non-edges. For pixels between the minimum threshold and the maximum threshold, if they are adjacent to pixels determined to be edges, they are determined to be edge pixels, otherwise they are determined to be non-edge pixels.
[0049] Specifically, the Otsu threshold segmentation method is used for adaptive threshold calculation. The Otsu threshold segmentation method is the optimal segmentation in the sense of the least squares method. It selects a threshold through a statistical method so that the threshold can separate the foreground color and the background color as much as possible. The judgment basis is the maximum inter-class variance.
[0050] This method means that for an image, it can be divided into two parts: foreground and background. The foreground refers to the target object, and the background refers to the background. The segmentation threshold of the foreground and background is t. The proportion of pixels belonging to the foreground in the entire image is recorded as PA, and its average gray value is MA. The proportion of pixels belonging to the background in the entire image is recorded as PB, and its average gray value is recorded as MB. The gray average value of the entire image is recorded as M. The inter-class variance is defined as follows:
[0051] ICV=PA*(MA-M) 2 +PB*(MB-M) 2
[0052] The value that maximizes ICV is the optimal segmentation threshold t, which is used as the adaptive threshold.
[0053] S15. Obtain edge lines of the edge image by extracting line functions, form an edge line set, count the number of pixels contained in each edge line, retain edge lines that exceed the pixel threshold, discard fine edges that do not reach the pixel threshold, and reduce the impact of fine edges or circles on subsequent operations;
[0054] The pixel threshold is selected based on the characteristics of the image after edge extraction, and is generally a value between 10 and 15. If it exceeds this range, some required edges may be removed.
[0055] S16. Arrange the edge line set with the fragmented edges removed in descending order according to the number of pixels, put the edge lines with longer lines in the front and the edge lines with shorter lines in the back, and then connect all the edge lines in order to form a long edge sequence;
[0056] S17. Divide the edge long sequence into M second edge sequences evenly, where M represents the number of sketch drawing sequences to be generated. Since there may be decimals in each sequence after division, an increasing list is used for approximate division;
[0057] Specifically, the approximate partitioning using increasing lists means that when a long edge sequence is formed, a long list is generated at the same time. The long list records the coordinate information of all pixel points in order. When the long edge sequence is evenly divided into M second edge sequences, M lists with increasing positions are generated to intercept the corresponding parts in the long list.
[0058] If the edge long sequence has a total of 100 pixels, the starting position of the list is 0, and the ending position is 99, then the pixels in the list are 0 to 99, that is, [0~99], a total of 100 pixels. If it is divided into three equal parts, the first part should contain 33.3... pixels. Since it cannot be a decimal, it is rounded down. The first part contains 33 pixels, which corresponds to the list of pixels from position 0 to position 32. Similarly, the second part also has 33 pixels. If the position is incremented, it corresponds to the 33 pixels from position 33 to position 65 in the list. However, the third part is the last part. If 33 are also taken, there will be one pixel left. Therefore, when the list has a remainder after equal division, the remainder will be assigned to the last part, that is, the last part contains 34 pixels, all pixels from position 66 to 99, a total of 34 bits.
[0059] The 0-99 here is just a regulation of the programming language, and can also be understood as an index of 1-100. The main purpose of this part is to divide the long edge sequence evenly. If there are decimals when dividing, the pixel points corresponding to the remainder after division can be placed in the last part of the division. The use of an incremental list can solve the problem that the total number of pixels in the long list cannot be evenly divided and there are decimal points. S18. Generate a blackboard of the same size as the complete sketch, and use the drawing function to incrementally draw the second edge sequence on the blackboard. Each time the incremental drawing is done, the current state is saved once and recorded as an edge sequence until all second edge sequences are drawn to obtain an edge sequence set;
[0060] Specifically, when simulating the real sketch drawing process, the long edges are drawn first in the early stage of drawing to determine the approximate shape of the drawing target, and then the short edges are used to increase the sketch details.
[0061] S19. The edge sequence set is expanded using an expansion algorithm. Since the edges extracted by Canny will form the outer edges of the sketch line segments in the original complete sketch, the expansion algorithm is used to expand and combine such outer edges into thick line block areas, thereby forming the template sequence required for operation (the expanded edge sequence); Figure 4 As shown, the first picture is the original sketch line segment. After extracting the edge, an outer edge like the second picture will be formed around the original sketch line segment. The outer edge in the second picture is expanded using the expansion algorithm to obtain the template of the third picture. The dot product (bitwise AND) of this template and the original sketch can obtain the sketch line segment at the corresponding position.
[0062] S20. Perform a dot multiplication operation on the edge sequence set after the dilation process and the complete sketch, that is, perform a bitwise AND operation on the corresponding pixel points, so as to obtain the sketch lines corresponding to the edge sequence, thereby obtaining the sketch painting sequence set. Specifically, if Figure 3 As shown, this embodiment shows the image after inverse mapping, that is, the image is a white background with black lines, while the image before inverse mapping is a black background with white lines. This method processes the image before inverse mapping. At this time, the black background pixel value is 0, and the corresponding binary value is 0000 0000, the white line pixel value is 255, and the corresponding binary value is 11111111. The template for bitwise AND operation (the edge sequence set after expansion) is also a black background with white lines. When performing bitwise AND operation, the area with a pixel value of 255 in the complete sketch of the black background with white lines and the area with a pixel value of 255 in the template of the black background with white lines are ANDed in binary corresponding positions, and finally the sketch line segment of the template corresponding area is retained, and then the inverse mapping can be obtained as shown below. Figure 3 Image with black lines on a white background shown.
[0063] Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the appended claims and their equivalents.
Claims
1. A method for automatically generating a sketch painting sequence set, characterized in that: include: S1. Obtaining a structure line image of the complete sketch image through a pre-trained structure line extraction model; S2. Preprocessing the structure line image to obtain an edge line set; The preprocessing process in step S2 is: S101. Binarize the structure line image to obtain a binary image, and use Gaussian filtering to remove noise from the binary image; S102. Using the edge extraction operator Canny to process the binary image after Gaussian filtering, obtain an edge image; S103. Obtain all edge lines of the edge image based on the line extraction function to form an edge line set, and record the number of pixels contained in each edge line; S3. Perform edge processing on the edge line set to obtain a second edge sequence set; The process of obtaining the second edge sequence set is: S201. Determine whether the number of pixels contained in the edge line exceeds the pixel threshold, if so, retain the edge line, otherwise discard the edge line; S202. Arrange the edge lines retained in S201 in descending order according to the number of pixels, and sequentially connect the retained edge lines together to form a first edge sequence; S203. According to the total number of pixels N of the first edge sequence, the first edge sequence is evenly divided into M second edge sequences to form a second edge sequence set, where M is the total number of sketch drawing sequences required; S4. using the second edge sequence set to draw an edge sequence set, and performing expansion processing on the edge sequence set; The process of step S4 includes: S301. Generate a blackboard of the same size as the input complete sketch image; S302. Use a drawing function to sequentially draw the second edge sequence in the second edge sequence set on the blackboard, and save the drawing image each time it is drawn; S303. After the second edge sequence set is drawn, all the saved drawn images are combined into a drawn edge sequence set, and an expansion algorithm is used to perform expansion processing; S5. Perform a dot multiplication operation on the expanded edge sequence set and the complete sketch image to obtain a sketch painting sequence set; The sketch drawing sequence set is a collection of incomplete sketches at various stages of drawing the complete sketch.
2. The method for automatically generating a sketch painting sequence set according to claim 1, characterized in that: In step S101, an adaptive binarization algorithm is used to select an L×L square area with each pixel as the center. The size of the square area L is an odd number. The weighted sum of the adjacent areas of the square area is calculated as the threshold of the area. If the pixel is greater than the threshold, the pixel value is 255. If the pixel is less than the threshold, the pixel value is 0.
3. The method for automatically generating a sketch painting sequence set according to claim 1, characterized in that: After Gaussian filtering of the binary image, the maximum inter-class variance method is used to calculate the adaptive threshold. 1 / F of the adaptive threshold is used as the minimum threshold, F is a hyperparameter, and the adaptive threshold is used as the maximum threshold. When using the Canny edge extraction operator, edge detection is performed based on the minimum threshold and the maximum threshold.
Citation Information
Patent Citations
Traffic-video-based moving vehicle detection method
CN106780548A
Fine-grained freehand sketch image retrieval method based on attention enhancement
CN111488474A
Hand-drawn image real-time retrieval method based on multi-granularity associative learning
CN113886615A
Sketch based search methods
WO2017168125A1
