Created
October 15, 2020 18:40
-
-
Save lydonchandra/a6d3486195e8c8a5f541a5b31a9dd8f8 to your computer and use it in GitHub Desktop.
Display nrrd as 3d using visvis
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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