shapedata - A Library to modify images and the corresponding landmarks¶
ShapeData¶
The ShapeData Package provides methods to transform images and the corrisponding landmarks in a similar way.
AbstractSingleImage¶
-
class
AbstractSingleImage
[source]¶ Bases:
object
Abstract Class to define a SingleImage-API
-
_crop
(*args, **kwargs)[source]¶ Internal implementation of
AbstractSingleImage.crop()
Parameters: - *args – positional arguments
- **kwargs – keyword arguments
Raises: NotImplementedError
– if not overwritten by subclass
-
_crop_lmks
(*args, **kwargs)[source]¶ Crops the landmarks
Parameters: - *args – positional arguments
- **kwargs – keyword arguments
Raises: NotImplementedError
– if not overwritten by subclass
-
_crop_to_landmarks
(*args, **kwargs)[source]¶ Internal implementation of
AbstractSingleImage.crop_to_landmarks()
Parameters: - *args – positional arguments
- **kwargs – keyword arguments
Raises: NotImplementedError
– if not overwritten by subclass
-
_normalize_rotation
(*args, **kwargs)[source]¶ Internal implementation of
AbstractSingleImage.normalize_rotation()
Parameters: - *args – positional arguments
- **kwargs – keyword arguments
Raises: NotImplementedError
– if not overwritten by subclass
-
_save_landmarks
(*args, **kwargs)[source]¶ Abstract internal Function to save landmarks
Parameters: - *args – positional arguments
- **kwargs – keyword arguments
Raises: NotImplementedError
– if not overwritten by subclass
-
_transform_img
(*args, **kwargs)[source]¶ Applies a given transformation to image
Parameters: - *args – positional arguments
- **kwargs – keyword arguments
Raises: NotImplementedError
– if not overwritten by subclass
-
_transform_lmk
(*args, **kwargs)[source]¶ Applies a given transformation to landmarks
Parameters: - *args – positional arguments
- **kwargs – keyword arguments
Raises: NotImplementedError
– if not overwritten by subclass
-
apply_trafo
(*args, **kwargs)[source]¶ Applies a given transformation to image and landmarks
Parameters: - *args – positional arguments
- **kwargs – keyword arguments
Raises: NotImplementedError
– if not overwritten by subclass
-
cartesian_coordinates
()[source]¶ Transforms the landmarks into cartesian coordinates
Raises: NotImplementedError
– if not overwritten by subclass
-
crop
(*args, **kwargs)[source]¶ Crops image and landmarks to given range
Parameters: - *args – positional arguments
- **kwargs – keyword arguments
Raises: NotImplementedError
– if not overwritten by subclass
-
crop_to_landmarks
(*args, **kwargs)[source]¶ Crops image and landmarks to bounding box specified by landmarks
Parameters: - *args – positional arguments
- **kwargs – keyword arguments
Raises: NotImplementedError
– if not overwritten by subclass
-
classmethod
from_files
(*args, **kwargs)[source]¶ Creates a class instance from files
Parameters: - *args – positional arguments
- **kwargs – keyword arguments
Raises:
-
get_landmark_bounds
(*args, **kwargs)[source]¶ Calculates bounds of landmarks
Parameters: - *args – positional arguments
- **kwargs – keyword arguments
Raises: NotImplementedError
– if not overwritten by subclass
-
homogeneous_coordinates
()[source]¶ Transforms the landmarks into homogeneous coordinates
Raises: NotImplementedError
– if not overwritten by subclass
-
img
¶ Property to get the actual image pixels
Returns: image pixels Return type: np.array
-
is_gray
¶ Property returning whether the image is a grayscale image
Raises: NotImplementedError
– if not overwritten by subclass
-
is_homogeneous
¶ Property returning whether the landmarks are in homogeneous coordinates
Raises: NotImplementedError
– if not overwritten by subclass
-
normalize_rotation
(*args, **kwargs)[source]¶ Rotates image and landmarks in a way, that the vector between two given points is parallel to horizontal axis
Parameters: - *args – positional arguments
- **kwargs – keyword arguments
Raises: NotImplementedError
– if not overwritten by subclass
-
rescale
(*args, **kwargs)[source]¶ Rescales image and landmarks
Parameters: - *args – positional arguments
- **kwargs – keyword arguments
Raises: NotImplementedError
– if not overwritten by subclass
-
resize
(*args, **kwargs)[source]¶ Resizes image and landmarks
Parameters: - *args – positional arguments
- **kwargs – keyword arguments
Raises: NotImplementedError
– if not overwritten by subclass
-
rotate
(*args, **kwargs)[source]¶ Rotates image and landmarks
Parameters: - *args – positional arguments
- **kwargs – keyword arguments
Raises: NotImplementedError
– if not overwritten by subclass
-
save
(*args, **kwargs)[source]¶ Abstract Function to save image and landmarks
Parameters: - *args – positional arguments
- **kwargs – keyword arguments
Raises: NotImplementedError
– if not overwritten by subclass
-
save_image
(*args, **kwargs)[source]¶ Abstract Function to save image
Parameters: - *args – positional arguments
- **kwargs – keyword arguments
Raises: NotImplementedError
– if not overwritten by subclass
-
save_landmarks
(*args, **kwargs)[source]¶ Abstract Function to save landmarks
Parameters: - *args – positional arguments
- **kwargs – keyword arguments
Raises: NotImplementedError
– if not overwritten by subclass
-
to_grayscale
()[source]¶ Converts image to grayscale
Raises: NotImplementedError
– if not overwritten by subclass
-
transform
(*args, **kwargs)[source]¶ Applies a given transformation to image and landmarks
Parameters: - *args – positional arguments
- **kwargs – keyword arguments
Raises: NotImplementedError
– if not overwritten by subclass
-
transform_about_centre
(*args, **kwargs)[source]¶ Applies a given transformation to image and landmarks at image center (internally shifts image and landmarks center to origin, applies transformation and shifts back)
Parameters: - *args – positional arguments
- **kwargs – keyword arguments
Raises: NotImplementedError
– if not overwritten by subclass
-
translate
(*args, **kwargs)[source]¶ Translates image and landmarks
Parameters: - *args – positional arguments
- **kwargs – keyword arguments
Raises: NotImplementedError
– if not overwritten by subclass
-
view
(*args, **kwargs)[source]¶ Plots image and landmarks
Parameters: - *args – positional arguments
- **kwargs – keyword arguments
Raises: NotImplementedError
– if not overwritten by subclass
-
BaseSingleImage¶
-
class
BaseSingleImage
(img: <sphinx.ext.autodoc.importer._MockObject object at 0x7f5a875c5eb8>, *args, **kwargs)[source]¶ Bases:
shapedata.base_data_processing.AbstractSingleImage
Holds Single Image
-
_crop
(min_y, min_x, max_y, max_x)[source]¶ Implements actual cropping inplace
Parameters: Raises: NotImplementedError
– if not overwritten by subclass
-
static
_crop_lmks
(lmks, min_y, min_x, max_y, max_x)[source]¶ Crops landmarks to given values
Parameters: Returns: cropped landmarks
Return type: np.ndarray
-
_crop_to_landmarks
(proportion=0.0, **kwargs)[source]¶ Crop to landmarks inplace
Parameters: - proportion (float) – boundary proportion of cropping
- **kwargs – additional keyword arguments
Raises: NotImplementedError
– if not overwritten by subclass
-
_normalize_rotation
(lmks, index_left, index_right, **kwargs)[source]¶ normalizes rotation based on two keypoints
Parameters: Returns: transformed Image
Return type:
-
_save_landmarks
(filepath, lmk_type, **kwargs)[source]¶ Saves landmarks to file
Parameters: Raises: NotImplementedError
– If not overwritten by subclass
-
_transform_img
(transformation: <sphinx.ext.autodoc.importer._MockObject object at 0x7f5a875c5be0>, **kwargs)[source]¶ Apply transformation inplace to image
Parameters: - transformation (
skimage.transform.AffineTransform
) – transformation to apply - **kwargs – additional keyword arguments
Returns: Transformed Image with original Landmarks
Return type: - transformation (
-
_transform_lmk
(transformation: <sphinx.ext.autodoc.importer._MockObject object at 0x7f5a875c5be0>)[source]¶ Apply transformation inplace to landmarks
Parameters: transformation ( skimage.transform.AffineTransform
) – transformation to applyReturns: Image with Transformed Landmarks Return type: BaseSingleImage
-
apply_trafo
(transformation: <sphinx.ext.autodoc.importer._MockObject object at 0x7f5a875c5be0>, **kwargs)[source]¶ Apply transformation inplace to image and landmarks
Parameters: - transformation (
skimage.transform.AffineTransform
) – transformation to apply - **kwargs – additional keyword arguments
Returns: Transformed Image and Landmarks
Return type: - transformation (
-
cartesian_coordinates
()[source]¶ Transforms landmark coordinates inplace to cartesian coordinates
Returns: Image with Landmarks in cartesian Coordinates Return type: BaseSingleImage
-
crop
(min_y, min_x, max_y, max_x)[source]¶ Crops Image by specified values
Parameters: Returns: cropped image
Return type:
-
crop_to_landmarks
(proportion=0.0, **kwargs)[source]¶ Crop image to landmarks
Parameters: - proportion (float) – image proportion to add to size of bounding box
- **kwargs – additional keyword arguments
Returns: cropped image
Return type:
-
classmethod
from_files
(file, extension=None, **kwargs)[source]¶ Creates a class instance from files
Parameters: - *args – positional arguments
- **kwargs – keyword arguments
Raises:
-
classmethod
from_ljson_files
(img_file, **kwargs)[source]¶ Create class from image or landmark file
Parameters: file (str) – path to image or landmarkfile Returns: Return type: BaseSingleImage
-
classmethod
from_npy_files
(file, **kwargs)[source]¶ Create class from image or landmark file
Parameters: file (str) – path to image or landmarkfile Returns: Return type: BaseSingleImage
-
classmethod
from_pts_files
(file, **kwargs)[source]¶ Create class from image or landmark file :param file: path to image or landmarkfile :type file: string
Returns: Return type: BaseSingleImage
-
static
get_landmark_bounds
(lmks)[source]¶ Function to calculate the landmark bounds
Parameters: lmks (np.ndarray) – landmarks Returns: - int (min_y)
- int (min_x)
- int (max_y)
- int (max_x)
-
homogeneous_coordinates
()[source]¶ Transforms landmark coordinates inplace to homogeneous coordinates
Returns: Image with Landmarks in Homogeneous Coordinates Return type: BaseSingleImage
-
img
¶ Property to get the actual image pixels
Returns: image pixels Return type: np.array
-
is_gray
¶ Property returning whether the image is a grayscale image
Raises: NotImplementedError
– if not overwritten by subclass
-
is_homogeneous
¶ Property returning whether the landmarks are in homogeneous coordinates
Raises: NotImplementedError
– if not overwritten by subclass
-
normalize_rotation
(*args, **kwargs)[source]¶ Rotates image and landmarks in a way, that the vector between two given points is parallel to horizontal axis
Parameters: - *args – positional arguments
- **kwargs – keyword arguments
Raises: NotImplementedError
– if not overwritten by subclass
-
rescale
(scale, **kwargs)[source]¶ Scale Image and landmarks
Parameters: - scale – scale parameter
- **kwargs – additional keyword arguments (passed to
skimage.transform.warp()
)
Returns: transformed Image
Return type:
-
resize
(target_shape, **kwargs)[source]¶ resize image and scale landmarks :param target_shape: target shape for resizing :type target_shape: tuple or list :param **kwargs: additional keyword arguments (passed to
skimage.transform.warp()
)Returns: transformed Image Return type: BaseSingleImage
-
rotate
(angle, degree=True, **kwargs)[source]¶ Rotates the image and landmarks by given angle
Parameters: Returns: transformed Image
Return type:
-
save
(directory, filename, lmk_type='LJSON', **kwargs)[source]¶ Saves Image and optionally landmarks to files
Parameters: - directory (str) – string containing the directory to save
- filename (str) – string containing the filename (without the extension)
- lmk_type (str or None) – if None: no landmarks will be saved if str: specifies type of landmark file
- **kwargs – additional keyword arguments passed to save function for landmarks
-
save_image
(filepath)[source]¶ Saves Image to file
Parameters: filepath (str) – file to save the image to
-
to_grayscale
()[source]¶ Convert Image to grayscale
Returns: Grayscale Image Return type: BaseSingleImage
-
transform
(transform=None, rotation=None, scale=None, translation=None, shear=None, trafo_matrix=None, return_matrix=False, **kwargs)[source]¶ transform image and landmarks by parameters or transformation matrix See
skimage.transform.AffineTransform
for a detailed parameter explanationParameters: - transform (
skimage.transform.AffineTransform
) – if transform is specified it overwrites all other arguments - rotation (float or None) – rotation angle in radiant
- scale (float or None) – scale value
- translation – translation params
- shear – shear params
- trafo_matrix – transformation matrix
- return_matrix (bool) – whether to return the transformation matrix along the transformed object
- **kwargs – additional keyword arguments
Returns: BaseSingleImage
– transformed Image- [optional] np.ndarray – transformation matrix
- transform (
-
transform_about_centre
(transform=None, rotation=None, scale=None, translation=None, shear=None, trafo_matrix=None, return_matrix=False, **kwargs)[source]¶ Perform transformations about the image center. (internally shifting image to origin, perform transformation and shift it back)
Parameters: - transform (
skimage.transform.AffineTransform
) – if transform is specified it overwrites all other arguments - rotation (float) – rotation angle in radiant
- scale (float) – scale value
- translation – translation params
- shear – shear params
- trafo_matrix – transformation matrix
- return_matrix (bool) – whether to return the transformation matrix along the transformed object
- **kwargs – additional keyword arguments
Returns: BaseSingleImage
– transformed Image- [optional] np.ndarray – transformation matrix
- transform (
-
translate
(translation, relative=False, **kwargs)[source]¶ translates image and landmarks
- translation :
- translation parameters
- relative : bool
- whether translation parameters are relative to image size
- **kwargs :
- additional keyword arguments (passed to
skimage.transform.warp()
)BaseSingleImage
- transformed Image
-
view
(*args, **kwargs)[source]¶ Plots image and landmarks
Parameters: - *args – positional arguments
- **kwargs – keyword arguments
Raises: NotImplementedError
– if not overwritten by subclass
-
Single Shape¶
The single_shape
subpackage implements dataprocessing and
image-landmark-transformations for 2D images. Furthermore it provides a
delira
compatible dataset.
ShapeDataset¶
default_loader¶
-
default_loader
(data: str, img_size: tuple, crop=None, extension=None, rotate=None, cached=False, random_offset=False, random_scale=False, point_indices=None)[source]¶ Helper Function to load single sample
Parameters: - data (str or
SingleImage2D
) – image file to load - img_size (tuple) – image size for resizing
- crop (None or float) – if None: nor cropping will be applied if float: specifies boundary proportion for cropping
- extension (str or None:) – specifiying the extension
- rotate (int or None) – specifies to image rotation (in degrees)
- cached (bool) – whether or not the data is already cached
- random_offset (bool or float) – if bool: must be False -> No Random Shift is applied if float: specifies the maximal number of pixels to shift
- random_scale (bool or float) – if bool: must be False -> No random scaling is applied if float: specifies the maximum amount of scaling
- point_indices (None or Iterable) – if None: All landmarks are returned if Iterable: only landmarks corresponding to indices are returned
Returns: - np.ndarray – image
- np.ndarray – landmarks
- data (str or
preprocessing¶
-
preprocessing
(img: shapedata.single_shape.data_processing.SingleImage2D, img_size: tuple, crop=None, rotate=None, random_offset=False, random_scale=False, point_indices=None)[source]¶ Helper Function to preprocess a single sample
Parameters: - img (
SingleImage2D
) – image file to preprocess - img_size (tuple) – image size for resizing
- crop (None or float) – if None: nor cropping will be applied if float: specifies boundary proportion for cropping
- extension (str or None:) – specifiying the extension
- rotate (int or None) – specifies to image rotation (in degrees)
- random_offset (bool or float) – if bool: must be False -> No Random Shift is applied if float: specifies the maximal number of pixels to shift
- random_scale (bool or float) – if bool: must be False -> No random scaling is applied if float: specifies the maximum amount of scaling
- point_indices (None or Iterable) – if None: All landmarks are returned if Iterable: only landmarks corresponding to indices are returned
Returns: - np.ndarray – image
- np.ndarray – landmarks
- img (
DataProcessing¶
-
class
DataProcessing
(samples, dim=2, **kwargs)[source]¶ Bases:
object
Process multiple SingleImages
See also
-
static
_get_files
(directory, extensions)[source]¶ return files with extensions
Parameters: Returns: valid files
Return type:
-
classmethod
from_dir
(data_dir, verbose=True, n_jobs=None, n_dim=2)[source]¶ create class instance from directory
Parameters: Returns: class instance
Return type:
-
lmk_pca
(scale: bool, center: bool, pt_indices=[], *args, **kwargs)[source]¶ perform PCA on samples’ landmarks
Parameters: - scale (bool) – whether or not to scale the principal components with the corresponding eigen value
- center (bool) – whether or not to substract mean before pca
- pt_indices (int) – indices to include into PCA (if empty: include all points)
- args (list) – additional positional arguments (passed to pca)
- **kwargs – additional keyword arguments (passed to pca)
Returns: eigen_shapes
Return type: np.array
-
static
SingleImage2D¶
-
class
SingleImage2D
(img, lmk=None, **kwargs)[source]¶ Bases:
shapedata.base_data_processing.BaseSingleImage
Holds Single Image
-
_crop
(min_y, min_x, max_y, max_x)[source]¶ Implements actual cropping inplace
Parameters: Returns: cropped image
Return type:
-
static
_crop_lmks
(lmks, min_y, min_x, max_y, max_x)¶ Crops landmarks to given values
Parameters: Returns: cropped landmarks
Return type: np.ndarray
-
_crop_to_landmarks
(proportion=0.0, **kwargs)[source]¶ Crop to landmarks
Parameters: - proportion (float) – Cropping Proportion
- **kwargs – additional keyword arguments (ignored here)
Returns: Cropped Image
Return type:
-
_normalize_rotation
(lmks, index_left, index_right, **kwargs)¶ normalizes rotation based on two keypoints
Parameters: Returns: transformed Image
Return type: BaseSingleImage
-
_save_landmarks
(filepath, lmk_type, **kwargs)[source]¶ Saves landmarks to file
Parameters: Raises: ValueError
– no valid landmarktype is given
-
_transform_img
(transformation: <sphinx.ext.autodoc.importer._MockObject object at 0x7f5a875c5be0>, **kwargs)¶ Apply transformation inplace to image
Parameters: - transformation (
skimage.transform.AffineTransform
) – transformation to apply - **kwargs – additional keyword arguments
Returns: Transformed Image with original Landmarks
Return type: BaseSingleImage
- transformation (
-
_transform_lmk
(transformation: <sphinx.ext.autodoc.importer._MockObject object at 0x7f5a875b4470>)[source]¶ Apply transformation inplace to landmarks
Parameters: transformation ( skimage.transform.AffineTransform
) – transformation to applyReturns: Image with Transformed Landmarks Return type: BaseSingleImage
-
apply_trafo
(transformation: <sphinx.ext.autodoc.importer._MockObject object at 0x7f5a875c5be0>, **kwargs)¶ Apply transformation inplace to image and landmarks
Parameters: - transformation (
skimage.transform.AffineTransform
) – transformation to apply - **kwargs – additional keyword arguments
Returns: Transformed Image and Landmarks
Return type: BaseSingleImage
- transformation (
-
cartesian_coordinates
()[source]¶ Transforms landmark coordinates inplace to cartesian coordinates
Returns: class – Image with Landmarks in cartesian Coordinates Return type: SingleImage2D
-
crop
(min_y, min_x, max_y, max_x)¶ Crops Image by specified values
Parameters: Returns: cropped image
Return type: BaseSingleImage
-
crop_to_landmarks
(proportion=0.0, **kwargs)¶ Crop image to landmarks
Parameters: - proportion (float) – image proportion to add to size of bounding box
- **kwargs – additional keyword arguments
Returns: cropped image
Return type: BaseSingleImage
-
classmethod
from_files
(file, extension=None, **kwargs)¶ Creates a class instance from files
Parameters: - *args – positional arguments
- **kwargs – keyword arguments
Raises:
-
classmethod
from_ljson_files
(img_file, **kwargs)[source]¶ Creates class from menpo pts landmarks and image
Parameters: - img_file (str) – image file to load
- **kwargs – additional keyword arguments
Returns: class instance
Return type:
-
classmethod
from_npy_files
(file, **kwargs)[source]¶ Create class from image file :param file: path to image file :type file: str :param **kwargs: additional keyword arguments
Returns: class instance Return type: SingleImage2D
-
classmethod
from_pts_files
(img_file, **kwargs)[source]¶ Creates class from menpo ljson landmarks and image
Parameters: - img_file (str) – image file to load
- **kwargs – additional keyword arguments
Returns: class instance
Return type:
-
static
get_landmark_bounds
(lmks)¶ Function to calculate the landmark bounds
Parameters: lmks (np.ndarray) – landmarks Returns: - int (min_y)
- int (min_x)
- int (max_y)
- int (max_x)
-
homogeneous_coordinates
()[source]¶ Transforms landmark coordinates inplace to homogeneous coordinates
Returns: Image with Landmarks in Homogeneous Coordinates Return type: SingleImage2D
-
img
¶ Property to get the actual image pixels
Returns: image pixels Return type: np.array
-
is_gray
¶ Property returning whether the image is a grayscale image
Raises: NotImplementedError
– if not overwritten by subclass
-
is_homogeneous
¶ Property returning whether the landmarks are in homogeneous coordinates
Raises: NotImplementedError
– if not overwritten by subclass
-
normalize_rotation
(index_left, index_right, **kwargs)[source]¶ normalizes rotation based on two keypoints
- index_left : int
- landmark-index of the left point
- index_right : int
- landmark-index of the right point
- **kwargs:
- additional keyword arguments (passed to
warp()
)
Returns: normalized image Return type: SingleImage2D
-
rescale
(scale, **kwargs)¶ Scale Image and landmarks
Parameters: - scale – scale parameter
- **kwargs – additional keyword arguments (passed to
skimage.transform.warp()
)
Returns: transformed Image
Return type: BaseSingleImage
-
resize
(target_shape, **kwargs)¶ resize image and scale landmarks :param target_shape: target shape for resizing :type target_shape: tuple or list :param **kwargs: additional keyword arguments (passed to
skimage.transform.warp()
)Returns: transformed Image Return type: BaseSingleImage
-
rotate
(angle, degree=True, **kwargs)¶ Rotates the image and landmarks by given angle
Parameters: Returns: transformed Image
Return type: BaseSingleImage
-
save
(directory, filename, lmk_type='LJSON', **kwargs)¶ Saves Image and optionally landmarks to files
Parameters: - directory (str) – string containing the directory to save
- filename (str) – string containing the filename (without the extension)
- lmk_type (str or None) – if None: no landmarks will be saved if str: specifies type of landmark file
- **kwargs – additional keyword arguments passed to save function for landmarks
-
save_landmarks
(filepath, lmk_type='LJSON', **kwargs)¶ Saves landmarks to file
Parameters:
-
to_grayscale
()¶ Convert Image to grayscale
Returns: Grayscale Image Return type: BaseSingleImage
-
transform
(transform=None, rotation=None, scale=None, translation=None, shear=None, trafo_matrix=None, return_matrix=False, **kwargs)¶ transform image and landmarks by parameters or transformation matrix See
skimage.transform.AffineTransform
for a detailed parameter explanationParameters: - transform (
skimage.transform.AffineTransform
) – if transform is specified it overwrites all other arguments - rotation (float or None) – rotation angle in radiant
- scale (float or None) – scale value
- translation – translation params
- shear – shear params
- trafo_matrix – transformation matrix
- return_matrix (bool) – whether to return the transformation matrix along the transformed object
- **kwargs – additional keyword arguments
Returns: BaseSingleImage
– transformed Image- [optional] np.ndarray – transformation matrix
- transform (
-
transform_about_centre
(transform=None, rotation=None, scale=None, translation=None, shear=None, trafo_matrix=None, return_matrix=False, **kwargs)¶ Perform transformations about the image center. (internally shifting image to origin, perform transformation and shift it back)
Parameters: - transform (
skimage.transform.AffineTransform
) – if transform is specified it overwrites all other arguments - rotation (float) – rotation angle in radiant
- scale (float) – scale value
- translation – translation params
- shear – shear params
- trafo_matrix – transformation matrix
- return_matrix (bool) – whether to return the transformation matrix along the transformed object
- **kwargs – additional keyword arguments
Returns: BaseSingleImage
– transformed Image- [optional] np.ndarray – transformation matrix
- transform (
-
translate
(translation, relative=False, **kwargs)¶ translates image and landmarks
- translation :
- translation parameters
- relative : bool
- whether translation parameters are relative to image size
- **kwargs :
- additional keyword arguments (passed to
skimage.transform.warp()
)BaseSingleImage
- transformed Image
-
ljson_importer¶
-
ljson_importer
(filepath)[source]¶ Importer for the Menpo JSON format. This is an n-dimensional landmark type for both images and meshes that encodes semantic labels in the format. Landmark set label: JSON Landmark labels: decided by file
Parameters: filepath (str) – Absolute filepath of the file. Returns: loaded landmarks Return type: np.ndarray
pts_importer¶
-
pts_importer
(filepath, image_origin=True, z=False, **kwargs)[source]¶ Importer for the PTS file format. Assumes version 1 of the format. Implementations of this class should override the
_build_points()
which determines the ordering of axes. For example, for images, the x and y axes are flipped such that the first axis is y (height in the image domain). Note that PTS has a very loose format definition. Here we make the assumption (as is common) that PTS landmarks are 1-based. That is, landmarks on a 480x480 image are in the range [1-480]. As Menpo is consistently 0-based, we subtract 1 off each landmark value automatically. If you want to use PTS landmarks that are 0-based, you will have to manually add one back on to landmarks post importing. Landmark set label: PTSParameters: - filepath (str) – Absolute filepath of the file.
- image_origin (bool, optional) – If
True
, assume that the landmarks exist within an image and thus the origin is the image origin. - **kwargs (dict, optional) – Any other keyword arguments.
Returns: imported points
Return type: np.ndarray
ljson_exporter¶
-
ljson_exporter
(lmk_points, filepath, **kwargs)[source]¶ Given a file handle to write in to (which should act like a Python file object), write out the landmark data. No value is returned. Writes out the LJSON format which is a verbose format that closely resembles the labelled point graph format. It describes semantic labels and connectivity between labels. The first axis of the format represents the image y-axis and is consistent with ordering within Menpo.
Parameters: - lmk_points (np.ndarray) – The shape to write out.
- filepath (str) – The file to write in to
pts_exporter¶
-
pts_exporter
(pts, file_handle, **kwargs)[source]¶ Given a file handle to write in to (which should act like a Python file object), write out the landmark data. No value is returned. Writes out the PTS format which is a very simple format that does not contain any semantic labels. We assume that the PTS format has been created using Matlab and so use 1-based indexing and put the image x-axis as the first coordinate (which is the second axis within Menpo). Note that the PTS file format is only powerful enough to represent a basic pointcloud. Any further specialization is lost.
Parameters: - pts (np.ndarray) – points to save
- file_handle (file-like object) – The file to write in to