Commit b2843c75 authored by Tiago de Freitas Pereira's avatar Tiago de Freitas Pereira
Browse files

Merge branch 'fixes' into 'master'

Fixed Scaler and preprocessors that use annotations

See merge request !76
parents 585b481d d8ad7aab
Pipeline #45024 failed with stages
in 1 minute and 36 seconds
......@@ -96,7 +96,12 @@ class HistogramEqualization(Base):
def _crop(image, annotations):
image = self.change_color_channel(image)
if self.cropper is not None:
image = self.cropper.transform([image], [annotations])[0]
# TODO: USE THE TAG `ALLOW_ANNOTATIONS`
image = (
self.cropper.transform([image])[0]
if annotations is None
else self.cropper.transform([image], [annotations])[0]
)
image = self.equalize_histogram(image)
return self.data_type(image)
......
......@@ -25,6 +25,7 @@ from .utils import load_cropper
from sklearn.utils import check_array
from bob.pipelines.sample import SampleBatch
class INormLBP(Base):
"""Performs I-Norm LBP on the given image"""
......@@ -120,10 +121,15 @@ class INormLBP(Base):
def _crop(image, annotations=None):
image = self.change_color_channel(image)
if self.cropper is not None:
image = self.cropper.transform([image], annotations=[annotations])[0]
# TODO: USE THE TAG `ALLOW_ANNOTATIONS`
image = (
self.cropper.transform([image])[0]
if annotations is None
else self.cropper.transform([image], [annotations])[0]
)
image = self.lbp_extractor(image)
return self.data_type(image)
if annotations is None:
return [_crop(data) for data in X]
else:
......
......@@ -27,7 +27,7 @@ def scale(images, target_img_size):
# images are always batched
output_shape = tuple(target_img_size)
output_shape = tuple(images.shape[0:1]) + output_shape
output_shape = tuple(images.shape[-1:-2]) + output_shape
images = resize(images, output_shape=output_shape)
return to_bob(images)
......
......@@ -25,6 +25,7 @@ from .Base import Base
from .utils import load_cropper
from bob.pipelines.sample import SampleBatch
class SelfQuotientImage(Base):
"""Crops the face (if desired) and applies self quotient image algorithm [WLW04]_ to photometrically enhance the image.
......@@ -49,9 +50,8 @@ class SelfQuotientImage(Base):
Base.__init__(self, **kwargs)
# call base class constructor with its set of parameters
self.face_cropper=face_cropper
self.sigma=sigma
self.face_cropper = face_cropper
self.sigma = sigma
self.cropper = load_cropper(face_cropper)
......@@ -90,10 +90,16 @@ class SelfQuotientImage(Base):
face : 2D :py:class:`numpy.ndarray`
The cropped and photometrically enhanced face.
"""
def _crop(image, annotations):
image = self.change_color_channel(image)
if self.cropper is not None:
image = self.cropper.transform([image], [annotations])[0]
# TODO: USE THE TAG `ALLOW_ANNOTATIONS`
image = (
self.cropper.transform([image])[0]
if annotations is None
else self.cropper.transform([image], [annotations])[0]
)
image = self.self_quotient(image)
return self.data_type(image)
......
......@@ -24,6 +24,7 @@ from .Base import Base
from .utils import load_cropper
from bob.pipelines.sample import SampleBatch
class TanTriggs(Base):
"""Crops the face (if desired) and applies Tan&Triggs algorithm [TT10]_ to photometrically enhance the image.
......@@ -110,9 +111,13 @@ class TanTriggs(Base):
def _crop(image, annotations=None):
image = self.change_color_channel(image)
if self.cropper is not None:
image = self.cropper.transform([image], [annotations])[0]
# TODO: USE THE TAG `ALLOW_ANNOTATIONS`
image = (
self.cropper.transform([image])[0]
if annotations is None
else self.cropper.transform([image], [annotations])[0]
)
image = self.tan_triggs(image)
return self.data_type(image)
if annotations is None:
......@@ -120,7 +125,6 @@ class TanTriggs(Base):
else:
return [_crop(data, annot) for data, annot in zip(X, annotations)]
def __getstate__(self):
d = dict(self.__dict__)
d.pop("tan_triggs")
......
......@@ -79,14 +79,13 @@ def test_gabor_graph():
fake_sample = get_fake_sample()
transformed_sample = transformer.transform([fake_sample])[0]
transformed_data = transformed_sample.data
assert len(transformed_sample.data) == 400
assert len(transformed_sample.data) == 80
def test_lgbphs():
transformer = load_resource("lgbphs", "transformer")
fake_sample = get_fake_sample()
transformed_sample = transformer.transform([fake_sample])[0]
transformed_data = transformed_sample.data
assert transformed_sample.data.shape == (2, 220267)
assert transformed_sample.data.shape == (2, 44014)
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