darsia.OpticalImage#

class OpticalImage(img, transformations=None, **kwargs)[source]#

Bases: Image

Special case of 2d trichromatic optical images, typically originating from photographs.

Specialized constructor for optical images.

In addition to the constructor of general images, the color space is required to be specified through the keyword arguments.

Methods

add_grid([origin, dx, dy, color, thickness])

Adds a grid on the image and returns new image.

append(image[, offset])

Append other image to current image.

astype(data_type)

For scalar data types, change the data type of the data array.

copy()

Copy constructor.

eval(point[, interpolation])

Evaluate the image array at a given point location.

geometry()

Generate (flat) geometry object corresponding to the image.

img_as(data_type)

Change data type via skimage.

integral()

Integrate the image over its spatial dimensions.

metadata()

Generator of metadata; can be used to init a new optical image with same specs.

reset_origin([return_image])

Reset origin and coordinatesystem.

reset_reference_time()

Pick date of first image in a series as reference date.

resize(cx[, cy])

roi(roi)

Extraction of spatial subregion using a darsia.ROI object.

save(path[, verbose])

Save image to file.

set_time([time])

Setter for time array.

shape_metadata()

Return all metadata connected to dimensions of image and voxels.

show([title, duration, mode])

Show image using matplotlib.pyplots or plotly built-in methods.

show_matplotlib([title, duration])

Show the image using matplotlib.pyplot.

show_plain([title])

Show image using matplotlib.pyplots in plain mode.

show_plotly([title, duration])

Show the image using plotly (often faster than matplotlib).

slice(cut, axis)

Extract of spatial slice.

subregion(roi)

Extraction of spatial subregion.

time_interval(indices)

Extraction of temporal subregion, only for space-time images.

time_slice(time_index)

Extraction of single time slice.

to_monochromatic(key)

Returns monochromatic version of the image.

to_trichromatic(color_space[, return_image])

Transforms image to another trichromatic color space.

to_vtk(path[, name])

Save image to file in vtk format.

update_metadata([meta])

Update metadata of image.

update_reference_time(reference)

Update reference time.

write(path, **kwargs)

Write the image to file.

Attributes

coordinatesystem

Physical coordinate system with equipped transformation from voxel to Cartesian space.

domain

Physical domain.

dtype

Data type of the (current) image array.

num_voxels

Number of voxels in each dimension.

opposite_corner

Cartesian coordinate of the corner opposite to origin.

shape

Shape of the image array, incl.

space_num

Spatial resolution, i.e., number of voxels.

voxel_size

Size of each voxel in each direction, ordered as indexing.

color_space

Color space of the trichromatic data space.

img

Data array.

original_dtype

Original dtype at construction of the object.

space_dim

Dimension of the spatial domain.

indexing

Indexing of each axis in context of matrix indexing (ijk) or Cartesian coordinates (xyz).

dimensions

Dimension in the directions corresponding to the indexings.

name

Name of image, e.g., used to describe the origin.

origin

Cartesian coordinates associated to the [0,0,0] voxel (after applying transformations), using Cartesian indexing.

series

Flag controlling whether the data array corresponds to a time series.

time_dim

Dimensionality of the image in temporal sense.

time_num

Number of time points.

date

Time in datetime format.

reference_date

Reference date (for defining relative time).

time

Relative time in scalar format (in seconds).

scalar

Flag controlling whether the data array is scalar, i.e., it does not use an extra axis to encode the range.

range_dim

Dimensionality of the image in data sense.

range_num

Number of entries for each data entry.

add_grid(origin=None, dx=1, dy=1, color=(0, 0, 125), thickness=9)[source]#

Adds a grid on the image and returns new image.

Parameters:
originnp.ndarray

Origin of the grid, in physical units - the reference coordinate system is provided by the corresponding attribute coordinatesystem.

dxfloat

Grid size in x-direction, in physical units.

dyfloat

Grid size in y-direction, in physical units.

colortuple of int

BGR color of the grid.

thicknessint

Thickness of the grid lines.

Returns:
OpticalImage

Original image with grid on top.

copy()[source]#

Copy constructor.

Returns:
OpticalImage

Copy of the image object.

metadata()[source]#

Generator of metadata; can be used to init a new optical image with same specs.

Returns:
dict

Metadata with keys equal to all keywords agurments.

to_monochromatic(key)[source]#

Returns monochromatic version of the image.

Returns:
ScalarImage

Monochromatic image.

to_trichromatic(color_space, return_image=False)[source]#

Transforms image to another trichromatic color space.

Parameters:
color_spacestr

Target color space.

return_imagebool

Flag controlling whether the converted image is returned, or converted internally.

Returns:
OpticalImage (optional): converted image, if requested via ‘return_image’.
write(path, **kwargs)[source]#

Write the image to file.

Parameters:
pathPath

Full path to the output image.

**kwargs

quality (int) – 0-100, resolution for a jpg image. compression (int) – 0-9, compression level for a png image.

color_space#

Color space of the trichromatic data space.