Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Ghislain Antony Vaillant
nithumb
Commits
fe0e746f
Commit
fe0e746f
authored
Apr 20, 2017
by
Jonathan Passerat-Palmbach
Browse files
fix: rescale and swap axes to preserve original orientation
parent
e2f6174b
Changes
1
Hide whitespace changes
Inline
Side-by-side
nithumb.py
View file @
fe0e746f
...
...
@@ -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'
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment