-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.py
117 lines (89 loc) · 2.9 KB
/
util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
from sirf import STIR
import typing
from dataclasses import dataclass
class SinogramTemplate(object):
def __init__(
self,
scanner: str = "Siemens_mMR",
span: int = 11,
max_ring_diff: int = 60,
view_mash_factor: int = 1,
):
self.scanner = scanner = scanner
self.span = span
self.max_ring_diff = max_ring_diff
self.view_mash_factor = view_mash_factor
def create(self) -> STIR.AcquisitionData:
self._acq_data = STIR.AcquisitionData(
self.scanner,
span=self.span,
max_ring_diff=self.max_ring_diff,
view_mash_factor=self.view_mash_factor,
)
return self._acq_data
def get_template(self) -> STIR.AcquisitionData:
return self._acq_data
def get_shape(self):
return self._acq_data.shape
def write(self, filename) -> None:
self._acq_data.write(f"{filename}.hs")
@dataclass
class BinningConfig(object):
start: float = 0
end: float = float("inf")
count_threshold: int = 10
class ListmodeData(object):
def __init__(self, listmode_file: str):
self._listmode_file = listmode_file
self._lm2sino = STIR.ListmodeToSinograms()
self._lm2sino.set_input(self._listmode_file)
self._sinogram = None
self._randoms = None
def to_sinogram(
self,
template_file: str,
prefix: str = "sinogram_",
binning: BinningConfig = None,
) -> STIR.AcquisitionData:
self._lm2sino.set_output_prefix(prefix)
self._lm2sino.set_template(template_file)
if binning:
self.time_shift = self.get_time_by_count_threshold(binning.count_threshold)
if self.time_shift > 0:
self._lm2sino.set_time_interval(
binning.start + self.time_shift, binning.end + self.time_shift
)
self._lm2sino.set_up()
print("start conversion...")
self._lm2sino.process()
self._sinogram = self._lm2sino.get_output()
return self._sinogram
def get_time_by_count_threshold(self, count_threshold):
return self._lm2sino.get_time_at_which_num_prompts_exceeds_threshold(
count_threshold
)
def estimate_randoms(self):
if self._sinogram:
self._randoms = self._lm2sino.estimate_randoms()
return self._randoms
return None
def get_sinogram(self):
return self._sinogram
def get_randoms(self):
return self._randoms
class uMAP(object):
def __init__(self, mu_map_file: str):
self._mu_map_file = mu_map_file
self._umap = STIR.ImageData(self._mu_map_file)
@property
def shape(self):
return self._umap.shape
@dataclass
class ImageResolution:
height: int
width: int
# class SinogramData(object):
# def __init__(self):
# pass
# def fit(self):
# pass