eugeneteoh / chromakey

Chroma key (green screen removal) algorithms with Python
MIT License
8 stars 3 forks source link

merge image cropped, zoomed and blur #1

Closed Priyankaagrawal closed 1 year ago

Priyankaagrawal commented 1 year ago

Hi I just wanted to replace the green screen with image attached, but the output is quite blur and image is cropping and zoomed. Please help me to resolve on same

wallpaper 144x120_1

eugeneteoh commented 1 year ago

Can you send me the code and the output image to reproduce?

Priyankaagrawal commented 1 year ago

` from PIL import Image from pathlib import Path import numpy as np from chromakey import chroma_key

image_path = Path(file).parent / "uneven_green_green_lighting.png" image = Image.open(str(image_path))

background_image = Image.new("RGB", image.size, "red")

background_image_path = Path(file).parent / "MAWP-C-1302_1.jpg" background_image = Image.open(str(background_image_path))

image = np.asarray(image) background_image = np.asarray(background_image) maskedimage, = chroma_key( image, keycolor="#6dff8b", background_image=background_image, tola=25, tolb=50 ) Image.fromarray(masked_image).show()`

Priyankaagrawal commented 1 year ago

image MAWP-C-1302_other

eugeneteoh commented 1 year ago

Ah yes. If you look into the code, the background image is resized to the same size as the original image. Background image is then summed with the mask.

If you don't want it to be zoomed in. You have to somehow project your image onto the mask.

Priyankaagrawal commented 1 year ago

Can you suggest, where I need to do this changes? I think this changes will go in core.py? I just want to apply image in green screen fully

eugeneteoh commented 1 year ago

I imagine it would be a separate new function. It is quite specific to your use case. You have to change the way you sum your background image and the mask array. Check: https://github.com/eugeneteoh/chromakey/blob/main/chromakey/core.py#L40

Priyankaagrawal commented 1 year ago

I have one more more query. Is it possible to start masking where the green-screen start instead of taking full width. It prevents my background image from cropping

eugeneteoh commented 1 year ago

As mentioned above:

If you don't want it to be zoomed in. You have to somehow project your image onto the mask.

I don't think this is easy as what you want is not a linear projection. The mask is almost never a perfect square/rectangle. You have to somehow distort your background image onto project to the mask. Best to ask someone else, as I'm not super familiar with this topic.