Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michiel Cottaar
fslpy
Commits
cdd86e33
Commit
cdd86e33
authored
8 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
New module for loading VEST lut files.
parent
4a80ba28
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
fsl/data/vest.py
+69
-0
69 additions, 0 deletions
fsl/data/vest.py
with
69 additions
and
0 deletions
fsl/data/vest.py
0 → 100644
+
69
−
0
View file @
cdd86e33
#!/usr/bin/env python
#
# vest.py - Functions for working with VEST files.
#
# Author: Paul McCarthy <pauldmccarthy@gmail.com>
#
"""
This module contains a handful of functions for working with VEST files.
.. autosummary::
:nosignatures:
looksLikeVestLutFile
loadVestLutFile
"""
import
numpy
as
np
def
looksLikeVestLutFile
(
path
):
"""
Returns ``True`` if the given ``path`` looks like a VEST LUT file,
``False`` otherwise.
"""
with
open
(
path
,
'
rt
'
)
as
f
:
return
f
.
readline
().
strip
()
==
'
%!VEST-LUT
'
def
loadVestLutFile
(
path
,
normalise
=
True
):
"""
Assumes that the given file is a VEST LUT file, and attempts to load it.
Returns a ``numpy.float32`` array of shape ``(n, 3)``, where ``n`` is the
number of colours in the file.
If ``normalise=True`` (the default), the colour values are normalised to
the range ``0-1``.
"""
with
open
(
path
,
'
rt
'
)
as
f
:
lines
=
f
.
readlines
()
# We over-allocate the colour array
# here, and truncate the array after
# reading. idx keepsd track of the
# number of colours read in.
idx
=
0
colours
=
np
.
zeros
((
len
(
lines
),
3
),
dtype
=
np
.
float32
)
for
line
in
lines
:
if
not
line
.
startswith
(
'
<-color{
'
):
continue
start
=
line
.
index
(
'
{
'
)
+
1
end
=
line
.
index
(
'
}
'
)
r
,
g
,
b
=
line
[
start
:
end
].
split
(
'
,
'
)
colours
[
idx
,
:]
=
float
(
r
),
float
(
g
),
float
(
b
)
idx
+=
1
colours
=
colours
[:
idx
,
:]
if
normalise
:
cmin
=
colours
.
min
()
cmax
=
colours
.
max
()
return
(
colours
-
cmin
)
/
(
cmax
-
cmin
)
else
:
return
colours
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment