Overview

imfusion.imagemath - Bindings for ImageMath Operations

This module provides element-wise arithmetic operations for SharedImage and SharedImageSet. You can apply these imagemath functionalities directly to objects of SharedImage and SharedImageSet with eager evaluation. Alternatively, the module offers lazy evaluation functionality through the submodule lazy. You can create wrapper expressions using the Expression provided by lazy.

See Expression for details.

Example for eager evaluation:

>>> from imfusion import imagemath

Add si1 and si2, which are SharedImage instances:

>>> si1 = imfusion.load(ct_image_png)[0][0]
>>> si2 = si1.clone()
>>> res = si1 + si2

res is a SharedImage instance.

>>> print(res)
imfusion.SharedImage(USHORT width: 512 height: 512 spacing: 0.661813x0.661813x1 mm)

Example for lazy evaluation:

>>> from imfusion.imagemath import lazy

Create expressions from SharedImage instances:

>>> expr1 = lazy.Expression(si1)
>>> expr2 = lazy.Expression(si2)

Add expr1 and expr2:

>>> expr3 = expr1 + expr2

Alternatively, you could add expr1 and si2 or si1 and expr2. Any expression containing an instance of Expression will be converted to lazy evaluation expression.

>>> expr3 = expr1 + si2

Find the result with lazy evaluation:

>>> res = expr3.evaluate()

res is a SharedImage instance similar to eager evaluation case.

>>> print(res)
imfusion.SharedImage(USHORT width: 512 height: 512 spacing: 0.661813x0.661813x1 mm)