Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added fix for image orientation #441

Merged
merged 1 commit into from
May 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion rembg/bg.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
getStructuringElement,
morphologyEx,
)
from PIL import Image
from PIL import Image, ImageOps
from PIL.Image import Image as PILImage
from pymatting.alpha.estimate_alpha_cf import estimate_alpha_cf
from pymatting.foreground.estimate_foreground_ml import estimate_foreground_ml
Expand Down Expand Up @@ -113,6 +113,10 @@ def apply_background_color(img: PILImage, color: Tuple[int, int, int, int]) -> P
return colored_image


def fix_image_orientation(img: PILImage) -> PILImage:
return ImageOps.exif_transpose(img)


def remove(
data: Union[bytes, PILImage, np.ndarray],
alpha_matting: bool = False,
Expand All @@ -138,6 +142,9 @@ def remove(
else:
raise ValueError("Input type {} is not supported.".format(type(data)))

# Fix image orientation
img = fix_image_orientation(img)

if session is None:
session = new_session("u2net", *args, **kwargs)

Expand Down