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
f5f73a4a
Commit
f5f73a4a
authored
2 years ago
by
Tamino Huxohl
Browse files
Options
Downloads
Patches
Plain Diff
refactoring of dicom module
parent
bdb70082
No related branches found
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.py
+9
-7
9 additions, 7 deletions
mu_map/file/dicom.py
mu_map/file/interfile_to_dicom.py
+4
-4
4 additions, 4 deletions
mu_map/file/interfile_to_dicom.py
with
13 additions
and
11 deletions
mu_map/file/dicom.py
+
9
−
7
View file @
f5f73a4a
...
@@ -6,7 +6,11 @@ from typing import Tuple
...
@@ -6,7 +6,11 @@ from typing import Tuple
import
numpy
as
np
import
numpy
as
np
import
pydicom
import
pydicom
dcm_type
=
pydicom
.
dataset
.
FileDataset
"""
Alias for the main dicom datatype.
"""
DICOM
=
pydicom
.
dataset
.
FileDataset
"""
"""
Since DICOM images only allow images stored in short integer format,
Since DICOM images only allow images stored in short integer format,
...
@@ -58,7 +62,7 @@ class DICOMTime(Enum):
...
@@ -58,7 +62,7 @@ class DICOMTime(Enum):
"""
"""
return
f
"
{
self
.
name
}
Time
"
return
f
"
{
self
.
name
}
Time
"
def
to_datetime
(
self
,
dicom
:
dcm_type
)
->
datetime
:
def
to_datetime
(
self
,
dicom
:
DICOM
)
->
datetime
:
"""
"""
Get the datetime according to this DICOMTime type.
Get the datetime according to this DICOMTime type.
"""
"""
...
@@ -94,7 +98,7 @@ def parse_age(patient_age: str) -> int:
...
@@ -94,7 +98,7 @@ def parse_age(patient_age: str) -> int:
return
int
(
_num
)
return
int
(
_num
)
def
load_dcm
(
filename
:
str
)
->
Tuple
[
pydicom
.
dataset
.
FileDataset
,
np
.
ndarray
]:
def
load_dcm
(
filename
:
str
)
->
Tuple
[
DICOM
,
np
.
ndarray
]:
"""
"""
Load a DICOM image, the data as a numpy array and apply normalization of the Siemens SPECT/CT
Load a DICOM image, the data as a numpy array and apply normalization of the Siemens SPECT/CT
Scanner.
Scanner.
...
@@ -144,9 +148,7 @@ def scale_image(image: np.ndarray, initial_scale=10000000) -> Tuple[np.ndarray,
...
@@ -144,9 +148,7 @@ def scale_image(image: np.ndarray, initial_scale=10000000) -> Tuple[np.ndarray,
return
image
,
scale
return
image
,
scale
def
update_dcm
(
def
update_dcm
(
dcm
:
DICOM
,
image
:
np
.
ndarray
)
->
DICOM
:
dcm
:
pydicom
.
dataset
.
FileDataset
,
image
:
np
.
ndarray
)
->
pydicom
.
dataset
.
FileDataset
:
"""
"""
Update the image data in a DICOM file. This function scales the image, converts
Update the image data in a DICOM file. This function scales the image, converts
it to unsigned integers with 16 bits and updates the pixel data in the DICOM file.
it to unsigned integers with 16 bits and updates the pixel data in the DICOM file.
...
@@ -176,7 +178,7 @@ def update_dcm(
...
@@ -176,7 +178,7 @@ def update_dcm(
return
dcm
return
dcm
def
change_uid
(
dcm
:
pydicom
.
dataset
.
FileDataset
)
->
pydicom
.
dataset
.
FileDataset
:
def
change_uid
(
dcm
:
DICOM
)
->
DICOM
:
"""
"""
Change the UIDs (SeriesInstance and SOPInstance) in a DICOM header so that
Change the UIDs (SeriesInstance and SOPInstance) in a DICOM header so that
it becomes its own unique file. Note that this method does not guarantee
it becomes its own unique file. Note that this method does not guarantee
...
...
This diff is collapsed.
Click to expand it.
mu_map/file/interfile_to_dicom.py
+
4
−
4
View file @
f5f73a4a
...
@@ -8,22 +8,22 @@ from mu_map.file.dicom import update_dcm, change_uid
...
@@ -8,22 +8,22 @@ from mu_map.file.dicom import update_dcm, change_uid
from
mu_map.file.interfile
import
load_interfile_img
from
mu_map.file.interfile
import
load_interfile_img
parser
=
argparse
.
ArgumentParser
(
parser
=
argparse
.
ArgumentParser
(
description
=
"
convert an I
NTERFILE
image to a DICOM image
"
,
description
=
"
convert an I
nterfile
image to a DICOM image
"
,
formatter_class
=
argparse
.
ArgumentDefaultsHelpFormatter
,
formatter_class
=
argparse
.
ArgumentDefaultsHelpFormatter
,
)
)
parser
.
add_argument
(
parser
.
add_argument
(
"
--inter
"
,
type
=
str
,
required
=
True
,
help
=
"
the I
NTERFILE
image to be converted
"
"
--inter
"
,
type
=
str
,
required
=
True
,
help
=
"
the I
nterfile
image to be converted
"
)
)
parser
.
add_argument
(
parser
.
add_argument
(
"
--dcm
"
,
"
--dcm
"
,
type
=
str
,
type
=
str
,
required
=
True
,
required
=
True
,
help
=
"
a DICOM reference image - data and according fields are exchanged from the I
NTERFILE
image
"
,
help
=
"
a DICOM reference image - data and according fields are exchanged from the I
nterfile
image
"
,
)
)
parser
.
add_argument
(
parser
.
add_argument
(
"
--out
"
,
"
--out
"
,
type
=
str
,
type
=
str
,
help
=
"
the output file - defaults to the I
NTERFILE
input with a dcm extension
"
,
help
=
"
the output file - defaults to the I
nterfile
input with a dcm extension
"
,
)
)
parser
.
add_argument
(
parser
.
add_argument
(
"
--description
"
,
"
--description
"
,
...
...
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