fsleyes.gl.textures.imagetexture

This module provides the ImageTexture and ImageTexture2D classes, Texture3D and Texture2D classes for storing an Image instance.

fsleyes.gl.textures.imagetexture.createImageTexture(name, image, *args, **kwargs)

Creates and returns an appropriate texture type (either ImageTexture or ImageTexture2D) for the given image.

class fsleyes.gl.textures.imagetexture.ImageTextureBase(image, nvals, ndims)

Bases: object

Base class shared by the ImageTexture and ImageTexture2D classes. Contains logic for retrieving a specific volume from a 3D + time or 2D + time Image, and for retrieving a specific channel from an RGB(A) Image.

static validateShape(image, texnvals, texndims)

Called by __init__(). Makes sure that the specified texture settings (number of dimensions, and number of values per texture element) are compatible with the image.

Parameters
  • imageImage

  • texnvals – Number of values per texture element

  • texndims – Number of texture dimensions

Raises

RuntimeError if the texture properties are not compatible with the image

__init__(image, nvals, ndims)

Create an ImageTextureBase

Parameters
  • image – The Image

  • nvals – Number of values per texture element

  • ndims – Number of texture dimensions

destroy()

Must be called when this ImageTextureBase is no longer needed.

property image

Returns the Image managed by this ImageTextureBase.

property volume

For Image instances with more than three dimensions, specifies the indices for the fourth and above dimensions with which to extract the 3D texture data. If the image has four dimensions, this may be a scalar, otherwise it must be a sequence of (Image.ndim - 3) the correct length.

property channel

For Image instances with multiple values per voxel, such as RGB24 or RGBA32 images, this option allows the channel to be selected.

property texCoordXform

Returns a transformation matrix which can be used to adjust a set of 3D texture coordinates so they can index the underlying texture, which may be 2D.

This implementation returns an identity matrix, but it is overridden by ImageTexture2D.

property invTexCoordXform

Returns the inverse of texCoordXform().

shapeData(data)

Shape the data so that it is ready for use as texture data.

This implementation returns the data unchanged, but it is overridden by ImageTexture2D.

prepareSetArgs(**kwargs)

Called by sub-classes in their Texture2D.set()/ Texture3D.set() override.

Prepares arguments to be passed through to the underlying set method. This method accepts any parameters that are accepted by Texture3D.set(), plus the following:

volume

See volume().

channel

See channel().

volRefresh

If True (the default), the texture data will be refreshed even if the volume and channel parameters haven’t changed. Otherwise, if volume and channel haven’t changed, the texture will not be refreshed.

Returns

True if any settings have changed and the ImageTexture is to be refreshed , False otherwise.

_ImageTextureBase__getData(volume, channel)

Extracts data from the Image for use as texture data.

For textures with multiple values per element (either by volume, or by channel), the data is arranged appropriately, i.e. with the value as the first dimension.

Parameters
  • volume – Volume index/indices, for images with more than three dimensions.

  • channel – Channel, for RGB(A) images.

_ImageTextureBase__imageDataChanged(image, topic, sliceobj)

Called when the Image notifies about a data changes. Triggers an image texture refresh via a call to set().

Parameters
  • image – The Image instance

  • topic – The string 'data'

  • sliceobj – Slice object specifying the portion of the image that was changed.

__dict__ = mappingproxy({'__module__': 'fsleyes.gl.textures.imagetexture', '__doc__': 'Base class shared by the :class:`ImageTexture` and\n :class:`ImageTexture2D` classes. Contains logic for retrieving a\n specific volume from a 3D + time or 2D + time :class:`.Image`, and\n for retrieving a specific channel from an RGB(A) ``Image``.\n ', 'validateShape': <staticmethod object>, '__init__': <function ImageTextureBase.__init__>, 'destroy': <function ImageTextureBase.destroy>, 'image': <property object>, 'volume': <property object>, 'channel': <property object>, 'texCoordXform': <property object>, 'invTexCoordXform': <property object>, 'shapeData': <function ImageTextureBase.shapeData>, 'prepareSetArgs': <function ImageTextureBase.prepareSetArgs>, '_ImageTextureBase__getData': <function ImageTextureBase.__getData>, '_ImageTextureBase__imageDataChanged': <function ImageTextureBase.__imageDataChanged>, '__dict__': <attribute '__dict__' of 'ImageTextureBase' objects>, '__weakref__': <attribute '__weakref__' of 'ImageTextureBase' objects>})
__module__ = 'fsleyes.gl.textures.imagetexture'
__weakref__

list of weak references to the object (if defined)

class fsleyes.gl.textures.imagetexture.ImageTexture(name, image, **kwargs)

Bases: fsleyes.gl.textures.imagetexture.ImageTextureBase, fsleyes.gl.textures.texture3d.Texture3D

The ImageTexture class contains the logic required to create and manage a 3D texture which represents a Image instance.

Once created, the Image instance is available as an attribute of an ImageTexture object, called image. See the Texture3D documentation for more details.

For multi-valued (e.g. RGB) textures, the Texture3D class requires data to be passed as a (C, X, Y, Z) array (for C values). If an ImageTexture is created with an image of type NIFTI_TYPE_RGB24 or NIFTI_TYPE_RGBA32, it will take care of re-arranging the image data so that it has the shape required by the Texture3D class.

__init__(name, image, **kwargs)

Create an ImageTexture. A listener is added to the Image.data property, so that the texture data can be refreshed whenever the image data changes - see the __imageDataChanged() method.

Parameters
  • name – A name for this imageTexure.

  • image – The Image instance.

  • volume – Initial volume index/indices, for >3D images.

All other arguments are passed through to the Texture3D.__init__() method, and thus used as initial texture settings.

Note

The default value of the threaded parameter is set to the value of fsl.utils.platform.Platform.haveGui.

destroy()

Must be called when this ImageTexture is no longer needed.

set(**kwargs)

Overrides Texture3D.set(). Passes all arguments through the prepareSetArgs() method, then passes them on to Texture3D.set().

Returns

True if any settings have changed and the ImageTexture is to be refreshed , False otherwise.

__module__ = 'fsleyes.gl.textures.imagetexture'
class fsleyes.gl.textures.imagetexture.ImageTexture2D(name, image, **kwargs)

Bases: fsleyes.gl.textures.imagetexture.ImageTextureBase, fsleyes.gl.textures.texture2d.Texture2D

The ImageTexture2D class is the 2D analogue of the ImageTexture class, for managing a 2D texture which represents an Image instance.

__init__(name, image, **kwargs)

Create an ImageTexture2D.

destroy()

Must be called when this ImageTexture2D is no longer needed.

property texCoordXform

Overrides ImageTextureBase.texCoordXform(). Returns an affine matrix which encodes a rotation that maps the two major axes of the image voxel coordinate system to the first two axes of the texture coordinate system.

__module__ = 'fsleyes.gl.textures.imagetexture'
shapeData(data)

Overrides ImageTexureBase.shapeData().

Shapes the data, ensuring that it is compatible with a 2D texture.

Parameters

data – numpy array containing the data

set(**kwargs)

Overrides Texture2D.set(). Passes all arguments through the prepareSetArgs() method, then passes them on to Texture2D.set().

Returns

True if any settings have changed and the ImageTexture is to be refreshed , False otherwise.