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
85cd873e
Commit
85cd873e
authored
2 years ago
by
Tamino Huxohl
Browse files
Options
Downloads
Patches
Plain Diff
change reconstruction function
parent
593a7109
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/util.py
+28
-33
28 additions, 33 deletions
mu_map/util.py
with
28 additions
and
33 deletions
mu_map/util.py
+
28
−
33
View file @
85cd873e
...
@@ -4,6 +4,8 @@ from typing import Optional
...
@@ -4,6 +4,8 @@ from typing import Optional
import
numpy
as
np
import
numpy
as
np
from
tomolab.Reconstruction.SPECT
import
SPECT_Static_Scan
from
tomolab.Reconstruction.SPECT
import
SPECT_Static_Scan
from
mu_map.dataset.util
import
align_images
COLOR_BLACK
=
(
0
,
0
,
0
)
COLOR_BLACK
=
(
0
,
0
,
0
)
COLOR_WHITE
=
(
255
,
255
,
255
)
COLOR_WHITE
=
(
255
,
255
,
255
)
...
@@ -44,34 +46,33 @@ def grayscale_to_rgb(img: np.ndarray):
...
@@ -44,34 +46,33 @@ def grayscale_to_rgb(img: np.ndarray):
return
img
.
repeat
(
3
).
reshape
((
*
img
.
shape
,
3
))
return
img
.
repeat
(
3
).
reshape
((
*
img
.
shape
,
3
))
def
reconstruct
(
recon
,
mu_map
=
None
,
use_gpu
=
True
):
import
random
recon
=
np
.
transpose
(
recon
,
(
2
,
1
,
0
)).
astype
(
np
.
float32
)
def
reconstruct
(
recon
,
mu_map
=
None
,
use_gpu
=
True
,
seed
=
42
):
print
(
f
"
Transpose recon to
{
recon
.
shape
}
"
)
random
.
seed
(
42
)
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
=
SPECT_Static_Scan
()
spect
.
set_use_gpu
(
use_gpu
)
spect
.
set_use_gpu
(
use_gpu
)
recon_t
=
np
.
transpose
(
recon
,
(
2
,
1
,
0
)).
astype
(
np
.
float32
)
n_pixels
=
recon_t
.
shape
[
0
]
print
(
f
"
NPixels
{
n_pixels
}
,
{
recon_t
.
shape
}
"
)
# spect.set_n_pixels(n_pixels, n_pixels)
spect
.
set_n_pixels
(
128
,
128
)
spect
.
set_n_pixels
(
128
,
128
)
spect
.
set_gantry_angular_positions
(
0.0
,
360.0
,
59
)
spect
.
set_gantry_angular_positions
(
0.0
,
360.0
,
59
)
print
(
"
Forward projection .....
"
,
end
=
"
\r
"
)
if
mu_map
is
not
None
:
if
mu_map
is
not
None
:
measurement
=
spect
.
project
(
recon
,
attenuation
=
mu_map
)
mu_map_t
=
np
.
transpose
(
mu_map
,
(
2
,
1
,
0
)).
astype
(
np
.
float32
)
spect
.
set_measurement
(
measurement
.
data
)
spect
.
set_attenuation
(
mu_map
)
padding_lower
=
math
.
ceil
(
n_pixels
-
mu_map_t
.
shape
[
2
])
else
:
padding_upper
=
math
.
floor
(
n_pixels
-
mu_map_t
.
shape
[
2
])
measurement
=
spect
.
project
(
recon
)
mu_map_t
=
np
.
pad
(
mu_map_t
,
[(
0
,
0
),
(
0
,
0
),
(
padding_lower
,
padding_upper
)])
spect
.
set_measurement
(
measurement
.
data
)
spect
.
set_attenuation
(
mu_map_t
)
print
(
"
Forward projection .....
"
,
end
=
"
\r
"
)
measurement
=
spect
.
project
(
recon_t
)
print
(
f
"
Measurement:
{
measurement
.
data
.
shape
}
"
)
spect
.
set_measurement
(
measurement
.
data
)
print
(
"
Forward projection DONE!
"
)
print
(
"
Forward projection DONE!
"
)
spect
.
set_pixel_size
(
4.8
,
4.8
)
spect
.
set_pixel_size
(
4.8
,
4.8
)
...
@@ -82,25 +83,19 @@ def reconstruct(recon, mu_map=None, use_gpu=True):
...
@@ -82,25 +83,19 @@ def reconstruct(recon, mu_map=None, use_gpu=True):
activity
=
spect
.
estimate_activity
(
activity
=
spect
.
estimate_activity
(
iterations
=
10
,
subset_size
=
16
,
subset_mode
=
"
random
"
,
method
=
"
EM
"
iterations
=
10
,
subset_size
=
16
,
subset_mode
=
"
random
"
,
method
=
"
EM
"
)
)
activity
=
activity
.
data
print
(
"
Reconstruction DONE!
"
)
print
(
"
Reconstruction DONE!
"
)
s
=
recon
.
shape
[
2
]
/
2
activity
=
activity
.
data
c
=
activity
.
shape
[
2
]
//
2
activity
=
np
.
transpose
(
activity
,
(
2
,
1
,
0
))
activity
=
activity
[:,
:,
c
-
math
.
ceil
(
s
):
c
+
math
.
floor
(
s
)]
activity
,
_
=
align_images
(
activity
,
recon
)
print
(
f
"
Reshape activity to
{
activity
.
shape
}
"
)
return
activity
return
np
.
transpose
(
activity
,
(
2
,
1
,
0
))
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
import
pydicom
import
pydicom
from
mu_map.dataset.default
import
DCM_TAG_PIXEL_SCALE_FACTOR
from
mu_map.dataset.util
import
load_dcm_img
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
"
)
img
=
load_dcm_img
(
"
./data/second/images/0001-stress-
recon_nac_nsc
.dcm
"
)
mu_map
=
mu_map
.
pixel_array
/
mu_map
[
DCM_TAG_PIXEL_SCALE_FACTOR
].
value
mu_map
=
load_dcm_img
(
"
./data/second/images/0001-stress-mu_map.dcm
"
)
reconstruct
(
img
,
mu_map
)
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