Skip to content

How to save nifti / dicom image with provided numpy array and affine matrix? #2663

@Nic-Ma

Description

@Nic-Ma

Hi @thewtex ,

We are trying to add the ITK writer in project MONAI, I searched the doc of ITK but I didn't find how to save a nifti or dicom image with provided numpy array and affine matrix. Could you please help show some example?

Expected code:

def save(np_array: np.ndarray, affine_matrix: np.ndarray):
    itk_np_view = itk.image_view_from_array(np_array)
    itk_np_view.SetMatrix(affine_matrix)
    itk.imwrite(itk_np_view, filename)

But seems there is no SetMatrix API.

Thanks in advance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:EnhancementImprovement of existing methods or implementation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions