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
5f6917dd
Commit
5f6917dd
authored
2 years ago
by
Tamino Huxohl
Browse files
Options
Downloads
Patches
Plain Diff
update header template for interfile recon
parent
adc8795f
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
mu_map/file/dicom_to_interfile.py
+2
-2
2 additions, 2 deletions
mu_map/file/dicom_to_interfile.py
mu_map/file/interfile.py
+23
-20
23 additions, 20 deletions
mu_map/file/interfile.py
with
25 additions
and
22 deletions
mu_map/file/dicom_to_interfile.py
+
2
−
2
View file @
5f6917dd
...
@@ -3,7 +3,7 @@ from typing import Dict, Tuple
...
@@ -3,7 +3,7 @@ from typing import Dict, Tuple
import
numpy
as
np
import
numpy
as
np
from
pydicom.dataset
import
FileDataset
as
DCMImage
from
pydicom.dataset
import
FileDataset
as
DCMImage
from
mu_map.file.interfile
import
HEADER_
TEMPLATE
,
parse_interfile_header_str
from
mu_map.file.interfile
import
TEMPLAT
E_HEADER_IMAG
E
,
parse_interfile_header_str
def
to_interfile
(
dcm
:
DCMImage
,
image
:
np
.
ndarray
)
->
Tuple
[
Dict
[
str
,
str
],
np
.
ndarray
]:
def
to_interfile
(
dcm
:
DCMImage
,
image
:
np
.
ndarray
)
->
Tuple
[
Dict
[
str
,
str
],
np
.
ndarray
]:
...
@@ -14,7 +14,7 @@ def to_interfile(dcm: DCMImage, image: np.ndarray) -> Tuple[Dict[str, str], np.n
...
@@ -14,7 +14,7 @@ def to_interfile(dcm: DCMImage, image: np.ndarray) -> Tuple[Dict[str, str], np.n
:param image: the image as a numpy array
:param image: the image as a numpy array
:return: the header and image in INTERFILE format
:return: the header and image in INTERFILE format
"""
"""
header
=
HEADER_
TEMPLATE
.
replace
(
"
{ROWS}
"
,
str
(
dcm
.
Rows
))
header
=
TEMPLAT
E_HEADER_IMAG
E
.
replace
(
"
{ROWS}
"
,
str
(
dcm
.
Rows
))
header
=
header
.
replace
(
"
{SPACING_X}
"
,
f
"
{
dcm
.
PixelSpacing
[
0
]
:
.
4
f
}
"
)
header
=
header
.
replace
(
"
{SPACING_X}
"
,
f
"
{
dcm
.
PixelSpacing
[
0
]
:
.
4
f
}
"
)
header
=
header
.
replace
(
"
{COLUMNS}
"
,
str
(
dcm
.
Columns
))
header
=
header
.
replace
(
"
{COLUMNS}
"
,
str
(
dcm
.
Columns
))
header
=
header
.
replace
(
"
{SPACING_Y}
"
,
f
"
{
dcm
.
PixelSpacing
[
1
]
:
.
4
f
}
"
)
header
=
header
.
replace
(
"
{SPACING_Y}
"
,
f
"
{
dcm
.
PixelSpacing
[
1
]
:
.
4
f
}
"
)
...
...
This diff is collapsed.
Click to expand it.
mu_map/file/interfile.py
+
23
−
20
View file @
5f6917dd
...
@@ -3,56 +3,58 @@ from typing import Dict, Tuple
...
@@ -3,56 +3,58 @@ from typing import Dict, Tuple
import
numpy
as
np
import
numpy
as
np
Interfile
=
Tuple
[
Dict
[
str
,
str
],
np
.
ndarray
]
"""
"""
Several keys defined in INTERFILE headers.
Several keys defined in INTERFILE headers.
"""
"""
KEY_DIM_1
=
"
!
matrix size [1]
"
KEY_DIM_1
=
"
matrix size [1]
"
KEY_DIM_2
=
"
!
matrix size [2]
"
KEY_DIM_2
=
"
matrix size [2]
"
KEY_DIM_3
=
"
!
matrix size [3]
"
KEY_DIM_3
=
"
matrix size [3]
"
KEY_SPACING_1
=
"
scaling factor (mm/pixel) [1]
"
KEY_SPACING_1
=
"
scaling factor (mm/pixel) [1]
"
KEY_SPACING_2
=
"
scaling factor (mm/pixel) [2]
"
KEY_SPACING_2
=
"
scaling factor (mm/pixel) [2]
"
KEY_SPACING_3
=
"
scaling factor (mm/pixel) [2]
"
KEY_SPACING_3
=
"
scaling factor (mm/pixel) [2]
"
KEY_NPROJECTIONS
=
"
!
number of projections
"
KEY_NPROJECTIONS
=
"
number of projections
"
KEY_DATA_FILE
=
"
name of data file
"
KEY_DATA_FILE
=
"
name of data file
"
KEY_BYTES_PER_PIXEL
=
"
!
number of bytes per pixel
"
KEY_BYTES_PER_PIXEL
=
"
number of bytes per pixel
"
KEY_NUMBER_FORMAT
=
"
!
number format
"
KEY_NUMBER_FORMAT
=
"
number format
"
"""
"""
A template of an INTERFILE header.
A template of an INTERFILE header.
"""
"""
HEADER_
TEMPLATE
=
"""
TEMPLAT
E_HEADER_IMAG
E
=
"""
!
INTERFILE :=
INTERFILE :=
!
imaging modality := nucmed
imaging modality := nucmed
!
version of keys := STIR4.0
version of keys := STIR4.0
name of data file := {DATA_FILE}
name of data file := {DATA_FILE}
!
GENERAL DATA :=
GENERAL DATA :=
!
GENERAL IMAGE DATA :=
GENERAL IMAGE DATA :=
!
type of data := Tomographic
type of data := Tomographic
imagedata byte order := LITTLEENDIAN
imagedata byte order := LITTLEENDIAN
isotope name := ^99m^Technetium
isotope name := ^99m^Technetium
!
SPECT STUDY (General) :=
SPECT STUDY (General) :=
process status := Reconstructed
process status := Reconstructed
!
number format := float
number format := float
!
number of bytes per pixel := 4
number of bytes per pixel := 4
number of dimensions := 3
number of dimensions := 3
matrix axis label [1] := x
matrix axis label [1] := x
!
matrix size [1] := {ROWS}
matrix size [1] := {ROWS}
scaling factor (mm/pixel) [1] := {SPACING_X}
scaling factor (mm/pixel) [1] := {SPACING_X}
matrix axis label [2] := y
matrix axis label [2] := y
!
matrix size [2] := {COLUMNS}
matrix size [2] := {COLUMNS}
scaling factor (mm/pixel) [2] := {SPACING_Y}
scaling factor (mm/pixel) [2] := {SPACING_Y}
matrix axis label [3] := z
matrix axis label [3] := z
!
matrix size [3] := {SLICES}
matrix size [3] := {SLICES}
scaling factor (mm/pixel) [3] := {SPACING_Z}
scaling factor (mm/pixel) [3] := {SPACING_Z}
first pixel offset (mm) [1] := {OFFSET_X}
first pixel offset (mm) [1] := {OFFSET_X}
first pixel offset (mm) [2] := {OFFSET_Y}
first pixel offset (mm) [2] := {OFFSET_Y}
first pixel offset (mm) [3] := 0
first pixel offset (mm) [3] := 0
number of time frames := 1
number of time frames := 1
!
END OF INTERFILE :=
END OF INTERFILE :=
"""
"""
...
@@ -80,6 +82,7 @@ def parse_interfile_header_str(header: str) -> Dict[str, str]:
...
@@ -80,6 +82,7 @@ def parse_interfile_header_str(header: str) -> Dict[str, str]:
:param header: the text of an INTERFILE header
:param header: the text of an INTERFILE header
:return: a dictionary of value in the header
:return: a dictionary of value in the header
"""
"""
header
=
header
.
replace
(
"
!
"
,
""
)
lines
=
header
.
strip
().
split
(
"
\n
"
)
lines
=
header
.
strip
().
split
(
"
\n
"
)
items
=
map
(
lambda
line
:
line
.
split
(
"
:=
"
),
lines
)
items
=
map
(
lambda
line
:
line
.
split
(
"
:=
"
),
lines
)
items
=
filter
(
lambda
item
:
len
(
item
)
==
2
,
items
)
items
=
filter
(
lambda
item
:
len
(
item
)
==
2
,
items
)
...
...
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