Skip to content
Snippets Groups Projects
Commit 8fb2b79b authored by Tamino Huxohl's avatar Tamino Huxohl
Browse files

add module for filter applied to the reconstruction

parent 5517a6e4
No related branches found
No related tags found
No related merge requests found
from mu_map.file.interfile import Interfile, InterfileKeys
TEMPLATE_FILTER_GAUSSIAN_PARAMS = """
post-filter type := Separable Gaussian
separable gaussian filter parameters :=
x-dir filter fwhm (in mm) := {FWHM_X}
y-dir filter fwhm (in mm) := {FWHM_Y}
z-dir filter fwhm (in mm) := {FWHM_Z}
x-dir maximum kernel size := {SIZE_X}
y-dir maximum kernel size := {SIZE_Y}
z-dir maximum kernel size := {SIZE_Z}
Normalise filter to 1 := 1
end separable gaussian filter parameters :=
"""
class GaussianFilter:
def __init__(self, projection: Interfile, width_scale: int = 1.0):
header, _ = projection
self.params = TEMPLATE_FILTER_GAUSSIAN_PARAMS
spacing_x = float(header[InterfileKeys.spacing(1)]) * width_scale
spacing_y = float(header[InterfileKeys.spacing(1)]) * width_scale
spacing_z = float(header[InterfileKeys.spacing(2)]) * width_scale
self.params = self.params.replace("{FWHM_X}", f"{spacing_x:.4f}")
self.params = self.params.replace("{FWHM_Y}", f"{spacing_y:.4f}")
self.params = self.params.replace("{FWHM_Z}", f"{spacing_z:.4f}")
self.params = self.params.replace("{SIZE_X}", header[InterfileKeys.dim(1)])
self.params = self.params.replace("{SIZE_Y}", header[InterfileKeys.dim(1)])
self.params = self.params.replace("{SIZE_Z}", header[InterfileKeys.dim(2)])
def insert(self, osem_params: str):
lines = self.params.strip().split("\n")
lines = list(map(lambda line: " " + line, lines))
lines.append("\n")
osem_lines = osem_params.strip().split("\n")
res = osem_lines[:-1] + lines + osem_lines[-1:]
return "\n".join(res)
def __repr__(self):
return self.params
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment