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