Model chart generation method and device for clothes edge optimization, equipment and medium
By redrawing and correcting the edges of clothes in the model picture, the problem of small areas where the edges of clothes in the prior art is unnatural, a more natural edge redrawing effect is achieved, and the usability of AI model picture generation is improved.
Patent Information
- Application Number
- CN202510108264.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-23
- Publication Date
- 2025-05-30
AI Technical Summary
In the existing AI-assisted model picture generation technology, unnatural small areas are prone to appear on the edges of the clothes in the generated model picture, affecting the visual effect of the image.
By cutting the clothes from the uploaded model diagram, extracting the transparent channel and converting it into a binary diagram, edge contour extraction and operation difference diagram generation, inputting the diffusion model with the edge line diagram of the clothes, and performing edge redrawing correction.
Effectively correct and restore the edges of the clothes, making them clean and natural after redrawing, and blending with the background without color difference, greatly improving the usability of AI model pictures generated.
Smart Images

Figure CN120070626A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a method, apparatus, device and medium for generating a model image with optimized clothing edges. Background Art
[0002] In the prior art, in the process of generating a model image assisted by AI, specifically: First, upload a photo of a real model, then accurately cut out the clothing area on the model and use it as a mask. Then, use a text-image large model to carefully redraw the area outside the mask to achieve seamless replacement of the model, clothing, and background, while ensuring that the clothing area remains unchanged.
[0003] However, in the implementation of this technology, there are some problems. Although auxiliary conditions are adopted, such as extracting the line drawing of the clothing to guide the text-image large model to maintain the integrity of the clothing edge during the generation process, limited by the accuracy of the current technology, there will be some additional small areas at the clothing edge in the generated model image. These small areas make the clothing edge appear unnatural, as if it has been manually modified or irregular, resulting in the finally generated model image looking rough visually and affecting its effect in practical applications. Summary of the Invention
[0004] The technical problem to be solved by the present invention is to provide a method, apparatus, device and medium for generating a model image with optimized clothing edges, which can effectively correct and restore the clothing edge, making the clothing edge of the redrawn image cleaner and more natural in fusion with the background.
[0005] In a first aspect, the present invention provides a method for generating a model image with optimized clothing edges, including the following steps:
[0006] Step 1: Cut out the clothing area from the uploaded model image to obtain a clothing cutout, extract the alpha channel in the clothing cutout, and convert it into a binary Figure 1 ;
[0007] Step 2: Extract the edge contour of the binary Figure 1 to form a first contour map; set the line width of the first contour map to the first set value of pixels;
[0008] Step 3: Perform an opening operation on the binary Figure 1 to obtain a binary Figure 2 , the kernel size of the opening operation is n*n, and the opening operation is iterated a set number of times; compare and judge the binary Figure 1 with the Two value Figure 2 , retain the different pixel points among them to obtain a first difference map;
[0009] Step 4: Extract the edge contour of the first difference map to form a second contour map, and set the line width of the second contour map to the first set value of pixels;
[0010] Step 5: Compare the first contour map with the second contour map to obtain the pixel area at the intersection position, and subtract the pixel area at the intersection position from the first contour map to obtain a second difference map;
[0011] Step 6: Extract the clothing edge line map from the alpha channel of the clothing cutout;
[0012] Step 7: Input the second difference map, the clothing edge line map, and the model map into a diffusion model to obtain a generated map.
[0013] In a second aspect, the present invention provides a device for generating a model map with optimized clothing edges, including:
[0014] A cutout module that cuts out the clothing area from the uploaded model map to obtain a clothing cutout, extracts the alpha channel in the clothing cutout, and converts it into a binary Figure 1 ;
[0015] A first contour module that extracts the edge contour of the binary Figure 1 to form a first contour map; sets the line width of the first contour map to the first set value of pixels;
[0016] A first difference module that performs an opening operation on the binary Figure 1 to obtain a binary Figure 2 , where the kernel size of the opening operation is n*n, and the opening operation is iterated a set number of times; compares and determines the binary Figure 1 with Two values Figure 2 to retain the different pixel points to obtain a first difference map;
[0017] A second contour module that extracts the edge contour of the first difference map to form a second contour map, and sets the line width of the second contour map to the first set value of pixels;
[0018] A second difference module that compares the first contour map with the second contour map to obtain the pixel area at the intersection position, and subtracts the pixel area at the intersection position from the first contour map to obtain a second difference map;
[0019] A line map module that extracts the clothing edge line map from the alpha channel of the clothing cutout;
[0020] A generation module that inputs the second difference map, the clothing edge line map, and the model map into a diffusion model to obtain a generated map.
[0021] In a third aspect, the present invention provides an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the program, the method described in the first aspect is implemented.
[0022] In a fourth aspect, the present invention provides a computer-readable storage medium, on which a computer program is stored. When the program is executed by a processor, the method described in the first aspect is implemented.
[0023] One or more technical solutions provided by the present invention have at least the following technical effects or advantages:
[0024] By redrawing and correcting the edges of the clothes in the model picture, the present invention ensures that the edges of the clothes after redrawing are clean without irregular tooth marks, and there is no color difference in the edge area of the redrawn clothes, making it blend more naturally with the background, thus greatly improving the usability of the pictures generated by the AI model pictures.
[0025] The above description is only an overview of the technical solution of the present invention. In order to be able to understand the technical means of the present invention more clearly, it can be implemented according to the content of the description. And in order to make the above and other purposes, features and advantages of the present invention more obvious and understandable, the following specific embodiments of the present invention are specifically given. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] The present invention will be further described below with reference to the drawings in conjunction with embodiments.
[0027] Figure 1 It is a flowchart of the method in Embodiment 1 of the present invention;
[0028] Figure 2 It is a schematic structural diagram of the device in Embodiment 2 of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0029] By providing a method, device, equipment, and medium for optimizing the edges of clothes in a model picture, the embodiment of the present application redraws the edge of the clothes in a model picture generated by AI after replacing the picture of the model or the background, making the edge cleaner and more accurate.
[0030] Embodiment 1
[0031] As Figure 1 shown, this embodiment provides a method for generating a model picture with optimized clothes edges, including the following steps:
[0032] Step 1: Crop the clothes area from the uploaded model picture to obtain a clothes crop, extract the alpha channel in the clothes crop, and convert it into a binary Figure 1 , that is, set the pixel values greater than or equal to 127 to 255, and the pixel values less than 127 to 0;
[0033] Step 2: Extract the edges of the binary Figure 1 to form a first contour map; set the line width of the first contour map to a first set value of pixels, and the first set value is 10;
[0034] Step 3: Perform an opening operation on the binary Figure 1 to obtain a binary Figure 2 . The kernel size of the opening operation is n*n, and the opening operation is iterated a set number of times. n can be 5, and the set number of iterations can be 2 times; Compare and judge the values of the binary Figure 1 and Two value Figure 2 , and retain the pixel points that are different among them to obtain a first difference map; The opening operation is an erosion followed by a dilation operation;
[0035] Step 4: Extract the edge contour of the first difference map to form a second contour map, and set the line width of the second contour map to the first set value of pixels;
[0036] Step 5: Compare the first contour map with the second contour map to obtain the pixel area at the intersection position, and subtract the pixel area at the intersection position from the first contour map to obtain a second difference map; that is, the pixels in the area of the first contour map that overlap with the pixel area at the intersection position are all set to 0; The purpose is not to redraw the small area of the edge of the clothes during edge redrawing to prevent obvious changes in this area after redrawing. The first difference map is used as a mask for edge redrawing;
[0037] Step 6: Extract the clothing edge line drawing from the alpha channel of the clothing matte; Extracting accurate clothing edge lines can control the large model to accurately redraw along the edge lines during the redrawing process;
[0038] Step 7: Input the second difference map, the clothing edge line drawing, and the model image into the diffusion model to obtain a generated image. For example, input the second difference map, the clothing edge line drawing, and the model image into stable diffusion, and then perform redrawing with an amplitude of 0.5 on the masked area in the model image.
[0039] In this embodiment, preferably, step 2 is specifically: use the findContours function of OpenCV to extract the edges of the binary Figure 1 to form a first contour map, and use the OpenCV drawing interface to set the line width of the first contour map to a first set value of pixels; that is, draw a region with a width of the first set value of pixels along the edge contour in the first contour map.
[0040] In this embodiment, preferably, step 4 is specifically as follows: Use the findContours function of OpenCV to extract the edge contours of the first difference map to form a second contour map, and use the OpenCV drawing interface to set the line width of the second contour map to a first set value of pixels; that is, draw a region with a width of the first set value of pixels along the edge contours in the second contour map.
[0041] In this embodiment, preferably, step 6 is specifically as follows: Extract the clothing edge line map from the alpha channel of the clothing cutout through the canny edge extraction algorithm of OpenCV.
[0042] Based on the same inventive concept, the present application also provides an apparatus corresponding to the method in Embodiment 1, as detailed in Embodiment 2.
[0043] Embodiment 2
[0044] As Figure 2 shown, in this embodiment, a model map generation apparatus for optimizing the clothing edge is provided, including:
[0045] A cutout module that cuts out the clothing area from the uploaded model map to obtain a clothing cutout, extracts the alpha channel in the clothing cutout, and converts it into a binary Figure 1 , that is, set the pixel values greater than or equal to 127 to 255, and the pixel values less than 127 to 0;
[0046] A first contour module that extracts the edge contours of the binary Figure 1 to form a first contour map; set the line width of the first contour map to a first set value of pixels;
[0047] A first difference module that performs an opening operation on the binary Figure 1 to obtain a binary Figure 2 , the kernel size of the opening operation is n*n, the opening operation is iterated a set number of times, this n can be 5, and the set number of iterations can be 2 times; compare and judge the binary Figure 1 with the Two value Figure 2 , retain the different pixel points among them to obtain a first difference map; the opening operation is an operation of eroding first and then dilating;
[0048] A second contour module that extracts the edge contours of the first difference map to form a second contour map, and sets the line width of the second contour map to the first set value of pixels;
[0049] The second difference module compares the first contour map with the second contour map to obtain the pixel region at the intersection position, and subtracts the pixel region at the intersection position from the first contour map to obtain the second difference map; that is, the pixels in the region of the first contour map that overlap with the pixel region at the intersection position are all set to 0; the purpose is not to redraw the small edge regions of the clothes during edge redrawing to prevent obvious changes in this region after redrawing, and the first difference map is used as the mask for edge redrawing.
[0050] The line drawing module extracts the clothes edge line drawing from the alpha channel of the clothes cutout.
[0051] The generation module inputs the second difference map, the clothes edge line drawing, and the model picture into the diffusion model to obtain the generated picture. For example, the second difference map, the clothes edge line drawing, and the model picture are input into stable diffusion, and then the mask region in the model picture is redrawn with an amplitude of 0.5.
[0052] In this embodiment, preferably, the first contour module is specifically: using the findContours function of OpenCV to extract the edge contours of the binary Figure 1 to form the first contour map, and using the OpenCV drawing interface to set the line width of the first contour map to the first set value of pixels; that is, draw a region with a width of the first set value of pixels along the edge contours in the first contour map.
[0053] In this embodiment, preferably, the second contour module is specifically: using the findContours function of OpenCV to extract the edge contours of the first difference map to form the second contour map, and using the OpenCV drawing interface to set the line width of the second contour map to the first set value of pixels; that is, draw a region with a width of the first set value of pixels along the edge contours in the second contour map.
[0054] In this embodiment, preferably, the line drawing module is specifically: extracting the clothes edge line drawing from the alpha channel of the clothes cutout through the canny edge extraction algorithm of OpenCV.
[0055] Since the device introduced in the second embodiment of the present invention is the device adopted for implementing the method of the first embodiment of the present invention, based on the method introduced in the first embodiment of the present invention, those skilled in the art can understand the specific structure and deformation of the device, so it will not be elaborated here. Any device adopted for the method of the first embodiment of the present invention belongs to the scope protected by the present invention.
[0056] Based on the same inventive concept, this application provides an electronic device embodiment corresponding to the first embodiment, as shown in Embodiment Three.
[0057] Embodiment Three
[0058] This embodiment provides an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, any implementation manner in Embodiment 1 can be realized.
[0059] Since the electronic device introduced in this embodiment is the device adopted to implement the method in Embodiment 1 of this application, based on the method introduced in Embodiment 1 of this application, those skilled in the art can understand the specific implementation manner and various variation forms of the electronic device in this embodiment. Therefore, the specific implementation of how this electronic device realizes the method in the embodiments of this application will not be introduced in detail here. As long as the device adopted by those skilled in the art to implement the method in the embodiments of this application belongs to the scope protected by this application.
[0060] Based on the same inventive concept, this application provides a storage medium corresponding to Embodiment 1, details of which are shown in Embodiment 4.
[0061] Embodiment 4
[0062] This embodiment provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, any implementation manner in Embodiment 1 can be realized.
[0063] The technical solutions provided in the embodiments of this application at least have the following technical effects or advantages:
[0064] In this embodiment, by redrawing and correcting the edges of the clothes in the model picture, it is ensured that the edges of the clothes after redrawing are clean without irregular tooth marks, and there is no color difference in the edge area of the clothes after redrawing, and it blends more naturally with the background, greatly improving the usability of the pictures generated by the AI model pictures.
[0065] Those skilled in the art should understand that the embodiments of the present invention can be provided as a method, a system, or a computer program product. Therefore, the present invention can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present invention can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0066] The present invention is described with reference to the flowcharts and / or block diagrams of methods, apparatuses (systems), and computer program products according to embodiments of the present invention. It should be understood that each flow and / or block in the flowcharts and / or block diagrams, as well as the combination of flows and / or blocks in the flowcharts and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to the processors of general-purpose computers, special-purpose computers, embedded processors, or other programmable data processing devices to generate a machine, such that the instructions executed by the processors of the computer or other programmable data processing devices generate means for implementing the functions specified in one flow Figure 1 one flow or multiple flows and / or blocks Figure 1 means for implementing the functions specified in one block or multiple blocks.
[0067] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to work in a specific manner, such that the instructions stored in the computer-readable memory generate a manufactured article including instruction means that implement the functions specified in one flow Figure 1 one flow or multiple flows and / or blocks Figure 1 means for implementing the functions specified in one block or multiple blocks.
[0068] These computer program instructions can also be loaded onto a computer or other programmable data processing device, such that a series of operation steps are executed on the computer or other programmable device to generate a computer-implemented process, and thus the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in one flow Figure 1 one flow or multiple flows and / or blocks Figure 1 means for implementing the functions specified in one block or multiple blocks.
[0069] Although the specific embodiments of the present invention have been described above, those skilled in the art of this technology should understand that the specific embodiments we described are illustrative rather than used to limit the scope of the present invention. Equivalent modifications and variations made by those skilled in the art in accordance with the spirit of the present invention should be covered by the scope protected by the claims of the present invention.
Claims
1. A method for generating a model image with optimized clothing edges, characterized in that: The steps include: Step 1: Cut out the clothing area from the uploaded model image to obtain a clothing cutout, extract the transparent channel in the clothing cutout, and convert it into a binary image 1; Step 2, extracting the edge contour of the binary image 1 to form a first contour image; setting the line width of the first contour image to a first set value of pixels; Step 3, performing an opening operation on the binary image 1 to obtain a binary image 2, wherein the kernel size of the opening operation is n*n, and the opening operation is iterated a set number of times; comparing the binary image 1 with the binary image 2, retaining the different pixels therein, and obtaining a first difference image; Step 4: extract edge contours from the first difference map to form a second contour map, and set the line width of the second contour map to a first set value of pixels; Step 5: Compare the first contour map with the second contour map to obtain pixel areas at the intersection positions, and subtract the pixel areas at the intersection positions from the first contour map to obtain a second difference map; Step 6: extracting clothing edge line drawings from the transparent channel of the clothing cutout; Step 7: Input the second difference map, the clothing edge line map and the model map into the diffusion model to obtain a generated map.
2. The method for generating a model image with optimized clothing edges according to claim 1, characterized in that: The step 2 specifically comprises: using the findContours function of OpenCV to extract the edge contour of the binary image 1 to form a first contour image, and using the OpenCV drawing interface to set the line width of the first contour image to a first set value of pixels; that is, drawing an area with a width of the first set value of pixels along the edge contour in the first contour image.
3. The method for generating a model image with optimized clothing edges according to claim 1, characterized in that: The step 4 specifically comprises: using the findContours function of OpenCV to extract the edge contour of the first difference image to form a second contour image, and using the OpenCV drawing interface to set the line width of the second contour image to a first set value of pixels; that is, drawing an area with a width of the first set value of pixels along the edge contour in the second contour image.
4. The method for generating a model image with optimized clothing edges according to claim 1, characterized in that: The step 6 is specifically as follows: extracting clothing edge line drawings from the transparent channel of the clothing cutout using the canny edge extraction algorithm of OpenCV.
5. A model image generation device for optimizing clothing edges, characterized in that: include: The cutout module cuts out the clothing area from the uploaded model image to obtain a clothing cutout image, extracts the transparent channel in the clothing cutout image, and converts it into a binary image 1; A first contour module extracts the edge contour of the binary image 1 to form a first contour image; and sets the line width of the first contour image to a first set value of pixels; A first difference module performs an opening operation on the binary image 1 to obtain a binary image 2, wherein the kernel size of the opening operation is n*n, and the opening operation is iterated a set number of times; the binary image 1 is compared and judged with the binary image 2, and different pixels are retained to obtain a first difference image; A second contour module extracts edge contours from the first difference map to form a second contour map, and sets the line width of the second contour map to a first set value of pixels; A second difference module compares the first contour map with the second contour map to obtain a pixel area at an intersection position, and subtracts the pixel area at the intersection position from the first contour map to obtain a second difference map; A line drawing module, which extracts a line drawing of the edge of the clothing from the transparent channel of the clothing cutout; The generation module inputs the second difference map, the clothing edge line map and the model map into the diffusion model to obtain a generated map.
6. The device for generating a model image with optimized clothing edges according to claim 5, characterized in that: The first contour module specifically comprises: using the findContours function of OpenCV to extract the edge contour of the binary image 1 to form a first contour image, and using the OpenCV drawing interface to set the line width of the first contour image to a first set value of pixels; that is, drawing an area with a width of the first set value of pixels along the edge contour in the first contour image.
7. The device for generating a model image with optimized clothing edges according to claim 5, characterized in that: The second contour module specifically includes: using OpenCV's findContours function to extract the edge contour of the first difference map to form a second contour map, and using the OpenCV drawing interface to set the line width of the second contour map to a first set value of pixels; that is, drawing an area with a width of the first set value of pixels along the edge contour in the second contour map.
8. The device for generating a model image with optimized clothing edges according to claim 5, characterized in that: The line drawing module specifically extracts clothing edge line drawings from the transparent channel of the clothing cutout using the canny edge extraction algorithm of OpenCV.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the method according to any one of claims 1 to 4 is implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 4 is implemented.
Citation Information
Patent Citations
A data structure and associated algorithms for assessing dispersion in complex geometry
CA2512946A1
Portrait reloading method and system and medium
CN112164013A
Mobile phone glass cover plate window area defect detection method based on symmetry
CN114881915A
Article display image generation method and device, computer equipment and storage medium
CN119090737A
Image processing method and apparatus
WO2018196470A1