Skip to content

Instantly share code, notes, and snippets.

@lydonchandra
Created October 15, 2020 18:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lydonchandra/a6d3486195e8c8a5f541a5b31a9dd8f8 to your computer and use it in GitHub Desktop.
Save lydonchandra/a6d3486195e8c8a5f541a5b31a9dd8f8 to your computer and use it in GitHub Desktop.
Display nrrd as 3d using visvis
import numpy as np
import nrrd
import argparse
import os.path
from argparse import ArgumentParser
import imageio
import visvis as vv
def is_valid_file(parser, arg):
if not os.path.exists(arg):
parser.error("The file %s does not exist!" % arg)
else:
return open(arg, 'r') # return an open file handle
parser = ArgumentParser(description='Display NRRD as 3D Volume')
parser.add_argument("-i", dest="file", required=True,
help="input nrrd file", metavar="string",
type=lambda x: is_valid_file(parser, x))
args = parser.parse_args()
nrrdInPath = args.file.name
data, header = nrrd.read(nrrdInPath)
npzOutPath = nrrdInPath + '.npz'
np.savez_compressed( npzOutPath, data )
app = vv.use()
vol = imageio.volread(npzOutPath)
vol_res = vv.volshow( vol )
app.Run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment