fix: rescale and swap axes to preserve original orientation

parent e2f6174b
......@@ -2,10 +2,13 @@
from __future__ import division
import numpy as np
from argparse import ArgumentParser
from nibabel import load
from PIL import Image
parser = ArgumentParser(prog='nithumb',
description='Generate a thumbnail from a NIfTI file')
parser.add_argument('inputfile', help='Input NIfTI file')
......@@ -13,8 +16,17 @@ parser.add_argument('thumbnail', help='Output thumbnail')
parsed = parser.parse_args()
image = load(parsed.inputfile).get_data()
imin = np.min(image)
imax = np.max(image)
image = ((image - imin) / np.float(imax - imin)) * 255.
image = np.swapaxes(image, 0, 1)
image = Image.fromarray(image[:, :, image.shape[2]//2] if image.ndim == 3
else image)
image = image.resize([128, 128])
if image.mode != 'RGB':
image = image.convert('RGB')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment