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 0x7f8f65aab438>, **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 0x7f8f65af4748>)[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 0x7f8f65aab438>, **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
-