miop.image_helper.image¶
Classes
|
Represents an image with associated metadata, and provides tools for preprocessing, transformation, and visualization. |
- class miop.image_helper.image.Image(image_path, image_name, metadata_type, metadata=None, tilt_axis=[1.0, 0, 0])[source]¶
Bases:
objectRepresents an image with associated metadata, and provides tools for preprocessing, transformation, and visualization.
The image is loaded from the given path and may include metadata in ‘fei’, ‘custom’, or ‘none’ formats. Basic image transformations such as cropping, rotation, and downsampling are supported.
- image_path¶
Path to the image file.
- Type:
str
- image_name¶
Name of the image file.
- Type:
str
- image¶
Image data as a NumPy array, loaded using OpenCV.
- Type:
np.ndarray
- metadata_type¶
Type of metadata used (‘fei’, ‘custom’, or ‘none’).
- Type:
str
- tilt_axis¶
Axis about which the tilt is defined. Default is [1., 0, 0].
- Type:
list of float
- tilt¶
Tilt angle in radians.
- Type:
float
- rotation_z¶
In-plane rotation angle (around z-axis) in radians. Automatically snapped to closest multiple of 90°.
- Type:
float
- tilt_rad¶
Whether the tilt is in radians (always True after init).
- Type:
bool
- metadata¶
Parsed metadata from the image (if available).
- Type:
dict
- crop(dim, top_left_corner)[source]¶
Crops the image based on given dimensions and top-left coordinates.
- Parameters:
dim (list of int) – Width and height of the cropped region [width, height].
top_left_corner (list of int) – X and Y coordinates of the top-left corner of the cropping box.
- Returns:
The image object after cropping (for method chaining).
- Return type:
Self
- downsample(factor_x, factor_y)[source]¶
Downsamples the image using nearest-neighbor interpolation.
- Parameters:
factor_x (float) – Downsampling factor in the x-direction (width).
factor_y (float) – Downsampling factor in the y-direction (height).
- Returns:
The image object after downsampling (for method chaining).
- Return type:
Self
- rotate(angle, rad=False)[source]¶
Rotates the image by a given angle.
- Parameters:
angle (float) – Angle to rotate the image.
rad (bool, optional) – If True, the angle is interpreted as radians. Default is False (degrees).
- Returns:
Rotated image.
- Return type:
np.ndarray
- rotate_by_transpose()[source]¶
Rotates the image using matrix transposition based on rotation_z, which is expected to be a multiple of 90 degrees (in radians). Uses NumPy’s rot90.
- Returns:
Rotated image.
- Return type:
np.ndarray
- Raises:
ValueError – If rotation_z exceeds 2π radians.
- save(path_to_dir)[source]¶
Saves the image to the specified directory as a PNG file.
- Parameters:
path_to_dir (str) – Directory where the image should be saved.
- Returns:
True if the image is successfully saved, False otherwise.
- Return type:
bool
- property shape¶
Returns the shape of the image.
- Returns:
The shape of the image (height, width, channels).
- Return type:
tuple