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
418d9d89
Commit
418d9d89
authored
2 years ago
by
Tamino Huxohl
Browse files
Options
Downloads
Patches
Plain Diff
update dicom/interfile utils
parent
b62a6936
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
+25
-0
25 additions, 0 deletions
mu_map/file/dicom.py
mu_map/file/interfile2dicom.py
+11
-3
11 additions, 3 deletions
mu_map/file/interfile2dicom.py
with
36 additions
and
3 deletions
mu_map/file/dicom.py
+
25
−
0
View file @
418d9d89
from
datetime
import
datetime
,
timedelta
from
typing
import
Tuple
import
numpy
as
np
...
...
@@ -15,6 +16,12 @@ DCM_TAG_PIXEL_SCALE_FACTOR = 0x00331038
Maximum value that can be stored in an unsigned integer with 16 bist.
"""
UINT16_MAX
=
2
**
16
-
1
"""
DICOM images always contain UIDs to indicate their uniqueness.
Thus, when a DICOM image is updated, UIDs have to be changed for
which the following prefix is used.
"""
UID_PREFIX
=
"
1.2.826.0.1.3680043.2.521.
"
def
load_dcm
(
filename
:
str
)
->
Tuple
[
pydicom
.
dataset
.
FileDataset
,
np
.
ndarray
]:
...
...
@@ -89,3 +96,21 @@ def update_dcm(
dcm
.
LargestImagePixelValue
=
image
.
max
()
dcm
[
DCM_TAG_PIXEL_SCALE_FACTOR
].
value
=
scale
return
dcm
def
change_uid
(
dcm
:
pydicom
.
dataset
.
FileDataset
)
->
pydicom
.
dataset
.
FileDataset
:
"""
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
that the UIDs are fully unique. Since the creation of UIDs is time dependent,
this function should not be used to rapidly change many UIDs.
:param dcm: the DICOM file to be udpated
:return: the DICOM file with updated UIDs
"""
now
=
datetime
.
now
()
soon
=
now
+
timedelta
(
seconds
=
1
)
dcm
.
SeriesInstanceUID
=
UID_PREFIX
+
now
.
strftime
(
"
%Y%m%d%H%M%S
"
)
dcm
.
SOPInstanceUID
=
UID_PREFIX
+
soon
.
strftime
(
"
%Y%m%d%H%M%S
"
)
return
dcm
This diff is collapsed.
Click to expand it.
mu_map/file/interfile2dicom.py
+
11
−
3
View file @
418d9d89
...
...
@@ -4,8 +4,8 @@ import os
import
numpy
as
np
import
pydicom
from
mu_map.file.dicom
import
update_dcm
from
mu_map.file.interfile
import
re
ad_interfile
from
mu_map.file.dicom
import
update_dcm
,
change_uid
from
mu_map.file.interfile
import
lo
ad_interfile
_img
parser
=
argparse
.
ArgumentParser
(
description
=
"
convert an INTERFILE image to a DICOM image
"
,
...
...
@@ -25,13 +25,21 @@ parser.add_argument(
type
=
str
,
help
=
"
the output file - defaults to the INTERFILE input with a dcm extension
"
,
)
parser
.
add_argument
(
"
--description
"
,
type
=
str
,
help
=
"
if provided the series description will be updated
"
,
)
args
=
parser
.
parse_args
()
if
args
.
out
is
None
:
args
.
out
=
os
.
path
.
splitext
(
args
.
inter
)[
0
]
+
"
.dcm
"
image
,
header
=
re
ad_interfile
(
args
.
inter
)
image
=
lo
ad_interfile
_img
(
args
.
inter
)
dcm
=
pydicom
.
dcmread
(
args
.
dcm
)
dcm
=
update_dcm
(
dcm
.
copy
(),
image
)
dcm
=
change_uid
(
dcm
)
if
args
.
description
:
dcm
.
SeriesDescription
=
args
.
description
pydicom
.
dcmwrite
(
args
.
out
,
dcm
)
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