0

I tried to use itk to convert array to 3d image as .img. But itk didn't work. Even I use the demo code to convert a image to array and then convert the array back to image. It still showed a 2d image. How can I solve this problem?

import itk

image = itk.imread("input_filename.png")



array_view = itk.GetArrayViewFromImage(image)
array = itk.GetArrayFromImage(image)
image_view = itk.GetImageViewFromArray( np_array)
image = itk.GetImageFromArray( np_array)
itk.imwrite(image, "output_filename.png")

I want to save the array as .img. And it should be 3d image.

1 Answer 1

1

PNG is 2D image format, so if you want to write a 3D image you need to write into a format which supports 3D such as NRRD, MetaImage (.mha) or NIFTI (.nii). You also need to use a 3D image viewer, such as 3D Slicer or ITK-SNAP.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.