Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.

Make a directory for chainercv.utils.image #421

Merged
merged 1 commit into from
Sep 14, 2017
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions chainercv/utils/image/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from chainercv.utils.image.read_image import read_image # NOQA
from chainercv.utils.image.write_image import write_image # NOQA
21 changes: 0 additions & 21 deletions chainercv/utils/image.py → chainercv/utils/image/read_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,3 @@ def read_image(path, dtype=np.float32, color=True):
else:
# transpose (H, W, C) -> (C, H, W)
return img.transpose((2, 0, 1))


def write_image(img, path):
"""Save an image to a file.

This function saves an image to given file. The image is in CHW format and
the range of its value is :math:`[0, 255]`.

Args:
image (~numpy.ndarray): An image to be saved.
path (str): The path of an image file.

"""

if img.shape[0] == 1:
img = img[0]
else:
img = img.transpose((1, 2, 0))

img = Image.fromarray(img.astype(np.uint8))
img.save(path)
23 changes: 23 additions & 0 deletions chainercv/utils/image/write_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import numpy as np
from PIL import Image


def write_image(img, path):
"""Save an image to a file.

This function saves an image to given file. The image is in CHW format and
the range of its value is :math:`[0, 255]`.

Args:
image (~numpy.ndarray): An image to be saved.
path (str): The path of an image file.

"""

if img.shape[0] == 1:
img = img[0]
else:
img = img.transpose((1, 2, 0))

img = Image.fromarray(img.astype(np.uint8))
img.save(path)