Pixel comparison-based generative model data production method, device, equipment and medium
By using pixel comparison and morphological optimization methods, the qualification of image removal results is automatically determined, which solves the problems of unstable removal effect and tedious manual screening in the nano-banana model. It realizes the construction of efficient and accurate image removal datasets, which are applicable to a variety of image types.
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-03
AI Technical Summary
Existing image object removal schemes based on nano-banana models suffer from unstable removal effects, poor visual consistency, low automation, and cumbersome manual screening, making it difficult to build high-quality image removal datasets and affecting the training efficiency of AI models.
A pixel-based generative model data pairing method is adopted. By unifying resolution, comparing three-channel pixels, morphological optimization, and identifying shadow regions, combined with interference ratio calculation, the qualification of the removal results is automatically determined, and the batch automated construction of image removal results is realized.
It achieves automated screening of elimination results, improving efficiency by 200 times, reducing labor costs by 99%, significantly improving the accuracy of elimination results and the retention rate of qualified results, ensuring the quality and stability of data pairs, and adapting to various image types.
Smart Images

Figure CN122335565A_ABST
Abstract
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 creating generative model data pairs based on pixel comparison. Background Technology
[0002] Image object removal is a core research direction in computer vision and image processing, widely applied in image inpainting, dataset construction, and visual content optimization. High-quality "original image-removed image" data pairs are crucial for training high-performance AI image inpainting models and improving object removal effectiveness. Currently, image object removal schemes based on nano-banana diffusion models have become a common technique in this field due to their lightweight deployment and rapid initial removal capabilities. However, this approach suffers from several insurmountable technical shortcomings in practical applications, failing to balance removal accuracy with data construction efficiency, thus hindering the construction of large-scale, high-quality image removal datasets and the subsequent training and deployment of AI models. Existing object removal schemes based on the nano-banana model mostly employ a method where inputting fill color blocks triggers model generation to eliminate target objects. Limited by the diffusion model's generation mechanism, these schemes suffer from poor stability and lack of visual consistency. Specifically: First, the model easily misidentifies and eliminates non-target objects with colors similar to the fill color blocks, resulting in the loss of key background elements and compromising image integrity. Second, for complex textures, text, and other refined areas, the model-generated fill is prone to distortion and deformation, failing to match the original image's style and content, resulting in a significant visual incongruity. Third, the edges of the eliminated areas are abruptly transitioned, leaving obvious traces of manual filling and easily accompanied by pixel jitter. For example, removing the area behind the target chair results in large-scale pixel jitter in the floor area and at the edges of the cardboard stack, leading to extremely poor overall visual coordination and failing to meet acceptable image standards. Meanwhile, the solution lacks an automated quality assessment and screening mechanism. High-quality data construction heavily relies on manual operation, which is not only costly but also difficult to control in terms of quality. On the one hand, in batch processing scenarios (such as batch removal of thousands of images), the removal results must be manually checked one by one to determine whether there are defects such as false removal, texture deformation, or obvious filling traces. Manual screening is time-consuming, inefficient, and subject to subjective judgment differences, lacking a unified screening standard, significantly increasing the cost of data collection. On the other hand, when the nano-banana model removes target objects, it simultaneously removes the object's associated projection. This normal processing effect is easily confused with abnormal noise in non-target areas generated by the model. Manual screening struggles to accurately distinguish between normally removed areas and abnormal interference areas, easily leading to the erroneous rejection of qualified results and the erroneous retention of unqualified results, further reducing data quality. Furthermore, existing solutions lack a systematic, fully automated processing system, failing to achieve a closed-loop automated operation of "original image and mask image input, nano-banana model elimination, intelligent result filtering, and qualified data pair output." The manual intervention process is cumbersome and redundant, which not only slows down the construction of large-scale datasets but also directly affects the training efficiency and iteration speed of subsequent AI image restoration models, making it difficult to adapt to the application needs of large-scale and efficient domains. Summary of the Invention
[0003] The technical problem to be solved by this invention is to provide a method, apparatus, device and medium for generating model data pairs based on pixel comparison. Through core steps such as resolution unification, three-channel pixel comparison, morphological optimization, shadow region recognition and interference ratio calculation, it accurately distinguishes the target elimination area (object + shadow) from abnormal interference areas, automatically determines whether the elimination result is qualified, and finally realizes the batch automated construction of "original image-elimination image" data pairs. This meets the needs of scenarios with high requirements for the accuracy and data quality of object elimination results, such as image editing, AI model training and dataset annotation, and significantly reduces labor costs and improves data construction efficiency.
[0004] In a first aspect, the present invention provides a method for creating generative model data pairs based on pixel comparison, characterized by comprising the following steps: Step 1: Obtain the original image Img_ori and the binarized mask image Mask_obj of the object to be eliminated. Fill the object region with a solid magenta color based on the Mask_obj to generate the fill image Img_fill. Input the Img_fill into the image object elimination model and output the preliminary elimination result image Img_elim. Step 2: Extract the resolution parameters of Img_ori and adjust Img_elim to a resolution consistent with Img_ori; Step 3: Perform pixel-by-pixel three-channel difference calculation on Img_elim and Img_ori after unifying the resolution, and generate the initial variable mask Mask_ori based on the preset pixel difference threshold T; Step 4: Perform morphological opening operation on the Mask_ori to remove isolated noise points and generate an optimized variable mask Mask_opt; Step 5: Based on 8-neighborhood connectivity analysis, identify regions from Mask_opt that are connected to the object region represented by Mask_obj and have an area greater than the first area threshold S1, and generate a shadow mask Mask_shadow. Step 6: Remove the object region corresponding to Mask_obj and the shadow region corresponding to Mask_shadow from Mask_opt to generate a noise mask Mask_noise, and count the total number of pixels of Mask_noise Noise_pix; Step 7: Calculate the interference ratio Ratio_noise and the maximum noise area Max_noise_area based on the Mask_noise. If the interference ratio is greater than the preset interference ratio threshold R or the maximum noise area is greater than the second area threshold S2, then Img_elim is determined to be an abnormal elimination result and discarded; otherwise, Img_ori and Img_elim are stored as a valid data pair.
[0005] Secondly, the present invention provides an apparatus for generating model data pairs based on pixel comparison, comprising: The image preprocessing and removal module obtains the original image Img_ori and the binarized mask image Mask_obj of the object to be removed. Based on the Mask_obj, the object region is filled with a solid magenta color to generate a fill image Img_fill. The Img_fill is input into the image object removal model, and the preliminary removal result image Img_elim is output. The resolution unification module extracts the resolution parameters of Img_ori and adjusts Img_elim to a resolution consistent with Img_ori. The pixel comparison module performs pixel-by-pixel three-channel difference calculation on Img_elim and Img_ori after unifying the resolution, and generates an initial variable mask Mask_ori based on the preset pixel difference threshold T. The morphological optimization module performs a morphological opening operation on the Mask_ori to remove isolated noise points and generate an optimized variable mask Mask_opt; The shadow region recognition module, based on 8-neighborhood connectivity analysis, identifies regions from the Mask_opt that are connected to the object region represented by the Mask_obj and whose area is greater than the first area threshold S1, and generates a shadow mask Mask_shadow; The noise region extraction module removes the object region corresponding to Mask_obj and the shadow region corresponding to Mask_shadow from Mask_opt, generates a noise mask Mask_noise, and counts the total number of pixels of Mask_noise Noise_pix; The anomaly detection module calculates the interference ratio Ratio_noise and the maximum noise area Max_noise_area based on the Mask_noise. If the interference ratio is greater than the preset interference ratio threshold R or the maximum noise area is greater than the second area threshold S2, then Img_elim is determined to be an anomaly elimination result and discarded; otherwise, Img_ori and Img_elim are stored as a valid data pair.
[0006] 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.
[0007] 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.
[0008] One or more technical solutions provided by this invention have at least the following technical effects or advantages: 1. The entire process of eliminating and filtering a single image in this invention takes ≤3 seconds, which is 200 times more efficient than manual filtering (10 minutes per image on average); when processing 1000 images in batches, the total time is ≤50 minutes, and large-scale high-quality “original image-elimination image” data pairs can be quickly constructed.
[0009] 2. This invention achieves automated screening of elimination results, eliminating the need for manual verification one by one, reducing labor costs by more than 99%, and ensuring uniform screening standards to avoid quality fluctuations caused by subjective judgment differences.
[0010] 3. The accuracy rate of anomaly elimination results recognition of this invention is ≥97%, and the retention rate of qualified results is ≥98%. It can accurately distinguish anomalies such as false elimination, texture distortion, and style inconsistency, which is more than 14% higher than manual screening (accuracy rate of about 85%).
[0011] 4. The present invention has a shadow region recognition accuracy of ≥95% and an abnormal noise and normal variation differentiation accuracy of ≥96%, effectively avoiding confusion between target area and interference area and ensuring the quality and stability of the filtered data pairs.
[0012] 5. This invention supports multiple image formats such as JPG, PNG, and BMP, and is compatible with more than 20 types of image types, including natural scenes, indoor scenes, text images, and texture images. It has a good filtering effect on objects of different sizes and materials to be eliminated.
[0013] 6. The pixel difference threshold T, shadow area threshold S1, interference ratio threshold R, and maximum noise area threshold S2 of this invention can all be flexibly adjusted according to the actual scene, adapting to the quality requirements of different image removal tasks, and have strong generalization ability.
[0014] 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
[0015] The present invention will be further described below with reference to the accompanying drawings and embodiments.
[0016] 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
[0017] This application provides a method, apparatus, device, and medium for creating generative model data pairs based on pixel comparison, which solves the shortcomings of existing nano-banana model object elimination schemes, such as "disordered results, cumbersome manual screening, difficulty in distinguishing regions, and low degree of automation".
[0018] The overall concept of the technical solution in this application is as follows: The automatic object removal result filtering method proposed in this invention is based on a five-order framework of "image preprocessing - removal processing - pixel comparison - morphological optimization - anomaly detection", and is implemented through the following key modules: Image preprocessing and elimination module Input data preparation: Obtain the original image (denoted as Img_ori) and the binarized mask image of the object to be removed (denoted as Mask_obj, with a pixel value of 255 for the object region and a pixel value of 0 for the background region), ensuring that the position and contour of the target object in the mask image correspond accurately to those in the original image.
[0019] Filling and elimination processing: Based on Mask_obj, the region of the object to be eliminated is located, and pure magenta is used to fill the region to generate a filled map (denoted as Img_fill); Img_fill is input into the nano-banana model, and the model performs elimination processing on the target object and outputs a preliminary elimination result map (denoted as Img_elim).
[0020] Resolution unification: Extract the resolution parameters (width W × height H) of Img_ori, and use a bilinear interpolation algorithm to adjust Img_elim to a resolution that is completely consistent with Img_ori, so as to avoid errors in subsequent pixel comparison due to resolution differences.
[0021] Three-channel pixel comparison module Pixel difference calculation: Perform pixel-by-pixel three-channel (R, G, B) difference calculation on Img_ori and Img_elim after resolution unification to obtain the three-channel difference value (ΔR, ΔG, ΔB) of each pixel. The calculation formula is as follows: ΔR=|R_ori-R_elim| ΔG=|G_ori-G_elim| ΔB=|B_ori-B_elim| where R_ori, G_ori, and B_ori are the three-channel values of the pixel corresponding to Img_ori, and R_elim, G_elim, and B_elim are the three-channel values of the pixel corresponding to Img_elim.
[0022] Variable pixel determination: Set a pixel difference threshold T (default T=10, which can be flexibly adjusted according to image type and scene requirements). If any one of the values of ΔR, ΔG, and ΔB of a pixel is greater than T, the pixel is determined to be a variable pixel and marked as 1; otherwise, it is a non-variable pixel and marked as 0. After traversing all pixels, an initial variable mask (denoted as Mask_ori) is generated.
[0023] Morphological optimization and shadow region recognition module Preliminary noise removal: Perform a morphological opening operation of "erosion followed by dilation" on Mask_ori: use a 3×3 rectangular structuring element for one erosion process to eliminate small isolated noise points; then use the same structuring element for one dilation process to restore the complete outline of the target area and output the optimized variable mask (denoted as Mask_opt).
[0024] Shadow region localization: Based on the characteristic that "shadows are usually connected to target objects," the connected regions of Mask_opt and Mask_obj are calculated. Connected regions directly connected to Mask_obj (the object region) and with an area greater than a set threshold S1 (default S1 = 50 pixels) are identified as shadow regions, and a shadow mask (denoted as Mask_shadow, with a pixel value of 255 for shadow regions and 0 for other regions) is generated. This step accurately distinguishes shadow regions from isolated noise points, avoiding misjudgments.
[0025] Interference Ratio Calculation and Anomaly Detection Module Noise mask generation: Based on Mask_opt, set the corresponding pixels of Mask_obj (object region) and Mask_shadow (shadow region) to 0. The area with the remaining pixel value of 1 is the abnormal noise region, and generate a noise mask (denoted as Mask_noise).
[0026] Effective region calculation: Calculate the total number of pixels in the entire image (Total_pix=W×H), subtract the number of pixels in the object region corresponding to Mask_obj (Obj_pix) and the number of pixels in the shadow region corresponding to Mask_shadow (Shadow_pix), and obtain the number of pixels in the interference-free reference region (Ref_pix=Total_pix-Obj_pix-Shadow_pix).
[0027] Interference ratio and maximum noise area calculation: Count the number of pixels in Mask_noise (Noise_pix), and calculate the interference ratio (Ratio_noise) using the formula: Ratio_noise = Noise_pix / Ref_pix × 100%; At the same time, use the connected component analysis algorithm to calculate the number of pixels in the largest connected region in Mask_noise (Max_noise_area).
[0028] Anomaly detection rules: Set an interference percentage threshold R (default R=5%) and a maximum noise area threshold S2 (default S2=100 pixels). If either of the following two conditions is met, Img_elim is considered an anomaly removal result and is not included in the data pair construction: 1. The proportion of interference (Ratio_noise) is greater than R; 2. Maximum noise area Max_noise_area > S2. If neither condition is met, then Img_elim is considered a qualified elimination result, and "Img_ori-Img_elim" is stored as a valid data pair.
[0029] (II) Algorithm Flow 1. Input the original image Img_ori and the mask image Mask_obj of the object to be removed, and generate Img_fill based on the object region filled in Mask_obj; 2. Input Img_ori and Img_fill into the nano-banana model, and output the preliminary elimination result map Img_elim; 3. Standardize the resolution of Img_ori and Img_elim to ensure pixel-level comparison accuracy; 4. Calculate the difference value of the three channels between the two images pixel by pixel, and generate an initial change mask Mask_ori based on the threshold T; 5. Perform an "erosion-dilation" opening operation on Mask_ori to obtain the optimized mask Mask_opt; 6. Based on connectivity analysis, identify large areas connected to the object region from Mask_opt and generate a shadow mask Mask_shadow; 7. Remove the object and shadow regions from Mask_opt to generate a noise mask Mask_noise; 8. Calculate the interference ratio Ratio_noise and the maximum noise area Max_noise_area; 9. Determine whether the elimination result is qualified based on the set threshold. If qualified, output the "Img_ori-Img_elim" data pair; otherwise, discard it. 10. Repeat steps 1-9 to achieve automated filtering and data pairing of batch images.
[0030] (III) Terminology Explanation Nano-banana model: An image object removal model based on a diffusion model, which can remove target objects and fill the background based on the input image and the mask image, but there is a certain risk of incorrect results.
[0031] Morphological opening operation: a composite operation consisting of two basic morphological operations, "erosion" and "dilation". Erosion can eliminate small noise, and dilation can restore the contour of the target area. It is often used for image noise removal and contour optimization.
[0032] Variation mask: A binarized image generated by pixel comparison, used to mark the regions in the original image and the eliminated image where pixels have changed, providing a basis for subsequent region differentiation.
[0033] Interference ratio: The ratio of the number of pixels in the abnormal noise area to the number of pixels in the interference-free reference area, used to quantify the degree of abnormality in the elimination result.
[0034] Connected component analysis: an image segmentation technique used to identify sets of adjacent (usually 4-neighbor or 8-neighbor) pixels in an image. In this invention, it is used to distinguish shadow regions from isolated noise regions. Example
[0035] like Figure 1 As shown, this embodiment provides a method for creating generative model data pairs based on pixel comparison, including the following steps: Step 1: Obtain the original image Img_ori and the binarized mask image Mask_obj of the object to be eliminated. Fill the object region with a solid magenta color based on the Mask_obj to generate the fill image Img_fill. Input the Img_fill into the image object elimination model and output the preliminary elimination result image Img_elim. Step 2: Extract the resolution parameters of Img_ori and adjust Img_elim to a resolution consistent with Img_ori; Step 3: Perform pixel-by-pixel three-channel difference calculation on Img_elim and Img_ori after unifying the resolution, and generate the initial variable mask Mask_ori based on the preset pixel difference threshold T; Step 4: Perform morphological opening operation on the Mask_ori to remove isolated noise points and generate an optimized variable mask Mask_opt; Step 5: Based on 8-neighborhood connectivity analysis, identify regions from Mask_opt that are connected to the object region represented by Mask_obj and have an area greater than the first area threshold S1, and generate a shadow mask Mask_shadow. Step 6: Remove the object region corresponding to Mask_obj and the shadow region corresponding to Mask_shadow from Mask_opt to generate a noise mask Mask_noise, and count the total number of pixels of Mask_noise Noise_pix; Step 7: Calculate the interference ratio Ratio_noise and the maximum noise area Max_noise_area based on the Mask_noise. If the interference ratio is greater than the preset interference ratio threshold R or the maximum noise area is greater than the second area threshold S2, then Img_elim is determined to be an abnormal elimination result and discarded; otherwise, Img_ori and Img_elim are stored as a valid data pair.
[0036] In this embodiment, preferably, step 3 specifically comprises: Calculate the difference values ΔR, ΔG, and ΔB for each pixel in the R, G, and B channels, where: ΔR=|R_ori-R_elim|, ΔG=|G_ori-G_elim|, ΔB=|B_ori-B_elim|, R_ori, G_ori, and B_ori are the three-channel values of the pixel corresponding to Img_ori, and R_elim, G_elim, and B_elim are the three-channel values of the pixel corresponding to Img_elim. If any one of ΔR, ΔG, or ΔB is greater than the pixel difference threshold T, then the pixel is marked as a variable pixel and assigned a value of 1; otherwise, it is marked as a non-variable pixel and assigned a value of 0. After traversing all pixels, a binary initial variable mask Mask_ori is generated, where a pixel value of 1 represents a variable region and a pixel value of 0 represents a non-variable region.
[0037] In this embodiment, preferably, the morphological opening operation in step 4 specifically involves: using a 3×3 rectangular structuring element, first performing an erosion process on the Mask_ori, and then using the same 3×3 rectangular structuring element to perform a dilation process on the eroded image to obtain the optimized variable mask Mask_opt.
[0038] In this embodiment, preferably, the first area threshold S1 is set to S1=max(50,Total_pix×0.1%), where Total_pix is the total number of pixels in the image.
[0039] In this embodiment, preferably, step 6 specifically comprises: Calculate the total number of pixels in the image: Total_pix = W × H, where W is the image width and H is the image height; count the number of pixels in the object region corresponding to Mask_obj: Obj_pix, and the number of pixels in the shadow region corresponding to Mask_shadow: Shadow_pix; calculate the number of pixels in the interference-free reference region: Ref_pix = Total_pix - Obj_pix - Shadow_pix; The formula for calculating the interference ratio is: Ratio_noise=Noise_pix / Ref_pix×100%.
[0040] In this embodiment, preferably, in step 7, the maximum noise area Max_noise_area is obtained by performing 8-neighborhood connected region analysis on the Mask_noise. Specifically, all connected regions in the Mask_noise are identified, and the number of pixels in the connected region with the largest number of pixels is taken as Max_noise_area. In step 2, a bilinear interpolation algorithm is used to adjust the Img_elim to a resolution consistent with the Img_ori; The pixel difference threshold T is set to 10 by default, the interference ratio threshold R is set to 5% by default, and the second area threshold S2 is set to 100 pixels by default.
[0041] Based on the same inventive concept, this application also provides an apparatus corresponding to the method in Embodiment 1, as detailed in Embodiment 2.
[0042] Example 1 like Figure 2 As shown, this embodiment provides an apparatus for creating generative model data pairs based on pixel comparison, including: The image preprocessing and removal module obtains the original image Img_ori and the binarized mask image Mask_obj of the object to be removed. Based on the Mask_obj, the object region is filled with a solid magenta color to generate a fill image Img_fill. The Img_fill is input into the image object removal model, and the preliminary removal result image Img_elim is output. The resolution unification module extracts the resolution parameters of Img_ori and adjusts Img_elim to a resolution consistent with Img_ori. The pixel comparison module performs pixel-by-pixel three-channel difference calculation on Img_elim and Img_ori after unifying the resolution, and generates an initial variable mask Mask_ori based on the preset pixel difference threshold T. The morphological optimization module performs a morphological opening operation on the Mask_ori to remove isolated noise points and generate an optimized variable mask Mask_opt; The shadow region recognition module, based on 8-neighborhood connectivity analysis, identifies regions from the Mask_opt that are connected to the object region represented by the Mask_obj and whose area is greater than the first area threshold S1, and generates a shadow mask Mask_shadow; The noise region extraction module removes the object region corresponding to Mask_obj and the shadow region corresponding to Mask_shadow from Mask_opt, generates a noise mask Mask_noise, and counts the total number of pixels of Mask_noise Noise_pix; The anomaly detection module calculates the interference ratio Ratio_noise and the maximum noise area Max_noise_area based on the Mask_noise. If the interference ratio is greater than the preset interference ratio threshold R or the maximum noise area is greater than the second area threshold S2, then Img_elim is determined to be an anomaly elimination result and discarded; otherwise, Img_ori and Img_elim are stored as a valid data pair.
[0043] In this embodiment, preferably, the pixel comparison module specifically comprises: Calculate the difference values ΔR, ΔG, and ΔB for each pixel in the R, G, and B channels, where: ΔR=|R_ori-R_elim|, ΔG=|G_ori-G_elim|, ΔB=|B_ori-B_elim|, R_ori, G_ori, and B_ori are the three-channel values of the pixel corresponding to Img_ori, and R_elim, G_elim, and B_elim are the three-channel values of the pixel corresponding to Img_elim. If any one of ΔR, ΔG, or ΔB is greater than the pixel difference threshold T, then the pixel is marked as a variable pixel and assigned a value of 1; otherwise, it is marked as a non-variable pixel and assigned a value of 0. After traversing all pixels, a binary initial variable mask Mask_ori is generated, where a pixel value of 1 represents a variable region and a pixel value of 0 represents a non-variable region.
[0044] In this embodiment, preferably, the morphological opening operation in the morphological optimization module specifically involves: using a 3×3 rectangular structuring element, first performing an erosion process on the Mask_ori, and then using the same 3×3 rectangular structuring element to perform a dilation process on the eroded image to obtain the optimized variable mask Mask_opt.
[0045] In this embodiment, preferably, the first area threshold S1 is set to S1=max(50,Total_pix×0.1%), where Total_pix is the total number of pixels in the image.
[0046] In this embodiment, preferably, the noise region extraction module specifically comprises: Calculate the total number of pixels in the image: Total_pix = W × H, where W is the image width and H is the image height; count the number of pixels in the object region corresponding to Mask_obj: Obj_pix, and the number of pixels in the shadow region corresponding to Mask_shadow: Shadow_pix; calculate the number of pixels in the interference-free reference region: Ref_pix = Total_pix - Obj_pix - Shadow_pix; The formula for calculating the interference ratio is: Ratio_noise=Noise_pix / Ref_pix×100%.
[0047] In this embodiment, preferably, in the anomaly determination module, the maximum noise area Max_noise_area is obtained by performing 8-neighborhood connected region analysis on the Mask_noise. Specifically, all connected regions in the Mask_noise are identified, and the number of pixels in the connected region with the largest number of pixels is taken as Max_noise_area. In step 2, a bilinear interpolation algorithm is used to adjust the Img_elim to a resolution consistent with the Img_ori; The pixel difference threshold T is set to 10 by default, the interference ratio threshold R is set to 5% by default, and the second area threshold S2 is set to 100 pixels by default.
[0048] Based on the same inventive concept, this application also provides an apparatus corresponding to the method in Embodiment 1, as detailed in Embodiment 2.
[0049] Example 2 like Figure 2 As shown, this embodiment provides an apparatus for creating generative model data pairs based on pixel comparison, including: The image preprocessing and removal module obtains the original image Img_ori and the binarized mask image Mask_obj of the object to be removed. Based on the Mask_obj, the object region is filled with a solid magenta color to generate a fill image Img_fill. The Img_fill is input into the image object removal model, and the preliminary removal result image Img_elim is output. The resolution unification module extracts the resolution parameters of Img_ori and adjusts Img_elim to a resolution consistent with Img_ori. The pixel comparison module performs pixel-by-pixel three-channel difference calculation on Img_elim and Img_ori after unifying the resolution, and generates an initial variable mask Mask_ori based on the preset pixel difference threshold T. The morphological optimization module performs a morphological opening operation on the Mask_ori to remove isolated noise points and generate an optimized variable mask Mask_opt; The shadow region recognition module, based on 8-neighborhood connectivity analysis, identifies regions from the Mask_opt that are connected to the object region represented by the Mask_obj and whose area is greater than the first area threshold S1, and generates a shadow mask Mask_shadow; The noise region extraction module removes the object region corresponding to Mask_obj and the shadow region corresponding to Mask_shadow from Mask_opt, generates a noise mask Mask_noise, and counts the total number of pixels of Mask_noise Noise_pix; The anomaly detection module calculates the interference ratio Ratio_noise and the maximum noise area Max_noise_area based on the Mask_noise. If the interference ratio is greater than the preset interference ratio threshold R or the maximum noise area is greater than the second area threshold S2, then Img_elim is determined to be an anomaly elimination result and discarded; otherwise, Img_ori and Img_elim are stored as a valid data pair.
[0050] In this embodiment, preferably, the pixel comparison module specifically comprises: Calculate the difference values ΔR, ΔG, and ΔB for each pixel in the R, G, and B channels, where: ΔR=|R_ori-R_elim|, ΔG=|G_ori-G_elim|, ΔB=|B_ori-B_elim|, R_ori, G_ori, and B_ori are the three-channel values of the pixel corresponding to Img_ori, and R_elim, G_elim, and B_elim are the three-channel values of the pixel corresponding to Img_elim. If any one of ΔR, ΔG, or ΔB is greater than the pixel difference threshold T, then the pixel is marked as a variable pixel and assigned a value of 1; otherwise, it is marked as a non-variable pixel and assigned a value of 0. After traversing all pixels, a binary initial variable mask Mask_ori is generated, where a pixel value of 1 represents a variable region and a pixel value of 0 represents a non-variable region.
[0051] In this embodiment, preferably, the morphological opening operation in the morphological optimization module specifically involves: using a 3×3 rectangular structuring element, first performing an erosion process on the Mask_ori, and then using the same 3×3 rectangular structuring element to perform a dilation process on the eroded image to obtain the optimized variable mask Mask_opt.
[0052] In this embodiment, preferably, the first area threshold S1 is set to S1=max(50,Total_pix×0.1%), where Total_pix is the total number of pixels in the image.
[0053] In this embodiment, preferably, the noise region extraction module specifically comprises: Calculate the total number of pixels in the image: Total_pix = W × H, where W is the image width and H is the image height; count the number of pixels in the object region corresponding to Mask_obj: Obj_pix, and the number of pixels in the shadow region corresponding to Mask_shadow: Shadow_pix; calculate the number of pixels in the interference-free reference region: Ref_pix = Total_pix - Obj_pix - Shadow_pix; The formula for calculating the interference ratio is: Ratio_noise=Noise_pix / Ref_pix×100%.
[0054] In this embodiment, preferably, in the anomaly determination module, the maximum noise area Max_noise_area is obtained by performing 8-neighborhood connected region analysis on the Mask_noise. Specifically, all connected regions in the Mask_noise are identified, and the number of pixels in the connected region with the largest number of pixels is taken as Max_noise_area. The resolution unification module uses a bilinear interpolation algorithm to adjust the Img_elim to a resolution consistent with the Img_ori; The pixel difference threshold T is set to 10 by default, the interference ratio threshold R is set to 5% by default, and the second area threshold S2 is set to 100 pixels by default.
[0055] 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.
[0056] Based on the same inventive concept, this application provides an electronic device embodiment corresponding to Embodiment 1, as detailed in Embodiment 3.
[0057] 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.
[0058] 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.
[0059] Based on the same inventive concept, this application provides a storage medium corresponding to Embodiment 1, as detailed in Embodiment 4.
[0060] 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.
[0061] 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.
[0062] 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.
[0063] 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.
[0064] 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.
[0065] 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 creating generative model data pairs based on pixel comparison, characterized in that, Includes the following steps: Step 1: Obtain the original image Img_ori and the binarized mask image Mask_obj of the object to be eliminated. Fill the object region with a solid magenta color based on the Mask_obj to generate the fill image Img_fill. Input the Img_fill into the image object elimination model and output the preliminary elimination result image Img_elim. Step 2: Extract the resolution parameters of Img_ori and adjust Img_elim to a resolution consistent with Img_ori; Step 3: Perform pixel-by-pixel three-channel difference calculation on Img_elim and Img_ori after unifying the resolution, and generate the initial variable mask Mask_ori based on the preset pixel difference threshold T; Step 4: Perform morphological opening operation on the Mask_ori to remove isolated noise points and generate an optimized variable mask Mask_opt; Step 5: Based on 8-neighborhood connectivity analysis, identify regions from Mask_opt that are connected to the object region represented by Mask_obj and have an area greater than the first area threshold S1, and generate a shadow mask Mask_shadow. Step 6: Remove the object region corresponding to Mask_obj and the shadow region corresponding to Mask_shadow from Mask_opt to generate a noise mask Mask_noise, and count the total number of pixels of Mask_noise Noise_pix; Step 7: Calculate the interference ratio Ratio_noise and the maximum noise area Max_noise_area based on the Mask_noise. If the interference ratio is greater than the preset interference ratio threshold R or the maximum noise area is greater than the second area threshold S2, then Img_elim is determined to be an abnormal elimination result and discarded; otherwise, Img_ori and Img_elim are stored as a valid data pair.
2. The method according to claim 1, characterized in that, Step 3 specifically involves: Calculate the difference values ΔR, ΔG, and ΔB for each pixel in the R, G, and B channels, where: ΔR=|R_ori-R_elim|, ΔG=|G_ori-G_elim|, ΔB=|B_ori-B_elim|, R_ori, G_ori, and B_ori are the three-channel values of the pixel corresponding to Img_ori, and R_elim, G_elim, and B_elim are the three-channel values of the pixel corresponding to Img_elim. If any one of ΔR, ΔG, or ΔB is greater than the pixel difference threshold T, then the pixel is marked as a variable pixel and assigned a value of 1; otherwise, it is marked as a non-variable pixel and assigned a value of 0. After traversing all pixels, a binary initial variable mask Mask_ori is generated, where a pixel value of 1 represents a variable region and a pixel value of 0 represents a non-variable region.
3. The method according to claim 1, characterized in that, The morphological opening operation in step 4 specifically involves: using a 3×3 rectangular structuring element, first performing an erosion process on the Mask_ori, and then using the same 3×3 rectangular structuring element to perform a dilation process on the eroded image to obtain the optimized variable mask Mask_opt.
4. The method according to claim 1, characterized in that, The first area threshold S1 is set to S1=max(50,Total_pix×0.1%), where Total_pix is the total number of pixels in the image.
5. The method according to claim 1, characterized in that, Step 6 specifically involves: Calculate the total number of pixels in the image: Total_pix = W × H, where W is the image width and H is the image height; count the number of pixels in the object region corresponding to Mask_obj: Obj_pix, and the number of pixels in the shadow region corresponding to Mask_shadow: Shadow_pix; calculate the number of pixels in the interference-free reference region: Ref_pix = Total_pix - Obj_pix - Shadow_pix; The formula for calculating the interference ratio is: Ratio_noise=Noise_pix / Ref_pix×100%.
6. The method according to claim 1, characterized in that, In step 7, the maximum noise area Max_noise_area is obtained by performing 8-neighborhood connected region analysis on the Mask_noise. Specifically, all connected regions in the Mask_noise are identified, and the number of pixels in the connected region with the largest number of pixels is taken as Max_noise_area.
7. The method according to claim 1, characterized in that, In step 2, a bilinear interpolation algorithm is used to adjust the Img_elim to a resolution consistent with the Img_ori; The pixel difference threshold T is set to 10 by default, the interference ratio threshold R is set to 5% by default, and the second area threshold S2 is set to 100 pixels by default.
8. A device for generating model data pairs based on pixel comparison, characterized in that, include: The image preprocessing and removal module obtains the original image Img_ori and the binarized mask image Mask_obj of the object to be removed. Based on the Mask_obj, the object region is filled with a solid magenta color to generate a fill image Img_fill. The Img_fill is input into the image object removal model, and the preliminary removal result image Img_elim is output. The resolution unification module extracts the resolution parameters of Img_ori and adjusts Img_elim to a resolution consistent with Img_ori. The pixel comparison module performs pixel-by-pixel three-channel difference calculation on Img_elim and Img_ori after unifying the resolution, and generates an initial variable mask Mask_ori based on the preset pixel difference threshold T. The morphological optimization module performs a morphological opening operation on the Mask_ori to remove isolated noise points and generate an optimized variable mask Mask_opt; The shadow region recognition module, based on 8-neighborhood connectivity analysis, identifies regions from the Mask_opt that are connected to the object region represented by the Mask_obj and whose area is greater than the first area threshold S1, and generates a shadow mask Mask_shadow; The noise region extraction module removes the object region corresponding to Mask_obj and the shadow region corresponding to Mask_shadow from Mask_opt, generates a noise mask Mask_noise, and counts the total number of pixels of Mask_noise Noise_pix; The anomaly detection module calculates the interference ratio Ratio_noise and the maximum noise area Max_noise_area based on the Mask_noise. If the interference ratio is greater than the preset interference ratio threshold R or the maximum noise area is greater than the second area threshold S2, then Img_elim is determined to be an anomaly elimination result and discarded; otherwise, Img_ori and Img_elim are stored as a valid data pair.
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.