Skip to content

Commit

Permalink
hyperfocal: img_proc.py: Fixed opening images without alpha with open…
Browse files Browse the repository at this point in the history
…_image_with_alpha()

Before open_image_with_alpha() would crash when opening images without an alpha channel, in particular jpegs

Now if the opened image does not have an alpha channel, a fully opaque alpha layer will be assumed
  • Loading branch information
okawo80085 committed Oct 18, 2021
1 parent 9470c7d commit 94cc5e6
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions hyperfocal/img_proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,12 @@ def process_preview(
def open_image_with_alpha(path: str) -> Tuple[np.ndarray, np.ndarray]:
img = cv2.imread(path, cv2.IMREAD_UNCHANGED)

img_alpha = img[:, :, 3]
img_rgb = img[:, :, :3]
return (img_rgb, img_alpha / 255)
if len(img.shape) == 3 and img.shape[2] == 4:
img_alpha = img[:, :, 3]
img_rgb = img[:, :, :3]
return (img_rgb, img_alpha / 255)

return img, np.ones(img.shape[:2], dtype=np.float32)


def process_photo(img: np.ndarray, config: Dict[str, setting]) -> np.ndarray:
Expand Down

0 comments on commit 94cc5e6

Please sign in to comment.