Skip to content

Attributes module

ImageAttributes dataclass

ImageAttributes(*, uiWidth: int = LV_field(0, UINT32), uiWidthBytes: int = LV_field(0, UINT32), uiHeight: int = LV_field(0, UINT32), uiComp: int = LV_field(0, UINT32), uiBpcInMemory: int = LV_field(0, INT32), uiBpcSignificant: int = LV_field(0, INT32), uiSequenceCount: int = LV_field(0, UINT32), uiTileWidth: int = LV_field(0, UINT32), uiTileHeight: int = LV_field(0, UINT32), eCompression: ImageAttributesCompression = LV_field(ictNone, INT32), dCompressionParam: float = LV_field(0.0, DOUBLE), ePixelType: ImageAttributesPixelType = LV_field(pxtUnsigned, INT32), uiVirtualComponents: int = LV_field(0, UINT32))

Dataclass for ND2 Image attributes chunk, stores mostly information about image width, height, number of components and bit depth of each pixel, as well as information about compression and total number of images.

componentBytes property

componentBytes: int

Size of component in bytes.

componentCount property

componentCount: int

Returns number of components in the image.

downsampleLevels cached property

downsampleLevels: list[int]

Returns list containing levels of downsampled images up to ND2_MIN_DOWNSAMPLED_SIZE.

dtype property

dtype: DTypeLike

Returns numpy datatype used for storing image data in Python.

frameCount property

frameCount: int

Returns number of frames in the ND2 file.

height property

height: int

Returns height of the image in pixels.

imageBytes property

imageBytes: int

Total size of the image in bytes.

pixelBytes property

pixelBytes: int

Size of pixel in bytes.

powSize cached property

powSize: int

Returns next power of 2 for bigger dimension.

powSizeBase cached property

powSizeBase: int

Returns exponent used in powSize() function.

safe_dtype property

safe_dtype: DTypeLike

Returns numpy datatype that will always be big enough to fit pixel component data.

shape property

shape: tuple[int, int, int]

Returns shape of the image which can be used with in array (height_pixels, width_pixels, component_count)

strides property

strides: tuple[int, int, int]

Returns the strides of the image which can be used in numpy array

width property

width: int

Returns width of the image in pixels.

widthBytes property

widthBytes: int

Size of image row in bytes.

calcWidthBytes staticmethod

calcWidthBytes(width: int, bits: int, comps: int) -> int

Calculates number of bytes per single image row.

create staticmethod

create(height: int, width: int, component_count: int, bits: int, sequence_count: int) -> ImageAttributes

Warning

This function is used for creating new ImageAttributes instance, usually for creating new .nd2 files with Nd2Writer class. Do not use this function if you only read .nd2 file.

Create ImageAttributes instance from following arguments (all must be passed as named arguments)

PARAMETER DESCRIPTION
height

height in pixels

TYPE: int

width

width in pixels

TYPE: int

component_count

number of components

TYPE: int

bits

number of bits per pixel component

TYPE: int

sequence_count

total number of frames in ND2 file (product of size of each dimension)

TYPE: int

findDownsampledLevelFor

findDownsampledLevelFor(size: int) -> int

Returns downsample level for given size.

from_lv staticmethod

from_lv(data: bytes | memoryview) -> ImageAttributes

Decodes ImageAttributes from ND2 lite variant chunk.

from_var staticmethod

from_var(data: bytes | memoryview) -> ImageAttributes

Decodes ImageAttributes from ND2 XML chunk.

makeDownsampled

makeDownsampled(downsample_level: int = 1) -> ImageAttributes

Returns ImageAttributes for downsampled image.

downsample_level: int Determines downsampling d = 2^downsample_level that produces lower level frames of size (w // d, h // d).

to_lv

to_lv() -> bytes

Encodes ImageAttributes to ND2 lite variant chunk.

ImageAttributesCompression

Enum for image compression.

ImageAttributesPixelType

Enum for pixel type.