Skip to content
Snippets Groups Projects
Commit 58e9db93 authored by Amir MOHAMMADI's avatar Amir MOHAMMADI
Browse files

Merge branch 'base' into 'master'

Base preprocessor accept **kwargs

See merge request !27
parents 0c57b664 2a82f3ef
No related branches found
No related tags found
1 merge request!27Base preprocessor accept **kwargs
Pipeline #
...@@ -4,8 +4,10 @@ import bob.ip.color ...@@ -4,8 +4,10 @@ import bob.ip.color
from bob.bio.base.preprocessor import Preprocessor from bob.bio.base.preprocessor import Preprocessor
class Base (Preprocessor): class Base (Preprocessor):
"""Performs color space adaptations and data type corrections for the given image. """Performs color space adaptations and data type corrections for the given
image.
**Parameters:** **Parameters:**
...@@ -16,17 +18,17 @@ class Base (Preprocessor): ...@@ -16,17 +18,17 @@ class Base (Preprocessor):
The specific color channel, which should be extracted from the image. The specific color channel, which should be extracted from the image.
""" """
def __init__(self, dtype = None, color_channel = 'gray'): def __init__(self, dtype=None, color_channel='gray', **kwargs):
Preprocessor.__init__(self, dtype=str(dtype), color_channel=color_channel) Preprocessor.__init__(self, dtype=str(dtype),
color_channel=color_channel, **kwargs)
self.channel = color_channel self.channel = color_channel
self.dtype = dtype self.dtype = dtype
def color_channel(self, image): def color_channel(self, image):
"""color_channel(image) -> channel """color_channel(image) -> channel
Returns the channel of the given image, which was selected in the constructor. Returns the channel of the given image, which was selected in the
Currently, gray, red, green and blue channels are supported. constructor. Currently, gray, red, green and blue channels are supported.
**Parameters:** **Parameters:**
...@@ -42,7 +44,8 @@ class Base (Preprocessor): ...@@ -42,7 +44,8 @@ class Base (Preprocessor):
if self.channel == 'rgb': if self.channel == 'rgb':
return bob.ip.color.gray_to_rgb(image) return bob.ip.color.gray_to_rgb(image)
if self.channel != 'gray': if self.channel != 'gray':
raise ValueError("There is no rule to extract a " + channel + " image from a gray level image!") raise ValueError("There is no rule to extract a " +
self.channel + " image from a gray level image!")
return image return image
if self.channel == 'rgb': if self.channel == 'rgb':
...@@ -56,14 +59,16 @@ class Base (Preprocessor): ...@@ -56,14 +59,16 @@ class Base (Preprocessor):
if self.channel == 'blue': if self.channel == 'blue':
return image[2, :, :] return image[2, :, :]
raise ValueError("The image channel '%s' is not known or not yet implemented", self.channel) raise ValueError(
"The image channel '%s' is not known or not yet implemented",
self.channel)
def data_type(self, image): def data_type(self, image):
"""data_type(image) -> image """data_type(image) -> image
Converts the given image into the data type specified in the constructor of this class. Converts the given image into the data type specified in the constructor of
If no data type was specified, or the ``image`` is ``None``, no conversion is performed. this class. If no data type was specified, or the ``image`` is ``None``, no
conversion is performed.
**Parameters:** **Parameters:**
...@@ -79,7 +84,6 @@ class Base (Preprocessor): ...@@ -79,7 +84,6 @@ class Base (Preprocessor):
image = image.astype(self.dtype) image = image.astype(self.dtype)
return image return image
def __call__(self, image, annotations=None): def __call__(self, image, annotations=None):
"""__call__(image, annotations = None) -> image """__call__(image, annotations = None) -> image
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment