Skip to content

Commit

Permalink
Update docstring for imgviz.io.XXX
Browse files Browse the repository at this point in the history
  • Loading branch information
wkentaro committed Jan 21, 2020
1 parent a922836 commit e366b52
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 4 deletions.
23 changes: 20 additions & 3 deletions imgviz/_io/_pyglet.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,37 @@ def check_pyglet_available():


def pyglet_run():
'''Start pyglet mainloop.'''
check_pyglet_available()

return pyglet.app.run()


def pyglet_imshow(image, caption=None, **kwargs):
def pyglet_imshow(image, caption=None, interval=0.5):
'''Show image with pyglet.
Parameters
----------
image: numpy.ndarray or list of numpy.ndarray or iterator of numpy.array
Image or images to show.
caption: str
Caption for pyglet window.
interval: float, optional
Interval for list or iterator of images. Default is 0.5.
Returns
-------
None
'''
check_pyglet_available()

if isinstance(image, types.GeneratorType):
_pyglet_imshow_generator(image, caption=caption, **kwargs)
_pyglet_imshow_generator(image, caption=caption, interval=interval)
elif isinstance(image, np.ndarray):
_pyglet_imshow_ndarray(image, caption=caption)
else:
_pyglet_imshow_list(image, caption=caption, **kwargs)
_pyglet_imshow_list(image, caption=caption, interval=interval)


def _pyglet_imshow_list(images, caption, interval=0.5):
Expand Down
26 changes: 26 additions & 0 deletions imgviz/_io/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,36 @@


def imread(filename):
'''Read image from file.
Parameters
----------
filename: str
Filename.
Returns
-------
img: numpy.ndarray, (H, W) or (H, W, 3) or (H, W, 4)
Image read.
'''
# type: (str) -> np.ndarray
return np.asarray(PIL.Image.open(filename))


def imsave(filename, arr):
'''Save image to file.
Parameters
----------
filename: str
Filename.
arr: numpy.ndarray, (H, W) or (H, W, 3) or (H, W, 4)
Image to save.
Returns
-------
None
'''
# type: (str, np.ndarray) -> None
return PIL.Image.fromarray(arr).save(filename)
25 changes: 25 additions & 0 deletions imgviz/_io/opencv.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,37 @@ def check_cv2_available():


def cv_imshow(image, window_name=''):
'''Show image with OpenCV.
Parameters
----------
image: numpy.ndarray
Image.
Returns
-------
None
'''
check_cv2_available()

return cv2.imshow(window_name, image[:, :, ::-1])


def cv_waitkey(msec=0):
'''Wait key for the OpenCV window.
Parameters
----------
msec: float
Miliseconds to wait.
Return
-------
keycode: int
Key code (e.g., ord('q')).
'''
check_cv2_available()

return cv2.waitKey(msec)
14 changes: 13 additions & 1 deletion imgviz/_io/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@


def pyplot_to_numpy():
'''Convert pyplot state to numpy array.
Parameters
----------
Returns
-------
arr: numpy.ndarray
Plotted image.
'''
f = io.BytesIO()
plt.savefig(
f,
Expand All @@ -16,4 +27,5 @@ def pyplot_to_numpy():
)
plt.close()
f.seek(0)
return np.asarray(PIL.Image.open(f))
arr = np.asarray(PIL.Image.open(f))
return arr

0 comments on commit e366b52

Please sign in to comment.