organoid_tracker.core.images module

class organoid_tracker.core.images.ChannelDescription(channel_name: str, colormap: Colormap)

Bases: NamedTuple

Describes a channel in an image. What name did the user give it, and what colormap is used to display it?

channel_name: str

Alias for field number 0

colormap: Colormap

Alias for field number 1

with_colormap(colormap: Colormap) ChannelDescription

Creates a new ChannelDescription with the same channel name, but a different colormap.

class organoid_tracker.core.images.Image(array: ndarray, offset: Position = Position(0.00, 0.00, 0))

Bases: object

Represents a single 3D image

property array

Gets the raw array. Note that the array indices are not translated, so the position self.offset appears at index (0,0,0) in the array.

bounding_box() BoundingBox

Gets a bounding box that encompasses the entire image.

property limit_x: int

Gets the limit in the x direction. If the image has an offset of 10 and a size of 20, the limit will be 30.

property limit_y: int

Gets the limit in the y direction. If the image has an offset of 10 and a size of 20, the limit will be 30.

property limit_z: int

Gets the limit in the z direction. If the image has an offset of 10 and a size of 20, the limit will be 30.

property min_x: int

Gets the lowest X coord for which the image has a value.

property min_y: int

Gets the lowest X coord for which the image has a value.

property min_z: int

Gets the lowest X coord for which the image has a value.

property offset: Position

Gets the offset of the array. If the offset is (10, 2, 0), then a position at (11, 2, 0) will appear in the array at index (1, 2, 0)

set_pixel(position: Position, value: Union[float, int])

Sets a single pixel, taking the offset of this image into account. Warning: doesn’t do bounds checking.

property shape_x: Tuple[int, int, int]

Gets the size in the x direction in pixels.

property shape_y: int

Gets the size in the y direction in pixels.

property shape_z: int

Gets the size in the z direction in pixels.

value_at(position: Position) Optional[int]

Gets the value at the given position. Takes the offset of this image into account. Returns None if the position is outside the image.

static zeros_like(image: Image, *, dtype: Optional = None) Image

Returns a new image consisting of only zeros with the same shape and offset as the existing image.

class organoid_tracker.core.images.ImageOffsets(offsets: List[Position] = None)

Bases: object

copy() ImageOffsets

Returns a copy of this object. Any changes to the copy won’t have an effect on this object, and vice versa.

move_in_time(time_point_delta: int)

Moves all offsets the given amounts of time points.

of_time_point(time_point: TimePoint) Position

Gets the pixel offset of the image in the given time point.

to_list() List[Position]

Exports this offset list as a list of offsets with time points specified.

update_offset(dx: int, dy: int, dz: int, min_time_point: int, max_time_point: int)

Sets the offset for all of the given time point range (inclusive). The offset is added to the current offset.

class organoid_tracker.core.images.Images

Bases: object

Records the images (3D + time), their resolution and their offset.

close_image_loader()

Closes the image loader, releasing file system handles, and replacing it with a dummy one that contains no images.

copy() Images

Returns a copy of this images object. Any changes to the copy won’t affect this object and vice versa.

filters: ImageFilters
first_time_point() Optional[TimePoint]

Gets the first time point with an image, if any.

first_time_point_number() Optional[int]

Gets the first time point with an image, if any.

get_channel_description(channel: ImageChannel) ChannelDescription

Gets the description of the given channel.

get_channels() List[ImageChannel]

Gets all available image channels. These are determined by the image_loader. They will be in order, so with ImageChannel.index_zero matching the position in the list.

get_image(time_point: TimePoint, image_channel: ImageChannel = ImageChannel(index_zero=0)) Optional[Image]

Gets an image along with offset information, or None if there is no image available for that time point.

get_image_slice_2d(time_point: TimePoint, image_channel: ImageChannel, z: int) Optional[ndarray]

Gets a 2D grayscale image for the given time point, image channel and z.

get_image_stack(time_point: TimePoint, image_channel: ImageChannel = ImageChannel(index_zero=0)) Optional[ndarray]

Loads an image using the current image loader. Returns None if there is no image for this time point.

has_timings() bool

Checks if the experiment has timing information for the time points, i.e. how long each time point is.

If explicit is True, then we only return True if the timings information was provided explicitly, instead of just using the time resolution.

image_loader(image_loader: Optional[ImageLoader] = None) ImageLoader

Gets/sets the image loader. Note: images loaded directly from this image loader will be uncached.

Warning: consider whether you need to close the old image loader first.

is_inside_image(position: Position, *, margin_xy: int = 0, margin_z: int = 0) Optional[bool]

Checks if the given position is inside the images. If there are no images loaded, this returns None. Any image offsets (see self.offsets) are taken into account.

If margins are specified, then this method also returns False for positions that are within the given number of pixels towards the edge of the image.

last_time_point() Optional[TimePoint]

Gets the last time point with an image, if any.

last_time_point_number() Optional[int]

Gets the last time point with an image, if any.

move_in_time(time_point_delta: int)

Moves all timings and offset data in time. The images themselves cannot be moved in time.

property offsets

Gets the image offsets - used to keep the position of the object of interest constant, while the images move.

resolution(allow_incomplete: bool = False) ImageResolution

Gets the image resolution. Raises UserError no spatial resolution has been set. Also raises UserError if the data has multiple time points, but no time resolution has been set.

save_3d_image_array(time_point: TimePoint, image_channel: ImageChannel, image: ndarray)

Saves a 3D image to the image loader. Also updates the image cache to have the newest array.

set_channel_description(channel: ImageChannel, description: ChannelDescription)

Sets the description of the given channel.

set_resolution(resolution: Optional[ImageResolution])

Sets the image resolution.

set_timings(timings: Optional[ImageTimings])

Sets explicit timings for all time points in the experiment. Useful if not all time points have the same time resolution.

If you set the timings to None, only the time resolution in ImageResolution will be used.

Note: in ImageResolution, the time interval is updated to match t(1) - t(0). If you later set a different time resolution, then that will delete the timings information.

time_points() Iterable[TimePoint]

Gets all time points for which images are available.

timings() ImageTimings

Gets the timings of all time points of the experiment. If they aren’t found, but a time resolution is specified, then constant timing is assumed. If no time resolution, and no explicit timings are found, a UserError is raised.

use_image_loader_from(images: Images)

Transfers the image loader from another Images instance, sharing the image cache.