0

How to convert png to nrrd? I need help, thank you! I use the following code:

    img = cv2.imread(imgPath)
    imgT = img.transpose(1,0,2)
    img3d = imgT[..., np.newaxis]
    nrrd.write(imgPath.split(".png")[0] + ".nrrd", img3d)

But the conversion speed is very slow. It takes me almost 8 seconds to convert 1 picture.

1 Answers1

0

I don't know what your conversion is so slow, but you could use SimpleITK to do it. It shouldn't take that long. Here's what that code would look like:

import SimpleITK as sitk

img = sitk.ReadImage(imgPath)
# not sure exactly what you're doing with the transpose and 3d bit of code
sitk.WriteImage(img, imgPath.split(".png")[0] + ".nrrd")
Dave Chen
  • 1,905
  • 1
  • 12
  • 18