Skip to content

[Feature request] Expose ITK Image to MONAI MetaTensor conversion #5708

@ntatsisk

Description

@ntatsisk

Is your feature request related to a problem? Please describe.
I am trying to convert easily between ITK Image and MONAI MetaTensor. Currently, I am using my own simple function that works for my partcular use case:

def itk_image_to_metatensor(img):
    reader = ITKReader(affine_lps_to_ras=False)
    img_array, meta_data = reader.get_data(img)
    img_array = convert_to_dst_type(img_array, dst=img_array, dtype=itk.D)[0]
    metatensor = MetaTensor.ensure_torch_and_prune_meta(img_array, meta_data)
    metatensor = EnsureChannelFirst()(metatensor)

    return metatensor

which more-or-less the code that lives insde LoadImage: https://github.com/Project-MONAI/MONAI/blob/dev/monai/transforms/io/array.py#L273-L289

Describe the solution you'd like
I would like that MONAI provides two functions e.g. itk_image_to_metatensor() and metatensor_to_itk_image(). The implementation of the first already exists inside LoadImage transform (https://github.com/Project-MONAI/MONAI/blob/dev/monai/transforms/io/array.py#L273-L289) and of the latter inside ITKWriter: https://github.com/Project-MONAI/MONAI/blob/dev/monai/data/image_writer.py#L470-L517. So, ideally they just need to be exposed in order for them to be more easily usable.

Thanks in advance ;)

xref for us: InsightSoftwareConsortium/ITKElastix#126

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions