A method, device, equipment and medium for generating an arbitrary solid color background for a commodity image
Patent Information
- Application Number
- CN202510916219.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Priority Date
- 2025-04-30
- Filing Date
- 2025-07-03
- Publication Date
- 2026-09-29
- Estimated Expiration
- 2045-07-03
AI Technical Summary
一部分方法通过人工拍摄,难以保证背景的一致性和纯净度,且拍摄过程受环境、设备等因素影响较大
[0021]1、高效性:相比传统的人工获取纯色背景或复杂的图像处理方式,本发明利用Stable Diffusion生成式算法和优化的算法,借助depth模块和 lineart模块控制网络辅助生成纯色背景,并快速完成颜色校准。单张图像的处理时间从传统人工操作的数分钟甚至更长时间,缩短至数秒内,大大提高了处理效率,能够满足批量生成商品图纯色背景的需求。
Smart Images

Figure CN120747282B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of background image creation technology, and in particular to a method, apparatus, device, and medium for generating arbitrary solid color backgrounds from product images. Background Technology
[0002] In product image displays, a solid color background is crucial for highlighting the main product. Currently, traditional methods for obtaining solid color backgrounds for product images have several problems. Some methods rely on manual shooting, which struggles to guarantee background consistency and purity, and the shooting process is significantly affected by environmental and equipment factors. Existing image processing technologies, when generating solid color backgrounds, cannot meet users' needs for different background colors. Changing the background color often requires complex manual operations, which are inefficient and difficult to batch process. This not only increases labor costs but also affects the overall effect and efficiency of product display. Summary of the Invention
[0003] The technical problem to be solved by the present invention is to provide a method, apparatus, device and medium for generating arbitrary solid color backgrounds for product images. It utilizes a white background image as a pad and a control network of depth and linearity to assist in generating solid color backgrounds. It can also quickly calibrate the background color according to the color specified by the user, so as to meet the diverse needs of solid color backgrounds in product image display and improve the product display effect and processing efficiency.
[0004] In a first aspect, the present invention provides a method for generating arbitrary solid color backgrounds from product images, comprising the following steps:
[0005] Step 1: Use the BiRefNet image matting model to cut out the background from the product image to obtain the image with the background removed;
[0006] Step 2: Combine the background-removed image with the white background image with a grayscale value of 255, and fill the background of the background-removed image with white to obtain the product white background image;
[0007] Step 3: Input the product's white background image into the depth module to obtain the depth image; input the product's white background image into the lineart module to obtain the lineart image;
[0008] Step 4: Send the depth image and linear image to ControlNet respectively, and use ControlNet to guide Stable Diffusion to draw an intermediate image with a solid color background;
[0009] Step 5: Convert the intermediate image from RGB color space to HSV color space, extract the H channel information, S channel information and V channel information of the intermediate image in HSV color space to obtain H1, S1 and V1, and obtain the set H2, S2 and V2.
[0010] Step 6: By iterating through each pixel in the intermediate image, modify the H1 and S1 values to H2 and S2 according to the difference. The entire image becomes H2, S2, V1. Then, convert H2, S2, V1 from HSV space to RGB space to obtain the final result image.
[0011] Secondly, the present invention provides an apparatus for generating arbitrary solid color backgrounds from product images, comprising:
[0012] Background units are removed by using the BiRefNet matting model to cut out the specified product image and obtain an image without the background.
[0013] Fill the background unit by combining the background-removed image with the white background image with a grayscale value of 255, and fill the background of the background-removed image with white to obtain the product white background image;
[0014] The instruction image unit inputs the product's white background image into the depth module to obtain the depth image; it then inputs the product's white background image into the lineart module to obtain the lineart image.
[0015] An intermediate unit is generated, and the depth image and linear image are sent to the control net respectively. The control net guides Stable Diffusion to draw an intermediate image with a solid color background.
[0016] The conversion channel unit converts the intermediate image from the RGB color space to the HSV color space, extracts the H channel information, S channel information and V channel information of the intermediate image in the HSV color space to obtain H1, S1 and V1, and obtains the set H2, S2 and V2.
[0017] The result unit is generated by iterating through each pixel in the intermediate image and modifying its H1 and S1 values to H2 and S2 according to the difference. The entire image becomes H2, S2, V1. Then, H2, S2, V1 are converted from HSV space to RGB space to obtain the final result 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:
[0021] 1. High Efficiency: Compared to traditional manual methods of obtaining solid-color backgrounds or complex image processing, this invention utilizes the Stable Diffusion generative algorithm and optimized algorithms, with the help of depth and linear modules to control the network to generate solid-color backgrounds and quickly complete color calibration. The processing time for a single image is reduced from several minutes or even longer in traditional manual operations to within seconds, greatly improving processing efficiency and meeting the needs of batch generating solid-color backgrounds for product images.
[0022] 2. Accuracy: A precise color calibration algorithm accurately generates solid color backgrounds that match the user's specified colors. Color deviation is controlled within an extremely small range, ensuring consistency between the product image background color and user expectations, thus enhancing the quality and professionalism of the product display. Simultaneously, the depth and linear modules control the background generated by the network, resulting in superior stability and structural rationality, and a higher degree of integration with the product subject.
[0023] 3. Flexibility: Users can freely specify any color as the solid color background for product images. This invention can quickly respond and complete color calibration, meeting the diverse background color needs in product displays. Whether it's common colors or special custom colors, they can be easily achieved, providing more creative and selective space for product displays.
[0024] 4. Compatibility: This invention can be seamlessly integrated into existing product image processing workflows and has good compatibility with other image processing technologies and software. For example, it can be combined with existing product image editing software as a functional module for generating solid color backgrounds and adjusting colors, making it convenient for users to use in their existing workflows and reducing the threshold and cost of technology application.
[0025] 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
[0026] The present invention will be further described below with reference to the accompanying drawings and embodiments.
[0027] Figure 1 This is a flowchart of the method in Embodiment 1 of the present invention;
[0028] Figure 2 This is a schematic diagram of the device in Embodiment 2 of the present invention. Detailed Implementation
[0029] This application provides a method, apparatus, device, and medium for generating arbitrary solid color backgrounds for product images. It utilizes a white background image as a pad and a control network of depth and linearity to assist in generating solid color backgrounds. It can also quickly calibrate the background color according to the color specified by the user, thereby meeting the diverse needs for solid color backgrounds in product image displays and improving product display effects and processing efficiency.
[0030] The overall concept of the technical solution in this application is as follows:
[0031] BiRefNet is a high-resolution image segmentation framework based on deep learning, often used to segment product images and backgrounds.
[0032] The depth module is used to extract depth information from an image. Its output depth image can reflect the distance relationship of objects in the image and provide reference information for the depth dimension when generating a solid color background.
[0033] The lineart module is used to extract the line structure of an image. The generated lineart image can highlight the outline and line features of the image, helping to generate a more structured solid color background.
[0034] controlnet: The control generation network in diffusion models can guide the generation of corresponding images based on the input image features (such as depth images, linear images). In this invention, it is used to guide Stable Diffusion to generate solid color backgrounds.
[0035] The algorithm is mainly implemented as follows:
[0036] (1) The product image is cut out using BiRefNet, and the composite area is marked in this way. After that, the algorithm only processes the background of the product image.
[0037] (2) Combine the transparent image with the white background image with a gray value of 255, and fill the background of the transparent image with white to obtain the white background product image.
[0038] (3) Send the white background product image to the depth module and the lineart module respectively to extract the depth image and the lineart image, and obtain the depth image and the lineart image.
[0039] (4) Input the white-background product image into the stable diffusion model, and send the depth image and linear image into the controlnet. At the same time, enable the color detail control plugin CD-Tuner, set the redraw amplitude to 0.85, and set the reference weights of the linear and depth modules to 0.5 and 0.6 respectively, so as to guide the Stable Diffusion to generate the initial solid color background. During the generation process, CD-Tuner optimizes and adjusts the color details to make the solid color background purer and more natural;
[0040] For example: CD-Tuner parameter settings details: To accurately generate a red background, in CD-Tuner, first adjust the Hue parameter to the corresponding red hue range. Generally, the red hue value is 0°. Set the Saturation parameter to 0.8 and the Value or Brightness parameter to 0.6.
[0041] (5) Convert the intermediate image from the common RGB color space to the HSV color space, extract the H channel, S channel and V channel information of the intermediate image in the HSV color space, and store them as H1, S1 and V1 respectively. Convert the user input RGB information into HSV channels and name them H2, S2 and V2.
[0042] (6) Adjust the color of each pixel in the initial solid color background. By traversing each pixel in the image, modify the H1 and S1 values to H2 and S2 according to the difference. The entire image will change to H2, S2, V1. Then, convert H2, S2, V1 from HSV space to RGB space to obtain the final result image.
[0043] Example 1
[0044] like Figure 1 As shown in the figure, this embodiment provides a method for generating arbitrary solid color backgrounds from product images, including the following steps:
[0045] Step 1: Use the BiRefNet image matting model to cut out the background from the product image to obtain the image with the background removed;
[0046] Step 2: Combine the background-removed image with the white background image with a grayscale value of 255, and fill the background of the background-removed image with white to obtain the product white background image;
[0047] Step 3: Input the product's white background image into the depth module to obtain the depth image; input the product's white background image into the lineart module to obtain the lineart image;
[0048] Step 4: Send the depth image and linear image to ControlNet respectively, and use ControlNet to guide Stable Diffusion to draw an intermediate image with a solid color background;
[0049] Step 5: Convert the intermediate image from RGB color space to HSV color space, extract the H channel information, S channel information and V channel information of the intermediate image in HSV color space to obtain H1, S1 and V1, and obtain the set H2, S2 and V2.
[0050] Step 6: By iterating through each pixel in the intermediate image, modify the H1 and S1 values to H2 and S2 according to the difference. The entire image becomes H2, S2, V1. Then, convert H2, S2, V1 from HSV space to RGB space to obtain the final result image.
[0051] In this embodiment, preferably, step 4 specifically involves: inputting a white-background product image into the stable diffusion model, sending the depth image and linear image to the controlnet respectively, enabling the color detail control plugin CD-Tuner, setting the redraw amplitude to 0.85, and setting the reference weights of the linear and depth modules to 0.5 and 0.6 respectively, and using the controlnet to guide Stable Diffusion in drawing an intermediate image with a solid color background.
[0052] In this embodiment, preferably, step 5 specifically involves: converting the intermediate image from the RGB color space to the HSV color space, extracting the H channel information, S channel information, and V channel information of the intermediate image in the HSV color space to obtain H1, S1, and V1, and converting the user-input RGB information into HSV channel information to obtain H2, S2, and V2.
[0053] Based on the same inventive concept, this application also provides an apparatus corresponding to the method in Embodiment 1, as detailed in Embodiment 2.
[0054] Example 2
[0055] like Figure 2 As shown, this embodiment provides an apparatus for generating arbitrary solid color backgrounds from product images, including:
[0056] Background units are removed by using the BiRefNet matting model to cut out the specified product image and obtain an image without the background.
[0057] Fill the background unit by combining the background-removed image with the white background image with a grayscale value of 255, and fill the background of the background-removed image with white to obtain the product white background image;
[0058] The instruction image unit inputs the product's white background image into the depth module to obtain the depth image; it then inputs the product's white background image into the lineart module to obtain the lineart image.
[0059] An intermediate unit is generated, and the depth image and linear image are sent to the control net respectively. The control net guides Stable Diffusion to draw an intermediate image with a solid color background.
[0060] The conversion channel unit converts the intermediate image from the RGB color space to the HSV color space, extracts the H channel information, S channel information and V channel information of the intermediate image in the HSV color space to obtain H1, S1 and V1, and obtains the set H2, S2 and V2.
[0061] The result unit is generated by iterating through each pixel in the intermediate image and modifying its H1 and S1 values to H2 and S2 according to the difference. The entire image becomes H2, S2, V1. Then, H2, S2, V1 are converted from HSV space to RGB space to obtain the final result image.
[0062] In this embodiment, preferably, the generation of the intermediate unit specifically involves: inputting a white-background product image into the stablediffusion model, sending the depth image and linear image to the controlnet respectively, enabling the color detail control plugin CD-Tuner, setting the redraw magnitude to 0.85, and setting the reference weights of the linear and depth modules to 0.5 and 0.6 respectively, and using the controlnet to guide Stable Diffusion in drawing and generating an intermediate image with a solid color background.
[0063] In this embodiment, preferably, the conversion channel unit specifically performs the following steps: converting the intermediate image from the RGB color space to the HSV color space, extracting the H channel information, S channel information and V channel information of the intermediate image in the HSV color space to obtain H1, S1 and V1, and converting the user-input RGB information into HSV channel information to obtain H2, S2 and V2.
[0064] 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.
[0065] Based on the same inventive concept, this application provides an electronic device embodiment corresponding to Embodiment 1, as detailed in Embodiment 3.
[0066] Example 3
[0067] 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.
[0068] 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.
[0069] Based on the same inventive concept, this application provides a storage medium corresponding to Embodiment 1, as detailed in Embodiment 4.
[0070] Example 4
[0071] 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.
[0072] 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.
[0073] 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 1A device that provides the functions specified in one or more boxes.
[0074] 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.
[0075] 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.
[0076] 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 generating arbitrary solid color backgrounds from product images, characterized in that: Includes the following steps: Step 1: Use the BiRefNet image matting model to cut out the background from the product image to obtain the image with the background removed; Step 2: Combine the background-removed image with the white background image with a grayscale value of 255, and fill the background of the background-removed image with white to obtain the product white background image; Step 3: Input the product's white background image into the depth module to obtain the depth image; input the product's white background image into the lineart module to obtain the lineart image; Step 4: Input the white-background product image into the stable diffusion model, send the depth image and linear image to the controlnet respectively, and enable the color detail control plugin CD-Tuner. Set the redraw amplitude to 0.85, and set the reference weights of the linear and depth modules to 0.5 and 0.6 respectively. Use the controlnet to guide StableDiffusion to draw and generate an intermediate image with a solid color background. Step 5: Convert the intermediate image from RGB color space to HSV color space, extract the H channel information, S channel information and V channel information of the intermediate image in HSV color space to obtain H1, S1 and V1, and obtain the set H2, S2 and V2. Step 6: By iterating through each pixel in the intermediate image, modify the H1 and S1 values to H2 and S2 according to the difference. The entire image becomes H2, S2, V1. Then, convert H2, S2, V1 from HSV space to RGB space to obtain the final result image.
2. The method for generating arbitrary solid color backgrounds from product images according to claim 1, characterized in that: Step 5 specifically involves: converting the intermediate image from the RGB color space to the HSV color space, extracting the H channel information, S channel information, and V channel information of the intermediate image in the HSV color space to obtain H1, S1, and V1, and converting the user-input RGB information into HSV channel information to obtain H2, S2, and V2.
3. An apparatus for generating arbitrary solid color backgrounds from product images, characterized in that: include: Background units are removed by using the BiRefNet matting model to cut out the specified product image and obtain an image without the background. Fill the background unit by combining the background-removed image with the white background image with a grayscale value of 255, and fill the background of the background-removed image with white to obtain the product white background image; The instruction image unit inputs the product's white background image into the depth module to obtain the depth image; it then inputs the product's white background image into the lineart module to obtain the lineart image. An intermediate unit is generated. The white-background product image is input into the stable diffusion model. The depth image and linear image are sent to the controlnet respectively. At the same time, the color detail control plugin CD-Tuner is enabled, the redraw amplitude is set to 0.85, and the reference weights of the linear and depth modules are set to 0.5 and 0.6 respectively. The controlnet guides the Stable Diffusion to draw and generate an intermediate image with a solid color background. The conversion channel unit converts the intermediate image from the RGB color space to the HSV color space, extracts the H channel information, S channel information and V channel information of the intermediate image in the HSV color space to obtain H1, S1 and V1, and obtains the set H2, S2 and V2. The result unit is generated by iterating through each pixel in the intermediate image and modifying its H1 and S1 values to H2 and S2 according to the difference. The entire image becomes H2, S2, V1. Then, H2, S2, V1 are converted from HSV space to RGB space to obtain the final result image.
4. The apparatus for generating arbitrary solid color backgrounds for product images according to claim 3, characterized in that: The conversion channel unit specifically performs the following steps: converting the intermediate image from the RGB color space to the HSV color space, extracting the H channel information, S channel information and V channel information of the intermediate image in the HSV color space to obtain H1, S1 and V1, and converting the user-input RGB information into HSV channel information to obtain H2, S2 and V2.
5. 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 2.
6. 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 2.