monai.deploy.operators.STLConverter

class monai.deploy.operators.STLConverter(*args, **kwargs)[source]

Bases: object

Converts volumetric image to surface mesh in STL

Creates an instance to generate a surface mesh in STL with an Image object.

Methods

__init__(*args, **kwargs)

Creates an instance to generate a surface mesh in STL with an Image object.

convert(image[, output_file, class_ids, …])

type image

Image

get_largest_cc(nda)

resize_volume(nda, output_shape[, order, …])

write_stl(verts, faces, filename)

class SpatialImage(image, dtype=<class 'numpy.float32'>)[source]

Bases: object

Object encapsulating a spatial volume image instance of Image.

Channel is not supported in this version.

Creates an instance.

Parameters
  • image (Image) – An instance of Image.

  • dtype (Numpy type, optional) – Defaults to np.float32.

__init__(image, dtype=<class 'numpy.float32'>)[source]

Creates an instance.

Parameters
  • image (Image) – An instance of Image.

  • dtype (Numpy type, optional) – Defaults to np.float32.

property affine

Affine of the re-oriented image data, or None

get_data()[source]

Returns the image array in ndarray

get_property(key, default=None)[source]

Gets value of the specified property

Parameters
  • key (str) – key of the property

  • default – default value if the property does not exist.

Returns

the value of the property, or the default value if property does not exist.

property image_array

Image data in Numpy array, or None

property itk_image

ITK image object created from the encapsulated image object, or None

property original_affine

Original affine of the image, or None

set_property(key, value)[source]

Sets an image property

Parameters
  • key (str) – key of the property

  • value – value of the property

property shape

Shape of image array, or None

property spacing

Pixel spacing of original image, aka resolution, or None

__init__(*args, **kwargs)[source]

Creates an instance to generate a surface mesh in STL with an Image object.

convert(image, output_file=None, class_ids=None, is_smooth=True, keep_largest_connected_component=True)[source]
Parameters
  • image (Image) – object with the image (ndarray of DHW index order) and its metadata dictionary.

  • output_file (str) – output STL file path. Default to None for not saving output file.

  • class_id (array, optional) – Class label id. Defaults to None.

  • is_smooth (bool, optional) – smoothing or not. Defaults to True.

  • keep_largest_connected_component (bool, optional) – Defaults to True.

Returns

Bytes of the binary STL file.