jupiter_dai
jupiter_dai

Reputation: 71

How to convert array to 3D image

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.

Upvotes: 0

Views: 510

Answers (1)

Dženan
Dženan

Reputation: 3395

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.

Upvotes: 1

Related Questions