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

πŸ› οΈ Ensure images are loaded in RGB format #1866

Merged
merged 2 commits into from
Mar 20, 2024
Merged
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions src/anomalib/data/utils/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def read_image(path: str | Path, as_tensor: bool = False) -> torch.Tensor | np.n
Returns:
image as numpy array
"""
image = Image.open(path)
image = Image.open(path).convert("RGB")
return to_dtype(to_image(image), torch.float32, scale=True) if as_tensor else np.array(image) / 255.0


Expand Down Expand Up @@ -441,7 +441,7 @@ def save_image(filename: Path | str, image: np.ndarray | Figure, root: Path | No
# if file_path is absolute, then root is ignored
# so we remove the top level directory from the path
if file_path.is_absolute() and root:
file_path = Path("/".join(str(file_path).split("/")[2:]))
file_path = Path(*file_path.parts[2:]) # OS-AGNOSTIC
if root:
file_path = root / file_path

Expand Down
Loading