Search

CN-122023183-A - Method, device, equipment and medium for eliminating Kontext Lora black artifacts

CN122023183ACN 122023183 ACN122023183 ACN 122023183ACN-122023183-A

Abstract

The invention provides a method, a device, equipment and a medium for eliminating Kontext Lora black artifacts, wherein the method comprises the steps of obtaining an input image pair, wherein the input image pair comprises a to-be-processed image containing black artifacts generated by Kontext Lora and a corresponding original input image, the to-be-processed image and the original input image are both of a uint8 type image in BGR format, detecting black artifact areas in the to-be-processed image to generate artifact area masks, performing distance grading eclosion processing on artifact areas corresponding to the artifact area masks to generate an eclosion image, and performing edge constraint restoration on the eclosion image by combining edge information of the original input image to generate an image after removal of the artifacts, so that efficient elimination of the black artifacts and accurate retention of image details are realized.

Inventors

  • LIU ZHIHAI
  • YANG KENGQIANG
  • TONG ZHEN

Assignees

  • 福建紫讯信息科技有限公司

Dates

Publication Date
20260512
Application Date
20251223

Claims (10)

  1. 1. A method for eliminating Kontext Lora black artifacts is characterized by comprising the following steps: Step 1, an input image pair is obtained, wherein the input image pair comprises a to-be-processed image containing black artifacts generated by Kontext Lora and a corresponding original input image, and the to-be-processed image and the original input image are both uint8 type images in a BGR format; step 2, detecting a black artifact region in the image to be processed, and generating an artifact region mask; step 3, performing distance grading eclosion treatment on the artifact region corresponding to the artifact region mask to generate an eclosion image; and 4, carrying out edge constraint restoration on the eclosion image by combining the edge information of the original input image to generate an image after artifact removal.
  2. 2. The method for eliminating Kontext Lora black artifacts according to claim 1, wherein the step 2 is specifically: converting an image to be processed into a gray level image, adopting a Sobel operator with the size of 3 multiplied by 3 to respectively calculate the horizontal gradient and the vertical gradient of the gray level image, and obtaining a gradient amplitude image based on the horizontal gradient and the vertical gradient; normalizing the gradient amplitude map to obtain a normalized gradient amplitude map, comparing and screening candidate edge points through 8 neighborhood gradient differences to generate a candidate edge mask, wherein the 8 neighborhood offset comprises (-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0) and (1, 1), and the screening condition is that the absolute value of the gradient difference between the pixel and the neighborhood pixel is larger than a gradient threshold value; Performing Canny edge detection on the gray level graph to generate an actual content edge mask, and judging a black area according to a gray level value threshold value to generate a black area mask; Carrying out connected domain analysis on the candidate edge masks, carrying out expansion treatment on each connected domain by adopting rectangular structural elements with the size of 21 multiplied by 21 to obtain candidate edge regions, calculating the duty ratio of black pixels in the candidate edge regions, respectively extracting main directions of the candidate edge regions and the corresponding real edge regions by PCA, and calculating the included angles of the two main directions; When PCA main direction extraction is performed, and the number of pixels in the connected domain is smaller than 10, judging that the connected domain does not form an artifact region.
  3. 3. The method for eliminating Kontext Lora black artifacts according to claim 1, wherein the step 3 specifically includes performing a distance-graded eclosion process on an artifact region corresponding to an artifact region mask to generate an eclosion image, and specifically includes: inverting the mask of the artifact region to obtain an inverted mask, and performing Euclidean distance transformation on the inverted mask to obtain the distance from each pixel in the artifact region to the non-artifact region; Carrying out strong, medium and weak three-level Gaussian blur processing on an image to be processed to obtain a strong blurred image, a middle blurred image and a weak blurred image, wherein the strong blur adopts a Gaussian kernel with the size of 5 multiplied by 5 and has the standard deviation of 3, the middle blur adopts a Gaussian kernel with the size of 3 multiplied by 3 and has the standard deviation of 2, and the weak blur adopts a Gaussian kernel with the size of 3 multiplied by 3 and has the standard deviation of 1; dividing the artifact region into three sub-regions of strong, medium and weak according to the distance, respectively corresponding to the regions of which the distance is less than or equal to 5px, the distance is less than or equal to 15px and the distance is less than or equal to 30px, and respectively replacing each sub-region with an image pixel corresponding to the fuzzy intensity to obtain the image after eclosion.
  4. 4. The method for eliminating Kontext Lora black artifacts according to claim 1, wherein the step 4 is specifically: Converting an original input image into an original gray level image, and carrying out Canny edge detection on the original gray level image to generate an original image edge mask; calculating the intersection of the artifact area mask and the original image edge mask to obtain a key edge mask, and simultaneously calculating the intersection of the artifact area mask and the black area mask to obtain a final smooth area; Based on the image to be processed, the pixels of the smooth area are replaced by the corresponding pixels of the eclosion image, and the pixels of the key edge mask area are replaced by the corresponding pixels of the original input image, so that the image with the artifact removed is obtained.
  5. 5. An apparatus for eliminating Kontext Lora black artifacts, comprising: The image acquisition module is used for acquiring an input image pair, wherein the input image pair comprises a to-be-processed image containing black artifacts generated by Kontext Lora and a corresponding original input image, and the to-be-processed image and the original input image are both uint8 type images in a BGR format; The artifact region generating module is used for detecting a black artifact region in the image to be processed and generating an artifact region mask; the eclosion processing module is used for carrying out distance grading eclosion processing on the artifact region corresponding to the artifact region mask to generate an eclosion image; and the artifact removing module is used for carrying out edge constraint restoration on the eclosion image by combining the edge information of the original input image to generate an artifact-removed image.
  6. 6. The apparatus for eliminating Kontext Lora black artifacts according to claim 5, wherein the artifact-generating region module is specifically configured to: converting an image to be processed into a gray level image, adopting a Sobel operator with the size of 3 multiplied by 3 to respectively calculate the horizontal gradient and the vertical gradient of the gray level image, and obtaining a gradient amplitude image based on the horizontal gradient and the vertical gradient; normalizing the gradient amplitude map to obtain a normalized gradient amplitude map, comparing and screening candidate edge points through 8 neighborhood gradient differences to generate a candidate edge mask, wherein the 8 neighborhood offset comprises (-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0) and (1, 1), and the screening condition is that the absolute value of the gradient difference between the pixel and the neighborhood pixel is larger than a gradient threshold value; Performing Canny edge detection on the gray level graph to generate an actual content edge mask, and judging a black area according to a gray level value threshold value to generate a black area mask; Carrying out connected domain analysis on the candidate edge masks, carrying out expansion treatment on each connected domain by adopting rectangular structural elements with the size of 21 multiplied by 21 to obtain candidate edge regions, calculating the duty ratio of black pixels in the candidate edge regions, respectively extracting main directions of the candidate edge regions and the corresponding real edge regions by PCA, and calculating the included angles of the two main directions; When PCA main direction extraction is performed, and the number of pixels in the connected domain is smaller than 10, judging that the connected domain does not form an artifact region.
  7. 7. The apparatus for eliminating Kontext Lora black artifacts according to claim 5, wherein the eclosion processing module is configured to perform a distance-graded eclosion processing on an artifact region corresponding to an artifact region mask, and generate an eclosion image, and the eclosion processing module is configured to: inverting the mask of the artifact region to obtain an inverted mask, and performing Euclidean distance transformation on the inverted mask to obtain the distance from each pixel in the artifact region to the non-artifact region; Carrying out strong, medium and weak three-level Gaussian blur processing on an image to be processed to obtain a strong blurred image, a middle blurred image and a weak blurred image, wherein the strong blur adopts a Gaussian kernel with the size of 5 multiplied by 5 and has the standard deviation of 3, the middle blur adopts a Gaussian kernel with the size of 3 multiplied by 3 and has the standard deviation of 2, and the weak blur adopts a Gaussian kernel with the size of 3 multiplied by 3 and has the standard deviation of 1; dividing the artifact region into three sub-regions of strong, medium and weak according to the distance, respectively corresponding to the regions of which the distance is less than or equal to 5px, the distance is less than or equal to 15px and the distance is less than or equal to 30px, and respectively replacing each sub-region with an image pixel corresponding to the fuzzy intensity to obtain the image after eclosion.
  8. 8. The apparatus for removing Kontext Lora black artifacts according to claim 5, wherein the artifact removal module is specifically configured to: Converting an original input image into an original gray level image, and carrying out Canny edge detection on the original gray level image to generate an original image edge mask; calculating the intersection of the artifact area mask and the original image edge mask to obtain a key edge mask, and simultaneously calculating the intersection of the artifact area mask and the black area mask to obtain a final smooth area; Based on the image to be processed, the pixels of the smooth area are replaced by the corresponding pixels of the eclosion image, and the pixels of the key edge mask area are replaced by the corresponding pixels of the original input image, so that the image with the artifact removed is obtained.
  9. 9. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor implements the method of any one of claims 1 to 4 when the program is executed by the processor.
  10. 10. A computer readable storage medium, on which a computer program is stored, characterized in that the program, when being executed by a processor, implements the method according to any one of claims 1 to 4.

Description

Method, device, equipment and medium for eliminating Kontext Lora black artifacts Technical Field The present invention relates to the field of image processing technologies, and in particular, to a method, an apparatus, a device, and a medium for eliminating Kontext Lora black artifacts. Background In the field of Kontext Lora-based image generation and editing, black artifacts often appear in the generated results due to problems such as deviation of the model to the local feature map, discontinuous gradient during feature fusion, and the like. The artifacts are mostly represented as irregular black areas distributed along the edges of the effective content, and have three characteristics of 'edge adhesiveness', 'width volatility', 'detail destructiveness', namely, the overall visual continuity of the image is destroyed, texture details of the effective content are covered, edge distortion is caused by excessive blurring by a traditional artifact removal algorithm (such as fixed-radius Gaussian blurring and global threshold filtering), or omission or false detection is caused by the fact that artifacts cannot be accurately identified, and the requirements of high-precision image generation (such as picture-inserting design and commodity visual presentation) are difficult to meet. Disclosure of Invention The invention aims to solve the technical problem of providing a method, a device, equipment and a medium for eliminating Kontext Lora black artifacts, which realize the efficient elimination of the black artifacts and the accurate reservation of image details. In a first aspect, the present invention provides a method of eliminating Kontext Lora black artifacts, comprising the steps of: Step 1, an input image pair is obtained, wherein the input image pair comprises a to-be-processed image containing black artifacts generated by Kontext Lora and a corresponding original input image, and the to-be-processed image and the original input image are both uint8 type images in a BGR format; step 2, detecting a black artifact region in the image to be processed, and generating an artifact region mask; step 3, performing distance grading eclosion treatment on the artifact region corresponding to the artifact region mask to generate an eclosion image; and 4, carrying out edge constraint restoration on the eclosion image by combining the edge information of the original input image to generate an image after artifact removal. In a second aspect, the present invention provides an apparatus for eliminating Kontext Lora black artifacts, comprising: The image acquisition module is used for acquiring an input image pair, wherein the input image pair comprises a to-be-processed image containing black artifacts generated by Kontext Lora and a corresponding original input image, and the to-be-processed image and the original input image are both uint8 type images in a BGR format; The artifact region generating module is used for detecting a black artifact region in the image to be processed and generating an artifact region mask; the eclosion processing module is used for carrying out distance grading eclosion processing on the artifact region corresponding to the artifact region mask to generate an eclosion image; and the artifact removing module is used for carrying out edge constraint restoration on the eclosion image by combining the edge information of the original input image to generate an artifact-removed image. In a third aspect, the invention provides an electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the method of the first aspect when executing the program. In a fourth aspect, the present invention provides a computer readable storage medium having stored thereon a computer program which when executed by a processor implements the method of the first aspect. The one or more technical schemes provided by the invention have at least the following technical effects or advantages: 1. the artifact identification accuracy is high, namely the artifact identification accuracy can reach more than 92 percent through 'brightness gradient dip + double condition judgment', and compared with the traditional threshold method (the accuracy is about 65 percent), the artifact identification accuracy can effectively reduce missed detection (such as narrow artifacts) and false detection (such as dark texture areas). 2. The dynamic eclosion adaptability is strong, the blurring strength can be automatically adjusted according to the width of the artifacts based on the three-level eclosion mode of distance transformation, the edge distortion rate is controlled within 5% while the artifacts are eliminated, and the Kontext Lora black artifacts with different widths (1-30 px) are adapted. 3. The detail retaining effect is excellent, namely, the original image feature guidance is introduced, the edge trend of the effective content is