Preprocessors

Image preprocessing tools

class facereclib.preprocessing.FaceCrop(cropped_image_size=None, cropped_positions=None, fixed_positions=None, color_channel='gray', offset=0, supported_annotations=None, mask_sigma=None, mask_neighbors=5, mask_seed=None, **kwargs)[source]

Bases: facereclib.preprocessing.Preprocessor.Preprocessor

Crops the face according to the eye positions

Parameters of the constructor of this preprocessor:

cropped_image_size
The size of the resulting cropped images.
cropped_positions
The coordinates in the cropped image, where the annotated points should be put to. This parameter is a dictionary with usually two elements, e.g., {‘reye’:(RIGHT_EYE_Y, RIGHT_EYE_X) , ‘leye’:(LEFT_EYE_Y, LEFT_EYE_X)}.
fixed_positions
If specified, ignore the annotations from the database and use these fixed positions throughout.
color_channel
In case of color images, which color channel should be used?
offset
An offset for feature extraction; will affect the cropped_image_size and the cropped_image_positions
supported_annotations
A list of supported pairs of annotations. If the database has different names for the annotations, they should be put here (used mainly for testing purposes). If not specified, ((‘reye’, ‘leye’), (‘eye’, ‘mouth’)) is used.
mask_sigma
Fill the area outside of image boundaries with random pixels from the border, by adding noise to the pixel values. To disable extrapolation, set this value to None. To disable adding random noise, set it to a negative value or 0.
mask_neighbors
The number of neighbors used during mask extrapolation. See bob.ip.base.extrapolate_mask() for details.
mask_seed

The random seed to apply for mask extrapolation.

Warning

When run in parallel, the same random seed will be applied to all parallel processes. Hence, results of parallel execution will differ from the results in serial execution.

crop_face(image, annotations)[source]

Executes the face cropping on the given image and returns the cropped version of it

quality()

Returns the quality of the last preprocessed image. This quality term is application dependent. By default, None is returned.

read_data(data_file)

Reads the preprocessed data from file. In this base class implementation, it uses bob.io.base.load to do that. If you have different format, please overwrite this function.

read_original_data(original_file_name)

Reads the original data (usually an image) from file. In this base class implementation, it uses bob.io.base.load to do that. If you have different format, please overwrite this function.

save_data(data, data_file)

Saves the given preprocessed data to a file with the given name. In this base class implementation:

  • If the given data has a save attribute, it calls data.save(bob.io.base.HDF5File(data_file), 'w'). In this case, the given data_file might be either a file name or a bob.io.base.HDF5File.
  • Otherwise, it uses bob.io.base.save to do that.

If you have a different format (e.g. not images), please overwrite this function.

class facereclib.preprocessing.FaceDetector(post_processor='face-crop', use_flandmark=False, cascade=None, detection_overlap=0.2, distance=2, scale_base=0.9576032806985737, lowest_scale=0.125, **kwargs)[source]

Bases: facereclib.preprocessing.NullPreprocessor.NullPreprocessor

Performs a face detection in the given image (ignoring any annotations).

quality()
read_data(filename)
read_original_data(original_file_name)

Reads the original data (usually an image) from file. In this base class implementation, it uses bob.io.base.load to do that. If you have different format, please overwrite this function.

save_data(data, filename)
class facereclib.preprocessing.HistogramEqualization(**kwargs)[source]

Bases: facereclib.preprocessing.FaceCrop.FaceCrop

Crops the face according to the eye positions (if given), and performs histogram equalization on the resulting image

crop_face(image, annotations)

Executes the face cropping on the given image and returns the cropped version of it

equalize_histogram(image)[source]

Calls bob function to do the actual histogram equalization

quality()

Returns the quality of the last preprocessed image. This quality term is application dependent. By default, None is returned.

read_data(data_file)

Reads the preprocessed data from file. In this base class implementation, it uses bob.io.base.load to do that. If you have different format, please overwrite this function.

read_original_data(original_file_name)

Reads the original data (usually an image) from file. In this base class implementation, it uses bob.io.base.load to do that. If you have different format, please overwrite this function.

save_data(data, data_file)

Saves the given preprocessed data to a file with the given name. In this base class implementation:

  • If the given data has a save attribute, it calls data.save(bob.io.base.HDF5File(data_file), 'w'). In this case, the given data_file might be either a file name or a bob.io.base.HDF5File.
  • Otherwise, it uses bob.io.base.save to do that.

If you have a different format (e.g. not images), please overwrite this function.

class facereclib.preprocessing.INormLBP(radius=2, is_uniform=False, is_circular=True, is_rotation_invariant=False, compare_to_average=False, add_average_bit=False, cropped_image_size=None, cropped_positions=None, **kwargs)[source]

Bases: facereclib.preprocessing.FaceCrop.FaceCrop

Crops the face according to the eye positions (if given), and performs I-Norm LBP on the resulting image

crop_face(image, annotations)

Executes the face cropping on the given image and returns the cropped version of it

i_norm(image)[source]

Computes the I-Norm-LBP normalization on the given image

quality()

Returns the quality of the last preprocessed image. This quality term is application dependent. By default, None is returned.

read_data(data_file)

Reads the preprocessed data from file. In this base class implementation, it uses bob.io.base.load to do that. If you have different format, please overwrite this function.

read_original_data(original_file_name)

Reads the original data (usually an image) from file. In this base class implementation, it uses bob.io.base.load to do that. If you have different format, please overwrite this function.

save_data(data, data_file)

Saves the given preprocessed data to a file with the given name. In this base class implementation:

  • If the given data has a save attribute, it calls data.save(bob.io.base.HDF5File(data_file), 'w'). In this case, the given data_file might be either a file name or a bob.io.base.HDF5File.
  • Otherwise, it uses bob.io.base.save to do that.

If you have a different format (e.g. not images), please overwrite this function.

class facereclib.preprocessing.Keypoints(crop_image=False, color_channel='gray', fixed_annotations=None, cropped_domain_annotations=False, relative_annotations=False, use_eye_corners=False, **kwargs)[source]

Bases: facereclib.preprocessing.FaceCrop.FaceCrop

Extracts keypoints (from a possibly normalized/cropped face image)

crop_face(image, annotations)

Executes the face cropping on the given image and returns the cropped version of it

extract_keypoints(image, annotations_arg)[source]

Executes the keypoints extractor

quality()

Returns the quality of the last preprocessed image. This quality term is application dependent. By default, None is returned.

read_data(image_file)[source]
read_original_data(original_file_name)

Reads the original data (usually an image) from file. In this base class implementation, it uses bob.io.base.load to do that. If you have different format, please overwrite this function.

save_data(image, image_file)[source]
class facereclib.preprocessing.NullPreprocessor(color_channel='gray', **kwargs)[source]

Bases: facereclib.preprocessing.Preprocessor.Preprocessor

Skips proprocessing by simply copying the file contents into an hdf5 file (and perform gray scale conversion if required)

quality()

Returns the quality of the last preprocessed image. This quality term is application dependent. By default, None is returned.

read_data(data_file)

Reads the preprocessed data from file. In this base class implementation, it uses bob.io.base.load to do that. If you have different format, please overwrite this function.

read_original_data(original_file_name)

Reads the original data (usually an image) from file. In this base class implementation, it uses bob.io.base.load to do that. If you have different format, please overwrite this function.

save_data(data, data_file)

Saves the given preprocessed data to a file with the given name. In this base class implementation:

  • If the given data has a save attribute, it calls data.save(bob.io.base.HDF5File(data_file), 'w'). In this case, the given data_file might be either a file name or a bob.io.base.HDF5File.
  • Otherwise, it uses bob.io.base.save to do that.

If you have a different format (e.g. not images), please overwrite this function.

class facereclib.preprocessing.Preprocessor(**kwargs)[source]

This is the base class for all preprocessors. It defines the minimum requirements for all derived proprocessor classes.

quality()[source]

Returns the quality of the last preprocessed image. This quality term is application dependent. By default, None is returned.

read_data(data_file)[source]

Reads the preprocessed data from file. In this base class implementation, it uses bob.io.base.load to do that. If you have different format, please overwrite this function.

read_original_data(original_file_name)[source]

Reads the original data (usually an image) from file. In this base class implementation, it uses bob.io.base.load to do that. If you have different format, please overwrite this function.

save_data(data, data_file)[source]

Saves the given preprocessed data to a file with the given name. In this base class implementation:

  • If the given data has a save attribute, it calls data.save(bob.io.base.HDF5File(data_file), 'w'). In this case, the given data_file might be either a file name or a bob.io.base.HDF5File.
  • Otherwise, it uses bob.io.base.save to do that.

If you have a different format (e.g. not images), please overwrite this function.

class facereclib.preprocessing.SelfQuotientImage(sigma=2.0, **kwargs)[source]

Bases: facereclib.preprocessing.FaceCrop.FaceCrop

Crops the face according to the eye positions (if given), computes the self quotient image.

crop_face(image, annotations)

Executes the face cropping on the given image and returns the cropped version of it

quality()

Returns the quality of the last preprocessed image. This quality term is application dependent. By default, None is returned.

read_data(data_file)

Reads the preprocessed data from file. In this base class implementation, it uses bob.io.base.load to do that. If you have different format, please overwrite this function.

read_original_data(original_file_name)

Reads the original data (usually an image) from file. In this base class implementation, it uses bob.io.base.load to do that. If you have different format, please overwrite this function.

save_data(data, data_file)

Saves the given preprocessed data to a file with the given name. In this base class implementation:

  • If the given data has a save attribute, it calls data.save(bob.io.base.HDF5File(data_file), 'w'). In this case, the given data_file might be either a file name or a bob.io.base.HDF5File.
  • Otherwise, it uses bob.io.base.save to do that.

If you have a different format (e.g. not images), please overwrite this function.

self_quotient(image)[source]
class facereclib.preprocessing.TanTriggs(gamma=0.2, sigma0=1, sigma1=2, size=5, threshold=10.0, alpha=0.1, **kwargs)[source]

Bases: facereclib.preprocessing.FaceCrop.FaceCrop

Crops the face (if desired) and applies Tan&Triggs algorithm

Parameters of the constructor of this preprocessor:

gamma, sigma0, sigma1, size, threshold, alpha
Please refer to the [TT10] original paper (see FaceRecLib documentation).
kwargs
The parameters directly passed to the facereclib.preprocessing.FaceCrop base class constructor.
crop_face(image, annotations)

Executes the face cropping on the given image and returns the cropped version of it

quality()

Returns the quality of the last preprocessed image. This quality term is application dependent. By default, None is returned.

read_data(data_file)

Reads the preprocessed data from file. In this base class implementation, it uses bob.io.base.load to do that. If you have different format, please overwrite this function.

read_original_data(original_file_name)

Reads the original data (usually an image) from file. In this base class implementation, it uses bob.io.base.load to do that. If you have different format, please overwrite this function.

save_data(data, data_file)

Saves the given preprocessed data to a file with the given name. In this base class implementation:

  • If the given data has a save attribute, it calls data.save(bob.io.base.HDF5File(data_file), 'w'). In this case, the given data_file might be either a file name or a bob.io.base.HDF5File.
  • Otherwise, it uses bob.io.base.save to do that.

If you have a different format (e.g. not images), please overwrite this function.

tan_triggs(image)[source]

Performs the Tan&Triggs normalization to the given image