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
3819bfae
Commit
3819bfae
authored
2 years ago
by
Tamino Huxohl
Browse files
Options
Downloads
Patches
Plain Diff
add util module to dataset
parent
d3a0f2d7
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/dataset/util.py
+51
-0
51 additions, 0 deletions
mu_map/dataset/util.py
with
51 additions
and
0 deletions
mu_map/dataset/util.py
0 → 100644
+
51
−
0
View file @
3819bfae
from
typing
import
Tuple
import
numpy
as
np
import
pydicom
"""
Since DICOM images only allow images stored in short integer format,
the Siemens scanner software multiplies values by a factor before storing
so that no precision is lost.
The scale can be found in this private DICOM tag.
"""
DCM_TAG_PIXEL_SCALE_FACTOR
=
0x00331038
def
load_dcm_img
(
filename
:
str
)
->
np
.
ndarray
:
"""
Load a DICOM image as a numpy array and apply normalization of the Siemens SPECT/CT
Scanner.
:param filename: filename of the DICOM image
:return: the image scaled and loaded into a numpy array
"""
image
=
pydicom
.
dcmread
(
filename
)
image
=
image
.
pixel_array
/
image
[
DCM_TAG_PIXEL_SCALE_FACTOR
].
value
return
image
def
align_images
(
image_1
:
np
.
ndarray
,
image_2
:
np
.
ndarray
)
->
Tuple
[
np
.
ndarray
,
np
.
ndarray
]:
"""
Center align the image with more slices to the one with fewer slices on the first axis (z-axis).
:param image_1: the image to be aligned
:param image_2: the image to which image_1 is aligned
:return: both images aligned in the order they were put in
"""
# reverse function if image_2 has more slices
if
image_2
.
shape
[
0
]
>
image_1
.
shape
[
0
]:
return
align_images
(
image_2
,
image_1
)[::
-
1
]
# central slice of image 2
c_2
=
image_2
.
shape
[
0
]
//
2
# image to the left and right of the center
left
=
c_2
right
=
image_2
.
shape
[
0
]
-
c_2
# central slice of image 1
c_1
=
image_1
.
shape
[
0
]
//
2
# select center and same amount to the left/right as image_2
return
image_1
[(
c_1
-
left
)
:
(
c_1
+
right
)],
image_2
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