-
-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
085ce27
commit ac77a7c
Showing
5 changed files
with
92 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# -*- coding: utf-8 -*- | ||
# imageio is distributed under the terms of the (new) BSD License. | ||
|
||
""" Read/Write images using rawpy. | ||
rawpy is an easy-to-use Python wrapper for the LibRaw library. | ||
It also contains some extra functionality for finding and repairing hot/dead pixels. | ||
""" | ||
|
||
import rawpy | ||
import numpy as np | ||
|
||
from ..core.request import URI_BYTES, InitializationError, IOMode, Request | ||
from ..core.v3_plugin_api import PluginV3 | ||
|
||
|
||
class RawPyPlugin(PluginV3): | ||
"""A class representing the rawpy plugin. | ||
This class is a subclass of PluginV3. | ||
Methods | ||
------- | ||
.. autosummary:: | ||
:toctree: _plugins/rawpy | ||
RawPyPlugin.read | ||
""" | ||
def __init__(self, request: Request) -> None: | ||
"""Instantiates a new rawpy plugin object | ||
parameters | ||
---------- | ||
request: {Request} | ||
A request object representing the resource to be operated on. | ||
""" | ||
|
||
super().__init__(request) | ||
|
||
self._image: rawpy = None | ||
self._image_file = request.get_file() | ||
|
||
def read(self, *, index: int = 0) -> np.ndarray: | ||
"""Read Raw Image. | ||
Returns | ||
------- | ||
image: ndimage | ||
The image data | ||
""" | ||
|
||
if self._request.mode.io_mode == IOMode.read: | ||
try: | ||
with rawpy.imread(self._image_file) as raw_image: | ||
self._image = raw_image.raw_image | ||
except (AttributeError, TypeError, rawpy.LibRawIOError) as ex: | ||
print(ex) | ||
except (rawpy.NotSupportedError, rawpy.LibRawError, rawpy.LibRawFatalError, rawpy.LibRawNonFatalError) as ex: | ||
print(ex) | ||
except Exception as ex: | ||
print(ex) | ||
else: | ||
print("Read is not supported!") | ||
|
||
return np.asarray(self._image) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
"""Tests for rawpy plugin | ||
""" | ||
|
||
import os | ||
import rawpy | ||
import imageio.v3 as iio | ||
|
||
|
||
def test_nef_local(test_images): | ||
"""Test for reading .nef file from .test_images dir. | ||
""" | ||
# Check image path | ||
im_path = str(test_images / "Nikon.nef") | ||
assert os.path.exists(im_path) | ||
|
||
# Test if plugin's content mathces rawpy content | ||
im_plugin = iio.imread(im_path) | ||
im_rawpy = rawpy.imread(im_path) | ||
assert im_plugin.all() == im_rawpy.raw_image.all() | ||
|