miop.image_collection

Classes

ImageCollection([metadata_type, metadata, ...])

Represents a collection of images, with support for downsampling, cropping, rotating, segmentation, and pairing based on image metadata.

class miop.image_collection.ImageCollection(metadata_type='none', metadata=None, downsample=1.0, crop_dim=[], two_by_two=False, use_segmentation=False, max_dim=(800, 800), verbose=True)[source]

Bases: DAGNode

Represents a collection of images, with support for downsampling, cropping, rotating, segmentation, and pairing based on image metadata.

metadata_type

Type of metadata (‘none’, ‘fei’, or ‘custom’).

Type:

str

metadata
Metadata associated with each image. Each dict may contain:
  • ‘StageTa’: Tilt angle in radians.

  • ‘tilt_axis’: Tilt axis as a 3D vector (e.g., [1., 0., 0.]).

  • ‘StageR’: Rotation angle of the microscope stage in the (x, y) plane, in radians.

Type:

list of dict

downsample_factor

Factor by which to downsample all images.

Type:

float

crop_dim

Crop dimensions per face. Format: [[[width, height], [x, y]], …]

Type:

list

two_by_two

If True, images are grouped into fixed pairs: (1,2), (3,4), etc. If False, grouped as overlapping pairs: (1,2), (2,3), etc.

Type:

bool

use_segmentation

Whether to use segmentation masks.

Type:

bool

max_dim

Maximum image dimensions as (width, height).

Type:

tuple of int

verbose

If True, prints warnings and logs.

Type:

bool

paths_to_images

File paths to the images in the collection.

Type:

list of str

paths_to_masks

File paths to the corresponding segmentation masks.

Type:

list of str

images

List of loaded Image objects.

Type:

list of Image

masks

Mapping from Image objects to their segmentation masks.

Type:

dict

pairs

List of image pairs used for multi-view geometry.

Type:

list of ImagePair

faces

Grouped image pairs, organized by face.

Type:

list of tuple

apply_to_collection(func, *args, **kwargs)[source]

Applies a function to each image in the collection.

Parameters:
  • func (callable) – Function to apply to each image.

  • *args – Additional positional arguments to pass to the function.

  • **kwargs – Additional keyword arguments to pass to the function.

Returns:

List of results from the function.

Return type:

list

apply_to_face(face_idx, func, *args, **kwargs)[source]

Applies a function to all images within a face.

Parameters:
  • face_idx (int) – Index of the face.

  • func (callable) – Function to apply.

  • *args – Additional positional arguments.

  • **kwargs – Additional keyword arguments.

Returns:

List of results from the function.

Return type:

list

crop(*crop_arg)[source]

Crops images in the collection.

Parameters:

crop_arg (list) –

List of crop parameters. Format per face: [[width, height], [x_offset, y_offset]]

If only one crop_arg is provided, it is applied to all faces.

downsample(factor_x, factor_y)[source]

Downsamples all images in the collection.

Parameters:
  • factor_x (float) – Downsampling factor for width.

  • factor_y (float) – Downsampling factor for height.

eval(paths_to_images, paths_to_masks=None)[source]

Loads and preprocesses the image collection: reading, cropping, downsampling, rotating, and handling segmentation.

Parameters:
  • paths_to_images (list of str) – Paths to the image files.

  • paths_to_masks (list of str, optional) – Paths to the segmentation mask directories.

Returns:

The processed image collection.

Return type:

ImageCollection

register_pair(paths_to_images)[source]

Not implemented. Used to manually add image pairs to the collection.

Raises:

NotImplementedError

rotate(angle=None, rad=False)[source]

Rotates all images of the collection according to angle or rotation_z from the metadata.

Parameters:
  • angle (float or None, optional) – Angle to rotate. If None, uses rotation_z from metadata.

  • rad (bool, optional) – If True, angle is in radians. Default is False.

save_collection(path_to_dir)[source]

Saves all images to the specified directory.

Parameters:

path_to_dir (str) – Directory path where images will be saved.

Returns:

Results from saving images.

Return type:

list

show(crop_utility=True, use_segmentation=False)[source]

Displays all images in the collection, optionally overlaying crop regions and segmentation masks.

Parameters:
  • crop_utility (bool, optional) – Whether to display the cropping utility overlay (default is True).

  • use_segmentation (bool, optional) – Whether to overlay segmentation masks (default is False).