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
d3a0f2d7
Commit
d3a0f2d7
authored
2 years ago
by
Tamino Huxohl
Browse files
Options
Downloads
Patches
Plain Diff
add reconstruction function to util
parent
cab9e42d
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
mu_map/util.py
+64
-0
64 additions, 0 deletions
mu_map/util.py
with
64 additions
and
0 deletions
mu_map/util.py
+
64
−
0
View file @
d3a0f2d7
import
math
from
typing
import
Optional
import
numpy
as
np
from
tomolab.Reconstruction.SPECT
import
SPECT_Static_Scan
COLOR_BLACK
=
(
0
,
0
,
0
)
COLOR_WHITE
=
(
255
,
255
,
255
)
...
...
@@ -40,3 +42,65 @@ def grayscale_to_rgb(img: np.ndarray):
"""
assert
img
.
ndim
==
2
,
f
"
grascale image has more than 2 dimensions
{
img
.
shape
}
"
return
img
.
repeat
(
3
).
reshape
((
*
img
.
shape
,
3
))
def
reconstruct
(
recon
,
mu_map
=
None
,
use_gpu
=
True
):
recon
=
np
.
transpose
(
recon
,
(
2
,
1
,
0
)).
astype
(
np
.
float32
)
print
(
f
"
Transpose recon to
{
recon
.
shape
}
"
)
if
mu_map
is
not
None
:
mu_map
=
np
.
transpose
(
mu_map
,
(
2
,
1
,
0
)).
astype
(
np
.
float32
)
s
=
recon
.
shape
[
0
]
padding_lower
=
math
.
ceil
(
s
-
mu_map
.
shape
[
2
])
padding_upper
=
math
.
floor
(
s
-
mu_map
.
shape
[
2
])
_shape
=
mu_map
.
shape
mu_map
=
np
.
pad
(
mu_map
,
[(
0
,
0
),
(
0
,
0
),
(
padding_lower
,
padding_upper
)])
print
(
f
"
Change mu_map shape from
{
_shape
}
to
{
mu_map
.
shape
}
"
)
spect
=
SPECT_Static_Scan
()
spect
.
set_use_gpu
(
use_gpu
)
spect
.
set_n_pixels
(
128
,
128
)
spect
.
set_gantry_angular_positions
(
0.0
,
360.0
,
59
)
print
(
"
Forward projection .....
"
,
end
=
"
\r
"
)
if
mu_map
is
not
None
:
measurement
=
spect
.
project
(
recon
,
attenuation
=
mu_map
)
spect
.
set_measurement
(
measurement
.
data
)
spect
.
set_attenuation
(
mu_map
)
else
:
measurement
=
spect
.
project
(
recon
)
spect
.
set_measurement
(
measurement
.
data
)
print
(
"
Forward projection DONE!
"
)
spect
.
set_pixel_size
(
4.8
,
4.8
)
spect
.
set_radius
(
200.0
)
spect
.
set_psf
(
fwhm0_mm
=
5.0
,
depth_dependence
=
0.0001
)
print
(
"
Reconstruction .....
"
,
end
=
"
\r
"
)
activity
=
spect
.
estimate_activity
(
iterations
=
10
,
subset_size
=
16
,
subset_mode
=
"
random
"
,
method
=
"
EM
"
)
activity
=
activity
.
data
print
(
"
Reconstruction DONE!
"
)
s
=
recon
.
shape
[
2
]
/
2
c
=
activity
.
shape
[
2
]
//
2
activity
=
activity
[:,
:,
c
-
math
.
ceil
(
s
):
c
+
math
.
floor
(
s
)]
print
(
f
"
Reshape activity to
{
activity
.
shape
}
"
)
return
np
.
transpose
(
activity
,
(
2
,
1
,
0
))
if
__name__
==
"
__main__
"
:
import
pydicom
from
mu_map.dataset.default
import
DCM_TAG_PIXEL_SCALE_FACTOR
img
=
pydicom
.
dcmread
(
"
./data/second/images/0001-stress-recon_nac_nsc.dcm
"
)
img
=
img
.
pixel_array
/
img
[
DCM_TAG_PIXEL_SCALE_FACTOR
].
value
mu_map
=
pydicom
.
dcmread
(
"
./data/second/images/0001-stress-mu_map.dcm
"
)
mu_map
=
mu_map
.
pixel_array
/
mu_map
[
DCM_TAG_PIXEL_SCALE_FACTOR
].
value
reconstruct
(
img
,
mu_map
)
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