Skip to content

Commit

Permalink
Added jp2 image support
Browse files Browse the repository at this point in the history
  • Loading branch information
BloodAxe committed Jan 1, 2024
1 parent 6556bc8 commit 63639ac
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions pytorch_toolbelt/utils/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import glob
import os
from pathlib import Path
from typing import Union, List
from typing import Union, List, Iterable

import cv2
import numpy as np
Expand All @@ -26,11 +26,11 @@
"read_rgb_image",
]

COMMON_IMAGE_EXTENSIONS = [".bmp", ".png", ".jpeg", ".jpg", ".tiff", ".tif"]
COMMON_IMAGE_EXTENSIONS = (".bmp", ".png", ".jpeg", ".jpg", ".tiff", ".tif", ".jp2")


def has_ext(fname: str, extensions: Union[str, List[str]]) -> bool:
if not isinstance(extensions, (str, list)):
def has_ext(fname: str, extensions: Union[str, Iterable[str]]) -> bool:
if not isinstance(extensions, (str, list, tuple)):
raise ValueError("Argument extensions must be either string or list of strings")
if isinstance(extensions, str):
extensions = [extensions]
Expand All @@ -45,6 +45,9 @@ def has_image_ext(fname: str) -> bool:


def find_in_dir(dirname: str) -> List[str]:
if not os.path.isdir(dirname):
raise FileNotFoundError(f"Directory {dirname} not found")

return [os.path.join(dirname, fname) for fname in sorted(os.listdir(dirname))]


Expand Down

0 comments on commit 63639ac

Please sign in to comment.