Skip to content
Snippets Groups Projects
Commit 75261a6e authored by Laurent COLBOIS's avatar Laurent COLBOIS
Browse files

Changed cropping examples to be directly generated by code

parent ea461fff
No related branches found
No related tags found
1 merge request!119Refactor baseline config helpers
Pipeline #51128 passed
from sklearn.pipeline import make_pipeline from sklearn.pipeline import make_pipeline
from bob.pipelines import wrap from bob.pipelines import wrap
from bob.bio.face.helpers import face_crop_solver from bob.bio.face import helpers
import numpy as np import numpy as np
import logging import logging
...@@ -237,7 +237,7 @@ def make_cropper( ...@@ -237,7 +237,7 @@ def make_cropper(
transform_extra_arguments for wrapping the cropper with a SampleWrapper. transform_extra_arguments for wrapping the cropper with a SampleWrapper.
""" """
face_cropper = face_crop_solver( face_cropper = helpers.face_crop_solver(
cropped_image_size=cropped_image_size, cropped_image_size=cropped_image_size,
cropped_positions=cropped_positions, cropped_positions=cropped_positions,
fixed_positions=fixed_positions, fixed_positions=fixed_positions,
......
...@@ -26,7 +26,7 @@ extensions = [ ...@@ -26,7 +26,7 @@ extensions = [
'sphinx.ext.napoleon', 'sphinx.ext.napoleon',
'sphinx.ext.viewcode', 'sphinx.ext.viewcode',
'sphinx.ext.mathjax', 'sphinx.ext.mathjax',
#'matplotlib.sphinxext.plot_directive' 'matplotlib.sphinxext.plot_directive'
] ]
# Be picky about warnings # Be picky about warnings
......
...@@ -38,35 +38,6 @@ There are currently three available modes : ...@@ -38,35 +38,6 @@ There are currently three available modes :
We present hereafter a visual example of those crops for the `eyes-center` annotation type. We present hereafter a visual example of those crops for the `eyes-center` annotation type.
.. figure:: img/cropping_example_source.png .. plot:: plot/default_crops.py
:height: 250px :include-source: True
:align: left
:alt: Source image
:figclass: align-center
Original face image
.. figure:: img/cropping_example_legacy.png
:height: 250px
:align: right
:alt: Legacy crop
:figclass: align-center
Legacy crop (160 x 128)
.. figure:: img/cropping_example_dnn.png
:height: 250px
:align: left
:alt: DNN crop
:figclass: align-center
DNN crop (160 x 160)
.. figure:: img/cropping_example_pad.png
:height: 250px
:align: right
:alt: PAD crop
:figclass: align-center
PAD crop (160 x 160)
\ No newline at end of file
doc/img/cropping_example_dnn.png

44.1 KiB

doc/img/cropping_example_legacy.png

34.4 KiB

doc/img/cropping_example_pad.png

42.6 KiB

import bob.io.image
from bob.bio.face.helpers import get_default_cropped_positions
from bob.bio.face.preprocessor import FaceCrop
import matplotlib.pyplot as plt
src = bob.io.image.load("../img/cropping_example_source.png")
modes = ["legacy", "dnn", "pad"]
cropped_images = []
SIZE = 160
# Pick cropping mode
for mode in modes:
if mode == "legacy":
cropped_image_size = (SIZE, 4 * SIZE // 5)
else:
cropped_image_size = (SIZE, SIZE)
annotation_type = "eyes-center"
# Load default cropped positions
cropped_positions = get_default_cropped_positions(
mode, cropped_image_size, annotation_type
)
# Instanciate cropper and crop
cropper = FaceCrop(
cropped_image_size=cropped_image_size,
cropped_positions=cropped_positions,
fixed_positions={"reye": (480, 380), "leye": (480, 650)},
color_channel="rgb",
)
cropped_images.append(cropper.transform([src])[0].astype("uint8"))
# Visualize cropped images
fig, axes = plt.subplots(2, 2, figsize=(10, 10))
for i, (img, label) in enumerate(zip([src] + cropped_images, ["original"] + modes)):
ax = axes[i // 2, i % 2]
ax.axis("off")
ax.imshow(bob.io.image.to_matplotlib(img))
ax.set_title(label)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment