chaco.image_data module

Defines the ImageData class.

class chaco.image_data.ImageData

Bases: chaco.abstract_data_source.AbstractDataSource

Represents a grid of data to be plotted using a Numpy 2-D grid.

The data array has dimensions NxM, but it may have more than just 2 dimensions. The appropriate dimensionality of the value array depends on the context in which the ImageData instance will be used.

data = Property(ImageTrait)

Holds the grid data that forms the image. The shape of the array is (N, M, D) where:

  • D is 1, 3, or 4.

  • N is the length of the y-axis.

  • M is the length of the x-axis.

Thus, data[0,:,:] must be the first row of data. If D is 1, then the array must be of type float; if D is 3 or 4, then the array must be of type uint8.

NOTE: If this ImageData was constructed with a transposed data array, then internally it is still transposed (i.e., the x-axis is the first axis and the y-axis is the second), and the data array property might not be contiguous. If contiguousness is required and calling copy() is too expensive, use the raw_value attribute. Also note that setting this trait does not change the value of transposed, so be sure to set it to its proper value when using the same ImageData instance interchangeably to store transposed and non-transposed data.

dimension = ReadOnly(DimensionTrait("image"))

The dimensionality of the data.

classmethod fromfile(filename)

Alternate constructor to create an ImageData from an image file on disk. ‘filename’ may be a file path or a file object.

get_array_bounds()

Always returns ((0, width), (0, height)) for x-bounds and y-bounds.

get_bounds()

Returns the minimum and maximum values of the data source’s data.

Implements AbstractDataSource.

get_data()

Returns the data for this data source.

Implements AbstractDataSource.

get_height()

Returns the shape of the y-axis.

get_size()int

Implements AbstractDataSource.

get_width()

Returns the shape of the x-axis.

is_masked()False

Implements AbstractDataSource.

raw_value = Property(ImageTrait)

A read-only attribute that exposes the underlying array.

set_data(data)

Sets the data for this data source.

Parameters

data (array) – The data to use.

transposed = Bool(False)

Is raw_value, the actual underlying image data array, transposed from data? (I.e., does the first axis correspond to the x-direction and the second axis correspond to the y-direction?)

Rather than transposing or swapping axes on the data and destroying continuity, this class exposes the data as both data and raw_value.

value_depth = Int(1)  # TODO: Modify ImageData to explicitly support scalar

Depth of the values at each i,j. Values that are used include:

  • 3: color images, without alpha channel

  • 4: color images, with alpha channel