An image erasing result intelligent pasting method, device, equipment and medium

The image fusion method using multi-connected component detection and dynamic dilation feathering solves the problems of harsh edge transitions, weak multi-target processing capabilities, inconsistent lighting and color, and insufficient parameter adaptability in traditional image fusion methods, achieving efficient and natural image fusion results.

CN122390980APending Publication Date: 2026-07-14XIAMEN ZIXUN INFORMATION TECHNOLOGY CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
XIAMEN ZIXUN INFORMATION TECHNOLOGY CO LTD
Filing Date
2026-03-23
Publication Date
2026-07-14

AI Technical Summary

Technical Problem

Traditional image pasting methods suffer from harsh edge transitions, weak multi-target processing capabilities, inconsistent lighting and color, insufficient parameter adaptability, and poor fusion of additional interference areas, making it difficult to meet the needs of high-precision and high-fidelity image editing.

Method used

By employing steps such as multi-connected component detection, minimum rotating rectangle BBox generation, dynamic dilation feathering, and intelligent color and light fusion, and through difference detection, mask fusion, and pixel-level weighted fusion, a seamless connection between the eliminated region and the original image background is achieved.

Benefits of technology

It improves image processing efficiency and quality, increases edge transition naturalness by 50%, reduces color and brightness deviation by 70%, achieves 98% accuracy in connected component detection, increases processing speed by 3 times, and is suitable for various image scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122390980A_ABST
    Figure CN122390980A_ABST
Patent Text Reader

Abstract

The application provides an image elimination result intelligent pasting method, device, equipment and medium, and the method comprises the steps of: acquiring an original image, an object-eliminated image and an artificial correction mask image; performing double-dimension block difference detection on the original image and the eliminated image to generate a preliminary difference mask; performing pixel-level secondary detection on the preliminary difference mask after inflation to generate a final difference mask; fusing the final difference mask and the artificial correction mask image to obtain a fused difference mask; performing connected domain analysis on the fused difference mask, filtering small connected domains and fitting the minimum circumscribed rotating rectangle to generate the geometric parameters of the boundary box; generating a boundary box mask according to the geometric parameters of the boundary box, performing distance transformation and feathering curve generation on the boundary box mask after inflation to generate an alpha channel mask; and after uniform resolution, performing weighted fusion on the red, green and blue channels respectively to generate a final pasting image. The application can realize natural and seamless fusion of the elimination area and the background.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of image processing technology, and in particular to a method, apparatus, device, and medium for intelligent re-pasting of image removal results. Background Technology

[0002] Image object removal and pasting fusion is a core technology in computer vision and image processing, widely used in image restoration, content editing, privacy occlusion removal, scene reconstruction, and many other scenarios. Its core objective is to accurately remove target objects while ensuring the integrity of the removed area and the naturalness of background blending, restoring a visual effect that matches the texture of the original image. Currently, traditional image pasting fusion techniques often employ conventional methods such as direct stitching, simple feathering, and fixed parameter thresholding, which struggle to balance the structural integrity of the removed area with the visual blending of the background. This results in significant limitations in practical applications, failing to meet the high-precision, high-fidelity processing requirements of complex scenes. Specific shortcomings are as follows: 1. The edges of the re-pasted sections are abruptly transitioned, and the visual splicing is obvious. Traditional patching methods mostly use a direct, hard stitching of the removed image to the original image. Some optimization schemes only use simple feathering with a fixed width to achieve edge connection, without considering adaptive transition optimization based on image background texture and gradient changes. This processing method results in clearly distinguishable boundary outlines between the removed area and the original background, easily producing abrupt stitching marks. The visual harmony between the edges of the removed area and the surrounding background is extremely poor, resulting in a fragmented overall image texture and failing to achieve a natural blending visual effect.

[0003] 2. Weak adaptability to complex multi-target scenarios For scenarios where images contain multiple targets to be eliminated, have irregular target boundaries, or contain complex connected components, traditional patching methods lack accurate target boundary recognition and partitioning mechanisms, making it impossible to accurately locate and distinguish the boundary range of individual targets to be eliminated. During the patching process, problems such as missing patching of some target areas and over-covering of local areas, resulting in the accidental elimination of background, are prone to occur. This makes it difficult to adapt to the processing needs of multi-target and complex structure scenarios, limiting its applicability.

[0004] 3. Lack of consistency in light, shadow, and color, resulting in distorted blending effects. Traditional patching techniques fail to adequately consider the compatibility of the removal area with the original image's background in terms of color distribution, brightness levels, and light and shadow direction. The patching process simply achieves pixel-level overlay and stitching without color calibration, light and shadow balance, or tone unification. This results in significant visual conflicts between the patched area and the surrounding background in terms of tone, saturation, and brightness, unnatural light and shadow transitions, severely distorted blending effects, and an inability to reproduce the true light, shadow, color, and texture of the original image.

[0005] 4. Insufficient parameter adaptability and inconsistent processing results. In traditional patching methods, core control parameters such as feather radius, region dilation coefficient, and fusion weights are mostly preset fixed values, without dynamically and adaptively adjusting based on image scene features, the size of the target to be eliminated, and the complexity of the background texture. For differentiated scenarios such as small target elimination, high-texture complex backgrounds, and low-texture solid-color backgrounds, fixed parameters cannot adapt to scene characteristics, easily leading to problems such as excessive edge blurring, texture loss, and abrupt boundaries. The processing effect is unstable, making it difficult to achieve standardized, high-quality patching fusion.

[0006] 5. The problem of shadow residue is prominent and violates visual logic. In existing elimination and re-pasting processes, target elimination is achieved solely through the masking of the object to be eliminated. The elimination model simultaneously eliminates the corresponding projection area of ​​the object. However, the traditional re-pasting process does not perform separate removal and optimization of the shadow area, directly re-pasting the shadow of the corresponding area in the original image. This ultimately presents a visual paradox where the target object has been eliminated, but the object's shadow remains, violating realistic visual logic and severely affecting the rationality and realism of the image.

[0007] 6. Interference area fusion processing fails When there are additionally labeled interference regions masking the image, traditional patching methods cannot achieve efficient collaborative fusion of the interference region mask and the detected eliminated region, lacking a region integration and fine-grained processing mechanism. In actual processing, problems such as residual interference regions, abrupt transitions between interference and eliminated regions, and accidental removal of valid background are prone to occur, further reducing the accuracy of patching fusion and the integrity of the image.

[0008] In summary, traditional image object removal and fusion methods suffer from multiple shortcomings, including issues with edge transition, scene adaptation, lighting and color, parameter control, shadow processing, and interference area fusion. These shortcomings make it difficult to meet the current demands for high-precision, high-realism, and highly scene-adaptable image editing and processing. There is an urgent need to develop better technical solutions to overcome these technical challenges. Summary of the Invention

[0009] The technical problem to be solved by this invention is to provide an intelligent method, device, equipment, and medium for re-attaching image removal results. Through core steps such as multi-connected component detection, minimum rotating rectangle BBox generation, dynamic dilation feathering, and intelligent fusion of color and light, it achieves seamless connection between the removed area and the original image background. Ultimately, it meets the needs of scenarios with high requirements for the naturalness of re-attachment and fusion, such as image editing, film and television post-production, e-commerce product image optimization, and AI model training data preprocessing, thereby improving image processing efficiency and quality.

[0010] In a first aspect, the present invention provides an intelligent re-pasting method for image removal results, characterized by comprising the following steps: Step S1: Obtain the original image, the image after object removal, and the manually corrected mask image; wherein, the manually corrected mask image is a binary image used to identify the correction area specified by the user; Step S2: Perform two-dimensional block difference detection on the original image and the image after object removal to generate a preliminary difference mask; Step S3: Dilate the preliminary difference mask, set a first dilation radius, and generate a dilated detection region; within the dilated detection region, calculate the absolute difference of pixel values ​​at corresponding positions between the original image and the image after object removal; when the absolute difference is greater than a preset fine detection threshold, mark the pixel as a difference pixel; merge the marked difference pixels with the preliminary difference mask by performing a logical OR operation to generate the final difference mask. Step S4: Perform a logical OR operation on the final difference mask and the manually corrected mask image to fuse them and obtain the fused difference mask; Step S5: Perform connected component analysis on the fused difference mask, extract multiple connected components and filter out small connected components with an area smaller than a preset threshold, fit the minimum bounding rotation rectangle for each effective connected component, and obtain the bounding box geometric parameters of each connected component. Step S6: Generate a corresponding bounding box mask based on the bounding box geometric parameters of each connected component. The bounding box mask is a binary image, where the pixel value inside the bounding box is 255 and the pixel value outside the bounding box is 0. Merge the bounding box masks of all connected components by performing a logical OR operation to generate a merged bounding box mask. Dilate the merged bounding box mask and set a second dilation radius to generate a dilated region mask. Define the interior of the merged bounding box mask as the core region and set the weight value of the core region to 1.0. Define the difference region between the dilated region mask and the merged bounding box mask as the feathered region. Perform a distance transformation on the feathered region, calculate the shortest Euclidean distance from each pixel in the region to the edge of the core region, and normalize the shortest Euclidean distance to obtain a normalized distance value. Input the normalized distance value into a preset feathering curve function and map it to a weight value to generate an α-channel mask. The gray value of each pixel in the α-channel mask is the fusion weight of that pixel, with a value range of [0,1]. Step S7: Unify the resolution of the original image, the image after object removal, and the α channel mask, and perform pixel-level weighted fusion on each color channel according to the following formula: R_blended=R_cleaned×α(x,y)+R_orig×(1-α(x,y)) G_blended=G_cleaned×α(x,y)+G_orig×(1-α(x,y)) B_blended=B_cleaned×α(x,y)+B_orig×(1-α(x,y)) Wherein, R_blended, G_blended, and B_blended are the pixel values ​​of the fused pixel in the red, green, and blue channels, respectively; R_cleaned, G_cleaned, and B_cleaned are the pixel values ​​of the image after object removal in the red, green, and blue channels at coordinates (x, y), respectively; R_orig, G_orig, and B_orig are the pixel values ​​of the original image in the red, green, and blue channels at coordinates (x, y), respectively; α(x, y) is the grayscale value of the α channel mask generated in step S6 at coordinates (x, y), and its value range is [0, 1]. The merged red, green, and blue channel pixel values ​​are cropped to the range of [0, 255] and merged into an RGB format color image to generate the final repost image.

[0011] Furthermore, the two-dimensional block difference detection in step S2 specifically involves: Set the first block size and step size parameters to divide the original image and the image after object removal into corresponding image blocks; For each pair of image patches, calculate the cosine similarity of their color vectors to obtain the cosine difference value; calculate the magnitude ratio of their color vectors to obtain the brightness difference value. When the cosine difference value is greater than or equal to a preset first cosine threshold, or the modulus ratio is less than or equal to a preset first modulus threshold, all pixels in the image block are marked as difference pixels, and a preliminary difference mask is generated. The fine detection threshold ranges from 10 to 30, and the absolute difference of pixel values ​​is the sum of the absolute differences of the red, green, and blue channels.

[0012] Furthermore, in step S5, fitting the minimum bounding rectangle for each effective connected component specifically involves: The fused difference mask is labeled with connected components, and the area of ​​each connected component is calculated. Filter connected components whose area is smaller than a preset area threshold, and retain valid connected components; For each valid connected component, extract its outer contour, calculate the circumscribed rotating rectangle with the smallest area surrounding the contour, and obtain the center point coordinates, width, height and rotation angle of the rotating rectangle as the bounding box geometric parameters. The preset area threshold is 100 pixels.

[0013] Furthermore, the first expansion radius ranges from 40 to 60 pixels, and the second expansion radius ranges from 15 to 25 pixels.

[0014] Furthermore, the feathering curve function is selected from one of the following: a linear function, a cosine function, a sigmoid function, or an exponential function; The expression for the cosine function is: f(x) = 0.5 × (1 - cos(π × x)), where x is the normalized distance value, and its value range is [0, 1].

[0015] Furthermore, step S6 also includes an exception handling mechanism: when the scientific computing library required for distance transformation is unavailable, a Gaussian blur algorithm is used to blur the dilated region mask to generate an alternative α-channel mask.

[0016] Furthermore, in step S7, when unifying the resolution, the image after object removal is adjusted using a bilinear interpolation algorithm, and the α channel mask is adjusted using a nearest neighbor interpolation algorithm.

[0017] Secondly, the present invention provides an intelligent re-attachment device for image removal results, comprising: The image acquisition module acquires the original image, the image after object removal, and the manually corrected mask image; wherein, the manually corrected mask image is a binary image used to identify the correction area specified by the user; The difference detection module performs two-dimensional block difference detection on the original image and the image after object removal to generate a preliminary difference mask; The secondary detection module performs dilation processing on the preliminary difference mask, sets a first dilation radius, and generates a dilated detection region. Within the dilated detection region, it calculates the absolute difference of pixel values ​​at corresponding positions between the original image and the image after object removal. When the absolute difference is greater than a preset fine detection threshold, the pixel is marked as a difference pixel. The marked difference pixels are combined with the preliminary difference mask by performing a logical OR operation to generate the final difference mask. The mask fusion module performs a logical OR operation to fuse the final difference mask with the manually corrected mask image to obtain the fused difference mask. The connected component analysis module performs connected component analysis on the fused difference mask, extracts multiple connected components and filters out tiny connected components with an area smaller than a preset threshold, fits the minimum bounding rotation rectangle for each effective connected component, and obtains the bounding box geometric parameters of each connected component. The feathering mask generation module generates a corresponding bounding box mask based on the bounding box geometric parameters of each connected component. The bounding box mask is a binary image, where the pixel value inside the bounding box is 255 and the pixel value outside the bounding box is 0. It then performs a logical OR operation on the bounding box masks of all connected components to merge them, generating a merged bounding box mask. The merged bounding box mask is then dilated, with a second dilation radius set to generate a dilated region mask. The interior of the merged bounding box mask is defined as the core region, and its weight is set to 1.0. The difference between the dilated region mask and the merged bounding box mask is defined as the feathered region. A distance transformation is performed on the feathered region, calculating the shortest Euclidean distance from each pixel within the region to the edge of the core region. This shortest Euclidean distance is then normalized to obtain a normalized distance value. The normalized distance value is input into a preset feathering curve function, mapped to a weight value, and an α-channel mask is generated. The grayscale value of each pixel in the α-channel mask is the fusion weight of that pixel, with a value range of [0,1]. The image fusion module unifies the resolution of the original image, the image after object removal, and the alpha channel mask, and performs pixel-level weighted fusion on each color channel according to the following formula: R_blended=R_cleaned×α(x,y)+R_orig×(1-α(x,y)) G_blended=G_cleaned×α(x,y)+G_orig×(1-α(x,y)) B_blended=B_cleaned×α(x,y)+B_orig×(1-α(x,y)) Wherein, R_blended, G_blended, and B_blended are the pixel values ​​of the fused pixel in the red, green, and blue channels, respectively; R_cleaned, G_cleaned, and B_cleaned are the pixel values ​​of the image after object removal in the red, green, and blue channels at coordinates (x, y), respectively; R_orig, G_orig, and B_orig are the pixel values ​​of the original image in the red, green, and blue channels at coordinates (x, y), respectively; α(x, y) is the grayscale value of the α channel mask generated in step S6 at coordinates (x, y), and its value range is [0, 1]. The merged red, green, and blue channel pixel values ​​are cropped to the range of [0, 255] and merged into an RGB format color image to generate the final repost image.

[0018] Thirdly, the present invention provides an electronic device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the method described in the first aspect.

[0019] Fourthly, the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method described in the first aspect.

[0020] One or more technical solutions provided by this invention have at least the following technical effects or advantages: 1. When using cosine curve feathering, the transition area of ​​the back-attached edge has no obvious splicing marks. The subjective evaluation of "naturalness of blending" by the human eye reaches 4.8 / 5 points, which is 50% higher than the traditional simple feathering method (3.2 / 5 points).

[0021] 2. The color deviation of the fused image is ≤3% and the brightness deviation is ≤5%, which is more than 70% higher than the traditional method (color deviation ≤10% and brightness deviation ≤15%), ensuring that the eliminated area and the background are visually seamless.

[0022] 3. The present invention has a connected component detection accuracy of ≥98%, a minimum rotation rectangle fitting error of ≤2 pixels, and can accurately identify and process 10+ simultaneous independent target regions without any missed or false detections.

[0023] 4. The entire process of processing a single 1024×1024 pixel image takes ≤5 seconds, which is 3 times more efficient than the traditional multi-step processing method (average 15 seconds / image); when processing 1000 images in batches, the total processing time is ≤1.5 hours, meeting the needs of large-scale processing.

[0024] 5. This invention supports dynamic adjustment of parameters such as expansion radius (5-50 pixels), feathering curve type, and difference detection threshold according to target size and scene complexity, adapting to 20+ types of image scenes (natural landscapes, indoor scenes, product images, etc.).

[0025] 6. This invention supports common image formats such as JPG, PNG, and BMP, and is compatible with multiple operating systems including Windows, Linux, and MacOS. When dependent libraries (such as OpenCV and SciPy) are missing, a fallback scheme is automatically activated, and the functionality availability rate is ≥99%.

[0026] The above description is merely an overview of the technical solution of the present invention. In order to better understand the technical means of the present invention and to implement it in accordance with the contents of the specification, and in order to make the above and other objects, features and advantages of the present invention more apparent and understandable, specific embodiments of the present invention are described below. Attached Figure Description

[0027] The present invention will be further described below with reference to the accompanying drawings and embodiments.

[0028] Figure 1 This is a flowchart of the method in Embodiment 1 of the present invention; Figure 2 This is a schematic diagram of the device in Embodiment 2 of the present invention. Detailed Implementation

[0029] This application provides an intelligent re-paste method, apparatus, device, and medium for image removal results, which solves the defects of traditional re-paste methods such as "awkward edge transitions, weak multi-target processing capabilities, inconsistent light and shadow colors, insufficient parameter adaptability, and poor fusion of additional interference areas".

[0030] The overall concept of the technical solution in this application is as follows: The intelligent image removal result pasting method proposed in this invention is based on a five-order framework of "difference detection - connected component analysis - BBox generation - dilation feathering - intelligent fusion", and is implemented through the following key modules: Image difference detection and mask fusion module Input data preparation: Obtain the original image (denoted as Img_orig), the image after object removal (denoted as Img_cleaned), and the mask image of the extra interference area (denoted as Img_extra_mask). Ensure that the resolution of the three images is initially consistent or can be unified through subsequent processing.

[0031] Two-dimensional difference detection: The `block_cos_diff_mask_with_norm` function is called, employing a two-dimensional detection mechanism of "cosine difference + modulus ratio" to compare `Img_orig` and `Img_cleaned` in blocks. The `block_size` (default 16) and `stride` (default 16) parameters are set, and the color direction difference (cosine similarity) and brightness difference (modulus ratio) of each image block are calculated. Regions with a cosine difference ≥ a set threshold (default 0.01) or a modulus ratio ≤ a set threshold (default 0.7) are marked as difference regions.

[0032] Secondary fine detection: The difference regions obtained in the initial detection are dilated (by default 48 pixels). A smaller block size (by default 3) is used in the dilated regions for secondary detection to further accurately locate the difference regions, avoid missing subtle differences, and generate an initial difference mask (denoted as Mask_stage1).

[0033] Multi-mask fusion: The initial difference mask and the extra interference region mask image Img_extra_mask are logically ORed to obtain the final difference mask (denoted as Mask_fused), ensuring that the extra interference region is included in the re-pasting process.

[0034] Multi-connected BBox generation module Connected component extraction: Perform connected component analysis on Mask_fused, filter out tiny connected components with an area smaller than a set threshold (default 100 pixels), and retain the valid target region.

[0035] Minimum Rotation Rectangle Fitting: For each valid connected component, the minimum bounding rectangle is calculated using the connected component labeling algorithm of OpenCV or SciPy, generating an accurate bounding box for each connected component. This ensures that the bounding box closely fits the outline of the target region, avoiding the inclusion of unnecessary background in the processing range.

[0036] BBox Merging and Storage: Merge all connected component BBoxes to generate a unified BBox mask (denoted as Mask_bbox_combined); at the same time, save the BBox mask of each individual connected component to a specified directory, supporting subsequent individual or batch processing.

[0037] Dynamic expansion feathering mask generation module BBox inflation processing: Based on the merged Mask_bbox_combined, according to the set inflation radius (default 20 pixels, can be dynamically adjusted), the binary inflation algorithm is used to expand the BBox outward, generating an expanded area after inflation, providing space for feathering transition.

[0038] Core and Feather Region Division: The interior of the original BBox is defined as the core region (α value = min_core_alpha, default 1.0, using all pixels of the elimination map), and the difference region between the dilated region and the original BBox is defined as the feather region (α value smoothly transitions from 1.0 to 0).

[0039] Multi-curve feathering calculation: Supports four feathering curves: linear, cosine, sigmoid, and exponential, which can be selected according to scene requirements (the default is the cosine curve, which provides a smoother transition). The distance from each pixel in the feathered area to the edge of the original bounding box is calculated using a distance transformation algorithm. After normalization, the distance is combined with the selected feathering curve to generate a precise alpha channel mask (denoted as Mask_alpha).

[0040] Anomaly handling mechanism: When the SciPy library is unavailable, it automatically reverts to the Gaussian blur algorithm to generate a feathered mask, ensuring functional stability; at the same time, it ensures that the α value outside the dilated region is 0 to avoid affecting irrelevant backgrounds.

[0041] Intelligent image fusion module Image preprocessing: Unify the resolution of Img_orig, Img_cleaned and all masks, adjust the size of the cleaned-up image using bilinear interpolation, and adjust the size of the mask using nearest neighbor interpolation to ensure pixel-level alignment.

[0042] Pixel-level fusion calculation: The generated Mask_alpha is expanded into four channels (RGB+Alpha) and then fused with Img_cleaned and Img_orig at the pixel level. The fusion formula is as follows: Blended_pixel=Img_cleaned_pixel×Alpha+Img_orig_pixel×(1-Alpha) where Blended_pixel is the fused pixel value and Alpha is the feathering weight of the corresponding pixel, with a value range of [0,1].

[0043] Results Optimization and Storage: The merged pixel values ​​are cropped to the range [0, 255] and converted to uint8 format, then saved as the final merged image in RGBA format. It also supports saving debug files such as the α channel mask and the dilated BBox mask for subsequent parameter optimization.

[0044] (II) Algorithm Flow 1. Input the original image Img_orig, the cleaned image Img_cleaned, and the extra interference mask Img_extra_mask; 2. Perform two-dimensional block difference detection on Img_orig and Img_cleaned to generate a preliminary difference maskMask_stage1; 3. Expand Mask_stage1 and perform a second fine-tuning detection to obtain the final difference mask Mask_final; 4. Combine Mask_final and Img_extra_mask to generate Mask_fused; 5. Perform connected component analysis on Mask_fused, filter out small regions, and fit the minimum rotated rectangle BBox for each connected component; 6. Merge all BBoxes to generate Mask_bbox_combined, and save the individual BBox mask; 7. Based on Mask_bbox_combined, set the expansion radius and feathering curve to generate a dynamically feathered α mask; 8. Unify the resolution of all images and masks, perform pixel-level weighted fusion, and generate the final reply image; 9. Save the final results and debug files (optional). The process ends.

[0045] (III) Terminology Explanation Multi-connected region: A collection of multiple unconnected target regions in an image. Each region is an independent connected region and requires separate bounding box fitting.

[0046] Minimum bounding rectangle of rotation: The smallest rectangle of rotation that can completely enclose the connected region. Compared to axis-aligned rectangles, it can fit the target area with a more closely.

[0047] Dilation and feathering: This method first expands the bounding box (increases it), and then performs a smooth transition of weights (feathering) within the expanded area to achieve a natural connection between the region and the background.

[0048] Alpha channel mask: A single-channel image used to control the image fusion weights. The pixel value ranges from [0,1]. The closer the value is to 1, the more preferentially the pixels of the eliminated image are used. The closer the value is to 0, the more preferentially the pixels of the original image are used.

[0049] Cosine similarity: This measures the degree of difference in color direction by calculating the cosine similarity of the color vectors of two image patches. The larger the value, the more obvious the color difference.

[0050] Modulus ratio: The ratio of the modulus (brightness) of the color vectors of two image blocks is used to measure the degree of brightness difference. The closer the value is to 0, the more obvious the brightness difference.

[0051] Application scenarios 1. E-commerce product image optimization: After taking product images for e-commerce platforms, redundant objects in the background (such as shooting props and clutter) need to be removed. This method can seamlessly integrate the product image after removal with the clean background, ensuring that the main body of the product is clear and the background is natural, thus improving the product display effect.

[0052] 2. Film and television post-production: When it is necessary to remove outliers (such as microphones or crew members) in film and television clips, this method can achieve precise integration of the removed area with the original scene, avoiding a "patchwork" look and reducing post-production costs.

[0053] 3. AI Model Training Data Preprocessing: When constructing training datasets for AI models of image object removal and image restoration, this method can generate high-quality "original image-removed fused image" data pairs to ensure data quality and improve model training results.

[0054] 4. Social Media Content Creation: When users share photos on social media platforms, they need to remove irrelevant people, watermarks, and other elements from the photos. After the platform integrates this method, it can automatically generate naturally blended removal results, improving the user's creative experience.

[0055] 5. Industrial Image Inspection: In industrial visual inspection, it is necessary to remove interfering objects (such as dust and occlusions) in the image to highlight the detection target. This method can maintain the visual consistency between the background and the target area after eliminating interference, thereby improving the accuracy of the detection algorithm. Example

[0056] like Figure 1As shown, this embodiment provides a method for intelligent re-pasting of image removal results, including the following steps: Step S1: Obtain the original image, the image after object removal, and the manually corrected mask image; wherein, the manually corrected mask image is a binary image used to identify the correction area specified by the user; Step S2: Perform two-dimensional block difference detection on the original image and the image after object removal to generate a preliminary difference mask; Step S3: Dilate the preliminary difference mask, set a first dilation radius, and generate a dilated detection region; within the dilated detection region, calculate the absolute difference of pixel values ​​at corresponding positions between the original image and the image after object removal; when the absolute difference is greater than a preset fine detection threshold, mark the pixel as a difference pixel; merge the marked difference pixels with the preliminary difference mask by performing a logical OR operation to generate the final difference mask. Step S4: Perform a logical OR operation on the final difference mask and the manually corrected mask image to fuse them and obtain the fused difference mask; Step S5: Perform connected component analysis on the fused difference mask, extract multiple connected components and filter out small connected components with an area smaller than a preset threshold, fit the minimum bounding rotation rectangle for each effective connected component, and obtain the bounding box geometric parameters of each connected component. Step S6: Generate a corresponding bounding box mask based on the bounding box geometric parameters of each connected component. The bounding box mask is a binary image, where the pixel value inside the bounding box is 255 and the pixel value outside the bounding box is 0. Merge the bounding box masks of all connected components by performing a logical OR operation to generate a merged bounding box mask. Dilate the merged bounding box mask and set a second dilation radius to generate a dilated region mask. Define the interior of the merged bounding box mask as the core region and set the weight value of the core region to 1.0. Define the difference region between the dilated region mask and the merged bounding box mask as the feathered region. Perform a distance transformation on the feathered region, calculate the shortest Euclidean distance from each pixel in the region to the edge of the core region, and normalize the shortest Euclidean distance to obtain a normalized distance value. Input the normalized distance value into a preset feathering curve function and map it to a weight value to generate an α-channel mask. The gray value of each pixel in the α-channel mask is the fusion weight of that pixel, with a value range of [0,1]. Step S7: Unify the resolution of the original image, the image after object removal, and the α channel mask, and perform pixel-level weighted fusion on each color channel according to the following formula: R_blended=R_cleaned×α(x,y)+R_orig×(1-α(x,y)) G_blended=G_cleaned×α(x,y)+G_orig×(1-α(x,y)) B_blended=B_cleaned×α(x,y)+B_orig×(1-α(x,y)) Wherein, R_blended, G_blended, and B_blended are the pixel values ​​of the fused pixel in the red, green, and blue channels, respectively; R_cleaned, G_cleaned, and B_cleaned are the pixel values ​​of the image after object removal in the red, green, and blue channels at coordinates (x, y), respectively; R_orig, G_orig, and B_orig are the pixel values ​​of the original image in the red, green, and blue channels at coordinates (x, y), respectively; α(x, y) is the grayscale value of the α channel mask generated in step S6 at coordinates (x, y), and its value range is [0, 1]. The merged red, green, and blue channel pixel values ​​are cropped to the range of [0, 255] and merged into an RGB format color image to generate the final repost image.

[0057] In this embodiment, preferably, the two-dimensional block difference detection in step S2 specifically involves: Set the first block size and step size parameters to divide the original image and the image after object removal into corresponding image blocks; For each pair of image patches, calculate the cosine similarity of their color vectors to obtain the cosine difference value; calculate the magnitude ratio of their color vectors to obtain the brightness difference value. When the cosine difference value is greater than or equal to a preset first cosine threshold, or the modulus ratio is less than or equal to a preset first modulus threshold, all pixels in the image block are marked as difference pixels, and a preliminary difference mask is generated. The fine detection threshold ranges from 10 to 30, and the absolute difference of pixel values ​​is the sum of the absolute differences of the red, green, and blue channels.

[0058] In this embodiment, preferably, fitting the minimum bounding rectangle for each effective connected component in step S5 specifically involves: The fused difference mask is labeled with connected components, and the area of ​​each connected component is calculated. Filter connected components whose area is smaller than a preset area threshold, and retain valid connected components; For each valid connected component, extract its outer contour, calculate the circumscribed rotating rectangle with the smallest area surrounding the contour, and obtain the center point coordinates, width, height and rotation angle of the rotating rectangle as the bounding box geometric parameters. The preset area threshold is 100 pixels.

[0059] In this embodiment, preferably, the value range of the first expansion radius is 40 to 60 pixels, and the value range of the second expansion radius is 15 to 25 pixels.

[0060] In this embodiment, preferably, the feathering curve function is selected from one of a linear function, a cosine function, a sigmoid function, or an exponential function; The expression for the cosine function is: f(x) = 0.5 × (1 - cos(π × x)), where x is the normalized distance value, and its value range is [0, 1].

[0061] In this embodiment, preferably, step S6 further includes an exception handling mechanism: when the scientific computing library required for distance transformation is unavailable, a Gaussian blur algorithm is used to blur the dilated region mask to generate an alternative α-channel mask.

[0062] In this embodiment, preferably, when unifying the resolution in step S7, the image after object removal is adjusted using a bilinear interpolation algorithm, and the α channel mask is adjusted using a nearest neighbor interpolation algorithm.

[0063] Based on the same inventive concept, this application also provides an apparatus corresponding to the method in Embodiment 1, as detailed in Embodiment 2.

[0064] Example 2 like Figure 2 As shown, this embodiment provides an intelligent image removal result re-pasting device, including: The image acquisition module acquires the original image, the image after object removal, and the manually corrected mask image; wherein, the manually corrected mask image is a binary image used to identify the correction area specified by the user; The difference detection module performs two-dimensional block difference detection on the original image and the image after object removal to generate a preliminary difference mask; The secondary detection module performs dilation processing on the preliminary difference mask, sets a first dilation radius, and generates a dilated detection region. Within the dilated detection region, it calculates the absolute difference of pixel values ​​at corresponding positions between the original image and the image after object removal. When the absolute difference is greater than a preset fine detection threshold, the pixel is marked as a difference pixel. The marked difference pixels are combined with the preliminary difference mask by performing a logical OR operation to generate the final difference mask. The mask fusion module performs a logical OR operation to fuse the final difference mask with the manually corrected mask image to obtain the fused difference mask. The connected component analysis module performs connected component analysis on the fused difference mask, extracts multiple connected components and filters out tiny connected components with an area smaller than a preset threshold, fits the minimum bounding rotation rectangle for each effective connected component, and obtains the bounding box geometric parameters of each connected component. The feathering mask generation module generates a corresponding bounding box mask based on the bounding box geometric parameters of each connected component. The bounding box mask is a binary image, where the pixel value inside the bounding box is 255 and the pixel value outside the bounding box is 0. It then performs a logical OR operation on the bounding box masks of all connected components to merge them, generating a merged bounding box mask. The merged bounding box mask is then dilated, with a second dilation radius set to generate a dilated region mask. The interior of the merged bounding box mask is defined as the core region, and its weight is set to 1.0. The difference between the dilated region mask and the merged bounding box mask is defined as the feathered region. A distance transformation is performed on the feathered region, calculating the shortest Euclidean distance from each pixel within the region to the edge of the core region. This shortest Euclidean distance is then normalized to obtain a normalized distance value. The normalized distance value is input into a preset feathering curve function, mapped to a weight value, and an α-channel mask is generated. The grayscale value of each pixel in the α-channel mask is the fusion weight of that pixel, with a value range of [0,1]. The image fusion module unifies the resolution of the original image, the image after object removal, and the alpha channel mask, and performs pixel-level weighted fusion on each color channel according to the following formula: R_blended=R_cleaned×α(x,y)+R_orig×(1-α(x,y)) G_blended=G_cleaned×α(x,y)+G_orig×(1-α(x,y)) B_blended=B_cleaned×α(x,y)+B_orig×(1-α(x,y)) Wherein, R_blended, G_blended, and B_blended are the pixel values ​​of the fused pixel in the red, green, and blue channels, respectively; R_cleaned, G_cleaned, and B_cleaned are the pixel values ​​of the image after object removal in the red, green, and blue channels at coordinates (x, y), respectively; R_orig, G_orig, and B_orig are the pixel values ​​of the original image in the red, green, and blue channels at coordinates (x, y), respectively; α(x, y) is the grayscale value of the α channel mask generated in step S6 at coordinates (x, y), and its value range is [0, 1]. The merged red, green, and blue channel pixel values ​​are cropped to the range of [0, 255] and merged into an RGB format color image to generate the final repost image.

[0065] In this embodiment, preferably, the two-dimensional block difference detection in the difference detection module specifically includes: Set the first block size and step size parameters to divide the original image and the image after object removal into corresponding image blocks; For each pair of image patches, calculate the cosine similarity of their color vectors to obtain the cosine difference value; calculate the magnitude ratio of their color vectors to obtain the brightness difference value. When the cosine difference value is greater than or equal to a preset first cosine threshold, or the modulus ratio is less than or equal to a preset first modulus threshold, all pixels in the image block are marked as difference pixels, and a preliminary difference mask is generated. The fine detection threshold ranges from 10 to 30, and the absolute difference of pixel values ​​is the sum of the absolute differences of the red, green, and blue channels.

[0066] In this embodiment, preferably, the minimum bounding rectangle fitted to each valid connected component in the connected component analysis module is specifically as follows: The fused difference mask is labeled with connected components, and the area of ​​each connected component is calculated. Filter connected components whose area is smaller than a preset area threshold, and retain valid connected components; For each valid connected component, extract its outer contour, calculate the circumscribed rotating rectangle with the smallest area surrounding the contour, and obtain the center point coordinates, width, height and rotation angle of the rotating rectangle as the bounding box geometric parameters. The preset area threshold is 100 pixels.

[0067] In this embodiment, preferably, the value range of the first expansion radius is 40 to 60 pixels, and the value range of the second expansion radius is 15 to 25 pixels.

[0068] In this embodiment, preferably, the feathering curve function is selected from one of a linear function, a cosine function, a sigmoid function, or an exponential function; The expression for the cosine function is: f(x) = 0.5 × (1 - cos(π × x)), where x is the normalized distance value, and its value range is [0, 1].

[0069] In this embodiment, preferably, the feathering mask generation module further includes an exception handling mechanism: when the scientific computing library required for distance transformation is unavailable, a Gaussian blur algorithm is used to blur the dilated region mask to generate an alternative α-channel mask.

[0070] In this embodiment, preferably, when unifying the resolution in the image fusion module, the image after object removal is adjusted using a bilinear interpolation algorithm, and the α-channel mask is adjusted using a nearest neighbor interpolation algorithm.

[0071] Since the apparatus described in Embodiment 2 of the present invention is an apparatus used to implement the method of Embodiment 1 of the present invention, those skilled in the art can understand the specific structure and variations of the apparatus based on the method described in Embodiment 1 of the present invention, and therefore will not be described again here. All apparatuses used in the method of Embodiment 1 of the present invention fall within the scope of protection of the present invention.

[0072] Based on the same inventive concept, this application provides an electronic device embodiment corresponding to Embodiment 1, as detailed in Embodiment 3.

[0073] Example 3 This embodiment provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it can implement any of the implementation methods in Embodiment 1.

[0074] Since the electronic device described in this embodiment is the device used to implement the method in Embodiment 1 of this application, those skilled in the art can understand the specific implementation method and various variations of the electronic device in this embodiment based on the method described in Embodiment 1 of this application. Therefore, how the electronic device implements the method in the embodiment of this application will not be described in detail here. Any device used by those skilled in the art to implement the method in the embodiment of this application falls within the scope of protection of this application.

[0075] Based on the same inventive concept, this application provides a storage medium corresponding to Embodiment 1, as detailed in Embodiment 4.

[0076] Example 4 This embodiment provides a computer-readable storage medium storing a computer program thereon. When the computer program is executed by a processor, it can implement any of the implementation methods in Embodiment 1.

[0077] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied 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.

[0078] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0079] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0080] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0081] While specific embodiments of the present invention have been described above, those skilled in the art should understand that the specific embodiments described are merely illustrative and not intended 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 within the scope of protection of the claims of the present invention.

Claims

1. A method for intelligent re-pasting of image removal results, characterized in that, Includes the following steps: Step S1: Obtain the original image, the image after object removal, and the manually corrected mask image; wherein, the manually corrected mask image is a binary image used to identify the correction area specified by the user; Step S2: Perform two-dimensional block difference detection on the original image and the image after object removal to generate a preliminary difference mask; Step S3: Dilate the preliminary difference mask, set a first dilation radius, and generate a dilated detection region; within the dilated detection region, calculate the absolute difference of pixel values ​​at corresponding positions between the original image and the image after object removal; when the absolute difference is greater than a preset fine detection threshold, mark the pixel as a difference pixel; merge the marked difference pixels with the preliminary difference mask by performing a logical OR operation to generate the final difference mask. Step S4: Perform a logical OR operation on the final difference mask and the manually corrected mask image to fuse them and obtain the fused difference mask; Step S5: Perform connected component analysis on the fused difference mask, extract multiple connected components and filter out small connected components with an area smaller than a preset threshold, fit the minimum bounding rotation rectangle for each effective connected component, and obtain the bounding box geometric parameters of each connected component. Step S6: Generate a corresponding bounding box mask based on the bounding box geometric parameters of each connected component. The bounding box mask is a binary image, where the pixel value inside the bounding box is 255 and the pixel value outside the bounding box is 0. Merge the bounding box masks of all connected components by performing a logical OR operation to generate a merged bounding box mask. Dilate the merged bounding box mask and set a second dilation radius to generate a dilated region mask. Define the interior of the merged bounding box mask as the core region and set the weight value of the core region to 1.

0. Define the difference region between the dilated region mask and the merged bounding box mask as the feathered region. Perform a distance transformation on the feathered region, calculate the shortest Euclidean distance from each pixel in the region to the edge of the core region, and normalize the shortest Euclidean distance to obtain a normalized distance value. Input the normalized distance value into a preset feathering curve function and map it to a weight value to generate an α-channel mask. The gray value of each pixel in the α-channel mask is the fusion weight of that pixel, with a value range of [0,1]. Step S7: Unify the resolution of the original image, the image after object removal, and the α channel mask, and perform pixel-level weighted fusion on each color channel according to the following formula: R_blended=R_cleaned×α(x,y)+R_orig×(1-α(x,y)) G_blended=G_cleaned×α(x,y)+G_orig×(1-α(x,y)) B_blended=B_cleaned×α(x,y)+B_orig×(1-α(x,y)) Wherein, R_blended, G_blended, and B_blended are the pixel values ​​of the fused pixel in the red, green, and blue channels, respectively; R_cleaned, G_cleaned, and B_cleaned are the pixel values ​​of the image after object removal in the red, green, and blue channels at coordinates (x, y), respectively; R_orig, G_orig, and B_orig are the pixel values ​​of the original image in the red, green, and blue channels at coordinates (x, y), respectively; α(x, y) is the grayscale value of the α channel mask generated in step S6 at coordinates (x, y), and its value range is [0, 1]. The merged red, green, and blue channel pixel values ​​are cropped to the range of [0, 255] and merged into an RGB format color image to generate the final repost image.

2. The method according to claim 1, characterized in that, The two-dimensional block difference detection in step S2 specifically involves: Set the first block size and step size parameters to divide the original image and the image after object removal into corresponding image blocks; For each pair of image patches, calculate the cosine similarity of their color vectors to obtain the cosine difference value; calculate the magnitude ratio of their color vectors to obtain the brightness difference value. When the cosine difference value is greater than or equal to a preset first cosine threshold, or the modulus ratio is less than or equal to a preset first modulus threshold, all pixels in the image block are marked as difference pixels, and a preliminary difference mask is generated. The fine detection threshold ranges from 10 to 30, and the absolute difference of pixel values ​​is the sum of the absolute differences of the red, green, and blue channels.

3. The method according to claim 1, characterized in that, In step S5, fitting the minimum bounding rotation rectangle for each effective connected component specifically involves: The fused difference mask is labeled with connected components, and the area of ​​each connected component is calculated. Filter connected components whose area is smaller than a preset area threshold, and retain valid connected components; For each valid connected component, extract its outer contour, calculate the circumscribed rotating rectangle with the smallest area surrounding the contour, and obtain the center point coordinates, width, height and rotation angle of the rotating rectangle as the bounding box geometric parameters. The preset area threshold is 100 pixels.

4. The method according to claim 1, characterized in that, The first expansion radius ranges from 40 to 60 pixels, and the second expansion radius ranges from 15 to 25 pixels.

5. The method according to claim 1, characterized in that, The feathering curve function is selected from one of the following: linear function, cosine function, sigmoid function, or exponential function. The expression for the cosine function is: f(x) = 0.5 × (1 - cos(π × x)), where x is the normalized distance value, and its value range is [0, 1].

6. The method according to claim 1, characterized in that, Step S6 also includes an exception handling mechanism: when the scientific computing library required for distance transformation is unavailable, a Gaussian blur algorithm is used to blur the dilated region mask to generate an alternative α-channel mask.

7. The method according to claim 1, characterized in that, In step S7, when unifying the resolution, the image after object removal is adjusted using a bilinear interpolation algorithm, and the α channel mask is adjusted using a nearest neighbor interpolation algorithm.

8. An intelligent re-attachment device for image removal results, characterized in that, include: The image acquisition module acquires the original image, the image after object removal, and the manually corrected mask image; wherein, the manually corrected mask image is a binary image used to identify the correction area specified by the user; The difference detection module performs two-dimensional block difference detection on the original image and the image after object removal to generate a preliminary difference mask; The secondary detection module performs dilation processing on the preliminary difference mask, sets a first dilation radius, and generates a dilated detection region. Within the dilated detection region, it calculates the absolute difference of pixel values ​​at corresponding positions between the original image and the image after object removal. When the absolute difference is greater than a preset fine detection threshold, the pixel is marked as a difference pixel. The marked difference pixels are combined with the preliminary difference mask by performing a logical OR operation to generate the final difference mask. The mask fusion module performs a logical OR operation to fuse the final difference mask with the manually corrected mask image to obtain the fused difference mask. The connected component analysis module performs connected component analysis on the fused difference mask, extracts multiple connected components and filters out tiny connected components with an area smaller than a preset threshold, fits the minimum bounding rotation rectangle for each effective connected component, and obtains the bounding box geometric parameters of each connected component. The feathering mask generation module generates a corresponding bounding box mask based on the bounding box geometric parameters of each connected component. The bounding box mask is a binary image, where the pixel value inside the bounding box is 255 and the pixel value outside the bounding box is 0. It then performs a logical OR operation on the bounding box masks of all connected components to merge them, generating a merged bounding box mask. The merged bounding box mask is then dilated, with a second dilation radius set to generate a dilated region mask. The interior of the merged bounding box mask is defined as the core region, and its weight is set to 1.

0. The difference between the dilated region mask and the merged bounding box mask is defined as the feathered region. A distance transformation is performed on the feathered region, calculating the shortest Euclidean distance from each pixel within the region to the edge of the core region. This shortest Euclidean distance is then normalized to obtain a normalized distance value. The normalized distance value is input into a preset feathering curve function, mapped to a weight value, and an α-channel mask is generated. The grayscale value of each pixel in the α-channel mask is the fusion weight of that pixel, with a value range of [0,1]. The image fusion module unifies the resolution of the original image, the image after object removal, and the alpha channel mask, and performs pixel-level weighted fusion on each color channel according to the following formula: R_blended=R_cleaned×α(x,y)+R_orig×(1-α(x,y)) G_blended=G_cleaned×α(x,y)+G_orig×(1-α(x,y)) B_blended=B_cleaned×α(x,y)+B_orig×(1-α(x,y)) Wherein, R_blended, G_blended, and B_blended are the pixel values ​​of the fused pixel in the red, green, and blue channels, respectively; R_cleaned, G_cleaned, and B_cleaned are the pixel values ​​of the image after object removal in the red, green, and blue channels at coordinates (x, y), respectively; R_orig, G_orig, and B_orig are the pixel values ​​of the original image in the red, green, and blue channels at coordinates (x, y), respectively; α(x, y) is the grayscale value of the α channel mask generated in step S6 at coordinates (x, y), and its value range is [0, 1]. The merged red, green, and blue channel pixel values ​​are cropped to the range of [0, 255] and merged into an RGB format color image to generate the final repost image.

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, it implements the method as described in any one of claims 1 to 7.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method as described in any one of claims 1 to 7.