pyiron_contrib.image.image module

class pyiron_contrib.image.image.Image(source, metadata=None, as_gray=False)[source]

Bases: object

A base class for storing image data in the form of numpy arrays. Functionality of the skimage library can be leveraged using the sub-module name and an activate method.

source

The raw data source.

Type

str/numpy.ndarray

data

The image data. Not loaded until called, so first call may be slow. Modifications are made to this field, leaving the source untouched. NOT saved to hdf.

Type

numpy.ndarray

as_gray

Whether to interpret the image as grayscale.

Type

bool

metadata

Metadata associated with the source.

Type

Metadata

convert_to_grayscale()[source]

Flattens (NxMx3) data into (NxM) grayscale data.

property data
from_hdf(hdf, group_name=None)[source]
property metadata
overwrite_source(new_source, new_metadata=None, as_gray=False)[source]

Apply a new source of image data to the image object.

Parameters
  • new_source (str/numpy.ndarray) – The filepath to the data, or the raw array of data itself.

  • new_metadata (Metadata) – The metadata associated with the new source. (Default is None.)

  • as_gray (bool) – Whether to interpret the new data as grayscale. (Default is False.)

plot(ax=None, subplots_kwargs=None, imshow_kwargs=None, hide_axes=True)[source]

Make a simple matplotlib imshow plot of the data.

Parameters
  • ax (matplotlib.axes.Axes) – The axis to plot on. (Default is None, make a new figure.)

  • subplots_kwargs (dict) – Keyword arguments to pass to the figure generation. Only used if no axis is provided. (Default is None.)

  • imshow_kwargs (dict) – Keyword arguments to pass to the imshow plotting command. (Default is None.)

  • hide_axes (bool) – Whether to hide axis ticks and labels. (Default is True.)

Returns

The figure the plot is in. (matplotlib.axes.Axes): The axis the plot is on.

Return type

(matplotlib.figure.Figure)

reload_data()[source]

Reverts the data attribute to the source, i.e. the most recently read file (if set by reading data), or the originally assigned array (if set by direct array assignment).

property shape
property source
to_hdf(hdf, group_name=None)[source]
class pyiron_contrib.image.image.Metadata(dict=None, /, **kwargs)[source]

Bases: UserDict

TODO: Leverage the generic to and from hdf functions written by Dominik over in pyiron_contrib/protocol

from_hdf(hdf, group_name=None)[source]
to_hdf(hdf, group_name=None)[source]
pyiron_contrib.image.image.pass_and_set_image_data(image)[source]

Decorator which connects function input and output to image.data.

Parameters

image (Image) – The image whose data to set.

Returns

Decorated function.

Return type

(fnc)

pyiron_contrib.image.image.pass_image_data(image)[source]

Decorator to see if the signature of the function starts with a particular variable (_IMAGE_VARIABLE). If so, automatically passes an attribute of the argument (image.data) as the first argument.

Parameters

image (Image) – The image whose data to use.

Returns

Decorated function.

Return type

(fnc)

pyiron_contrib.image.image.set_image_data(image)[source]

Decorator which checks the returned value of the function. If that value is of type numpy.ndarray, uses it to set an attribute of the argument (image.data) instead of returning it.

Parameters

image (Image) – The image whose data to set.

Returns

Decorated function.

Return type

(fnc)