Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
mu-map
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tamino Huxohl
mu-map
Commits
3858361b
Commit
3858361b
authored
2 years ago
by
Tamino Huxohl
Browse files
Options
Downloads
Patches
Plain Diff
dicom to interfile conversion expects a default patient position
parent
1c0319f1
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
mu_map/file/convert.py
+27
-20
27 additions, 20 deletions
mu_map/file/convert.py
with
27 additions
and
20 deletions
mu_map/file/convert.py
+
27
−
20
View file @
3858361b
...
...
@@ -12,7 +12,11 @@ from mu_map.file.interfile import (
"""
Module for the conversion between the different formats.
"""
def
parse_position
(
position
:
str
)
->
Tuple
[
str
,
str
]:
def
parse_position
(
dcm
:
DICOM
,
default_orientation
:
str
=
"
feet_in
"
,
default_rotation
:
str
=
"
supine
"
)
->
Tuple
[
str
,
str
]:
"""
Parse the patient position from the DICOM patient position
field into the orientation and rotation as used by the Interfile
...
...
@@ -21,24 +25,25 @@ def parse_position(position: str) -> Tuple[str, str]:
:param position: the value of the patient position field in the DICOM header
:return: a tuple of patient orientation and rotation
"""
if
len
(
position
)
!=
3
:
raise
ValueError
(
f
"
Cannot parse patient position
{
position
}
"
)
_orienation
=
position
[:
2
]
if
_orienation
==
"
FF
"
:
orientation
=
"
feet_in
"
elif
_orienation
==
"
HF
"
:
orientation
=
"
head_in
"
_rotation
=
position
[
2
]
if
_orienation
==
"
P
"
:
rotation
=
"
prone
"
elif
_rotation
==
"
S
"
:
rotation
=
"
supine
"
if
rotation
is
None
or
orientation
is
None
:
raise
ValueError
(
f
"
Cannot parse patient position
{
position
}
"
)
orientation
=
default_orientation
rotation
=
default_rotation
try
:
position
=
dcm
.
PatientPosition
_orienation
=
position
[:
2
]
if
_orienation
==
"
FF
"
:
orientation
=
"
feet_in
"
elif
_orienation
==
"
HF
"
:
orientation
=
"
head_in
"
_rotation
=
position
[
2
]
if
_orienation
==
"
P
"
:
rotation
=
"
prone
"
elif
_rotation
==
"
S
"
:
rotation
=
"
supine
"
except
:
pass
return
orientation
,
rotation
...
...
@@ -50,7 +55,6 @@ def dicom_to_interfile(dcm: DICOM, image: np.ndarray) -> Interfile:
:param image: the image as a numpy array
:return: an Interfile as a combination of header and image
"""
orientation
,
rotation
=
parse_position
(
dcm
.
PatientPosition
)
header
=
TEMPLATE_HEADER_IMAGE
.
replace
(
"
{ROWS}
"
,
str
(
dcm
.
Rows
))
header
=
header
.
replace
(
"
{SPACING_X}
"
,
f
"
{
dcm
.
PixelSpacing
[
0
]
:
.
4
f
}
"
)
...
...
@@ -60,8 +64,11 @@ def dicom_to_interfile(dcm: DICOM, image: np.ndarray) -> Interfile:
header
=
header
.
replace
(
"
{SPACING_Z}
"
,
f
"
{
dcm
.
SliceThickness
:
.
4
f
}
"
)
header
=
header
.
replace
(
"
{OFFSET_X}
"
,
str
(
-
0.5
*
dcm
.
Rows
*
dcm
.
PixelSpacing
[
0
]))
header
=
header
.
replace
(
"
{OFFSET_Y}
"
,
str
(
-
0.5
*
dcm
.
Columns
*
dcm
.
PixelSpacing
[
1
]))
orientation
,
rotation
=
parse_position
(
dcm
)
header
=
header
.
replace
(
"
{PATIENT_ORIENTATION}
"
,
orientation
)
header
=
header
.
replace
(
"
{PATIENT_ROTATION}
"
,
rotation
)
header
=
parse_interfile_header_str
(
header
)
return
Interfile
(
header
,
image
.
astype
(
np
.
float32
))
...
...
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