-3

in this demo color is not changed : https://huggingface.co/spaces/KenjieDec/RemBG

So here my method

def remove_background(image_path):
    # Read the input image
    input_image = cv2.imread(image_path, cv2.IMREAD_UNCHANGED)
    
    # Remove the background
    output_image = remove(input_image, alpha_matting=True, alpha_matting_erode_size=10)

    output_image_pil = Image.fromarray(output_image)
    
    return output_image_pil

. . .

   image = remove_background(file_path)
   image.save(save_file_path)

here input png. it has white background

enter image description here

here output png. background removed but the color tone is changed

enter image description here

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
Furkan Gözükara
  • 22,964
  • 77
  • 205
  • 342

1 Answers1

0

In short, it's the way how rembg algorithm works. Sometimes it might lose the color information.

rembg converts the image to a binary mask and then applies that mask to the original image. This might result in some changes in the color.

  • you can try to use different background removal methods such as the GrabCut algorithm from opencv.
  • try to adjust parameters of rembg such as threshold, radius, and scale.
  • use the split function to separate the image into its color channels. Then you can adjust the color values of each channel individually. In the end, you can merge it back.
  • after removing the background apply the mask to the original image with the bitwise_and function and then apply histogram equalization to adjust the color tone with cvtColor and equalizeHist.

Last but not least, try to look for other alternatives.

RAI
  • 584
  • 9