Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- from cv2 import imread, imwrite, IMREAD_UNCHANGED
- def apply_white_background_removal(img):
- alpha_channel = img[:, :, 3]
- white_background_mask = (alpha_channel == 255)
- img[white_background_mask] = [0, 0, 0, 0]
- return img
- def remove_background(img_path, output_path, background_removal_func):
- img = imread(img_path, IMREAD_UNCHANGED)
- img = background_removal_func(img)
- imwrite(output_path, img)
- if __name__ == "__main__":
- input_image_path = "caminho/para/sua/imagem.png"
- output_image_path = "caminho/para/salvar/nova/imagem_sem_fundo.png"
- remove_background(input_image_path, output_image_path, apply_white_background_removal)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement