Commit 585b481d authored by Amir MOHAMMADI's avatar Amir MOHAMMADI
Browse files

Merge branch 'fix-color-channel' into 'master'

[Preprocessor] Fix color channel

See merge request !75
parents 195e72ae 0dd91782
Pipeline #44978 failed with stages
in 1 minute and 41 seconds
...@@ -60,7 +60,7 @@ class Base(TransformerMixin, BaseEstimator): ...@@ -60,7 +60,7 @@ class Base(TransformerMixin, BaseEstimator):
def fit(self, X, y=None): def fit(self, X, y=None):
return self return self
def color_channel(self, image): def change_color_channel(self, image):
"""color_channel(image) -> channel """color_channel(image) -> channel
Returns the channel of the given image, which was selected in the Returns the channel of the given image, which was selected in the
...@@ -121,5 +121,5 @@ class Base(TransformerMixin, BaseEstimator): ...@@ -121,5 +121,5 @@ class Base(TransformerMixin, BaseEstimator):
def _transform_one_image(self, image): def _transform_one_image(self, image):
assert isinstance(image, numpy.ndarray) and image.ndim in (2, 3) assert isinstance(image, numpy.ndarray) and image.ndim in (2, 3)
# convert to grayscale # convert to grayscale
image = self.color_channel(image) image = self.change_color_channel(image)
return self.data_type(image) return self.data_type(image)
...@@ -337,7 +337,7 @@ class FaceCrop(Base): ...@@ -337,7 +337,7 @@ class FaceCrop(Base):
return None return None
# convert to the desired color channel # convert to the desired color channel
image = self.color_channel(image) image = self.change_color_channel(image)
# annotate the image if annotations are missing # annotate the image if annotations are missing
if ( if (
......
...@@ -94,7 +94,7 @@ class HistogramEqualization(Base): ...@@ -94,7 +94,7 @@ class HistogramEqualization(Base):
""" """
def _crop(image, annotations): def _crop(image, annotations):
image = self.color_channel(image) image = self.change_color_channel(image)
if self.cropper is not None: if self.cropper is not None:
image = self.cropper.transform([image], [annotations])[0] image = self.cropper.transform([image], [annotations])[0]
image = self.equalize_histogram(image) image = self.equalize_histogram(image)
......
...@@ -118,7 +118,7 @@ class INormLBP(Base): ...@@ -118,7 +118,7 @@ class INormLBP(Base):
""" """
def _crop(image, annotations=None): def _crop(image, annotations=None):
image = self.color_channel(image) image = self.change_color_channel(image)
if self.cropper is not None: if self.cropper is not None:
image = self.cropper.transform([image], annotations=[annotations])[0] image = self.cropper.transform([image], annotations=[annotations])[0]
image = self.lbp_extractor(image) image = self.lbp_extractor(image)
......
...@@ -91,7 +91,7 @@ class SelfQuotientImage(Base): ...@@ -91,7 +91,7 @@ class SelfQuotientImage(Base):
The cropped and photometrically enhanced face. The cropped and photometrically enhanced face.
""" """
def _crop(image, annotations): def _crop(image, annotations):
image = self.color_channel(image) image = self.change_color_channel(image)
if self.cropper is not None: if self.cropper is not None:
image = self.cropper.transform([image], [annotations])[0] image = self.cropper.transform([image], [annotations])[0]
image = self.self_quotient(image) image = self.self_quotient(image)
......
...@@ -108,7 +108,7 @@ class TanTriggs(Base): ...@@ -108,7 +108,7 @@ class TanTriggs(Base):
""" """
def _crop(image, annotations=None): def _crop(image, annotations=None):
image = self.color_channel(image) image = self.change_color_channel(image)
if self.cropper is not None: if self.cropper is not None:
image = self.cropper.transform([image], [annotations])[0] image = self.cropper.transform([image], [annotations])[0]
image = self.tan_triggs(image) image = self.tan_triggs(image)
......
...@@ -79,7 +79,7 @@ def test_base(): ...@@ -79,7 +79,7 @@ def test_base():
# read input # read input
image = _image() image = _image()
preprocessed = base.transform(image) preprocessed = base.transform([image])[0]
assert preprocessed.ndim == 2 assert preprocessed.ndim == 2
assert preprocessed.dtype == numpy.float64 assert preprocessed.dtype == numpy.float64
...@@ -87,7 +87,7 @@ def test_base(): ...@@ -87,7 +87,7 @@ def test_base():
# color output # color output
base = bob.bio.face.preprocessor.Base(color_channel="rgb", dtype=numpy.uint8) base = bob.bio.face.preprocessor.Base(color_channel="rgb", dtype=numpy.uint8)
colored = base.transform(bob.ip.color.rgb_to_gray(image)) colored = base.transform([bob.ip.color.rgb_to_gray(image)])[0]
assert colored.ndim == 3 assert colored.ndim == 3
assert colored.dtype == numpy.uint8 assert colored.dtype == numpy.uint8
...@@ -95,7 +95,7 @@ def test_base(): ...@@ -95,7 +95,7 @@ def test_base():
numpy.allclose(colored[c], bob.ip.color.rgb_to_gray(image)) for c in range(3) numpy.allclose(colored[c], bob.ip.color.rgb_to_gray(image)) for c in range(3)
) )
colored = base.transform(image) colored = base.transform([image])[0]
assert colored.ndim == 3 assert colored.ndim == 3
assert colored.dtype == numpy.uint8 assert colored.dtype == numpy.uint8
assert numpy.all(colored == image) assert numpy.all(colored == image)
...@@ -131,7 +131,7 @@ def test_face_crop(): ...@@ -131,7 +131,7 @@ def test_face_crop():
_compare(fixed_cropper.transform([image]), reference) _compare(fixed_cropper.transform([image]), reference)
# check color cropping # check color cropping
cropper.channel = "rgb" cropper.color_channel = "rgb"
cropped = cropper.transform([image], [annotation])[0] cropped = cropper.transform([image], [annotation])[0]
assert cropped.ndim == 3 assert cropped.ndim == 3
assert cropped.shape[0] == 3 assert cropped.shape[0] == 3
...@@ -149,7 +149,7 @@ def test_face_crop(): ...@@ -149,7 +149,7 @@ def test_face_crop():
pass pass
# reset the configuration, so that later tests don't get screwed. # reset the configuration, so that later tests don't get screwed.
cropper.channel = "gray" cropper.color_channel = "gray"
def test_tan_triggs(): def test_tan_triggs():
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment