|
1
|
|
|
# Copyright 2014 Diamond Light Source Ltd. |
|
2
|
|
|
# |
|
3
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); |
|
4
|
|
|
# you may not use this file except in compliance with the License. |
|
5
|
|
|
# You may obtain a copy of the License at |
|
6
|
|
|
# |
|
7
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0 |
|
8
|
|
|
# |
|
9
|
|
|
# Unless required by applicable law or agreed to in writing, software |
|
10
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, |
|
11
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
12
|
|
|
# See the License for the specific language governing permissions and |
|
13
|
|
|
# limitations under the License. |
|
14
|
|
|
|
|
15
|
|
|
""" |
|
16
|
|
|
.. module:: dezinger_sinogram_deprecated |
|
17
|
|
|
:platform: Unix |
|
18
|
|
|
:synopsis: A plugin working in sinogram space to removes zingers. Remove |
|
19
|
|
|
zingers (caused by scattered X-rays hitting the CCD chip directly) |
|
20
|
|
|
.. moduleauthor:: Nghia Vo <[email protected]> |
|
21
|
|
|
|
|
22
|
|
|
""" |
|
23
|
|
|
from savu.plugins.plugin import Plugin |
|
24
|
|
|
from savu.plugins.driver.cpu_plugin import CpuPlugin |
|
25
|
|
|
from savu.plugins.utils import register_plugin |
|
26
|
|
|
import numpy as np |
|
27
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
class DezingerSinogramDeprecated(Plugin, CpuPlugin): |
|
30
|
|
|
""" |
|
31
|
|
|
""" |
|
32
|
|
|
|
|
33
|
|
|
def __init__(self): |
|
34
|
|
|
super(DezingerSinogramDeprecated, self).__init__("DezingerSinogramDeprecated") |
|
35
|
|
|
|
|
36
|
|
|
def setup(self): |
|
37
|
|
|
in_dataset, out_dataset = self.get_datasets() |
|
38
|
|
|
out_dataset[0].create_dataset(in_dataset[0]) |
|
39
|
|
|
in_pData, out_pData = self.get_plugin_datasets() |
|
40
|
|
|
in_pData[0].plugin_data_setup('SINOGRAM', 'single') |
|
41
|
|
|
out_pData[0].plugin_data_setup('SINOGRAM', 'single') |
|
42
|
|
|
|
|
43
|
|
|
def pre_process(self): |
|
44
|
|
|
in_pData = self.get_plugin_in_datasets() |
|
45
|
|
|
width_dim = in_pData[0].get_data_dimension_by_axis_label('detector_x') |
|
46
|
|
|
height_dim = \ |
|
47
|
|
|
in_pData[0].get_data_dimension_by_axis_label('rotation_angle') |
|
48
|
|
|
sino_shape = list(in_pData[0].get_shape()) |
|
49
|
|
|
self.width1 = sino_shape[width_dim] |
|
50
|
|
|
self.height1 = sino_shape[height_dim] |
|
51
|
|
|
|
|
52
|
|
|
def process_frames(self, data): |
|
53
|
|
|
tolerance = self.parameters['tolerance'] |
|
54
|
|
|
nhigh = 1.0 + tolerance |
|
55
|
|
|
sinogram = np.copy(data[0]) |
|
56
|
|
|
sinogram[sinogram == 0.0] = np.mean(sinogram) |
|
57
|
|
|
sinogram_d = np.roll(sinogram, 1, axis=0) |
|
58
|
|
|
sinogram_u = np.roll(sinogram, -1, axis=0) |
|
59
|
|
|
|
|
60
|
|
|
list_top = sinogram[0] |
|
61
|
|
|
list_top1 = sinogram[1] |
|
62
|
|
|
list_top2 = list_top / list_top1 |
|
63
|
|
|
list_top[list_top2 > nhigh] = list_top1[list_top2 > nhigh] |
|
64
|
|
|
|
|
65
|
|
|
list_bottom = sinogram[-1] |
|
66
|
|
|
list_bottom1 = sinogram[-2] |
|
67
|
|
|
list_bottom2 = list_bottom / list_bottom1 |
|
68
|
|
|
list_bottom[list_bottom2 > nhigh] = list_bottom1[list_bottom2 > nhigh] |
|
69
|
|
|
|
|
70
|
|
|
mat_ratio_d = sinogram / sinogram_d |
|
71
|
|
|
sinogram[mat_ratio_d > nhigh] = sinogram_d[mat_ratio_d > nhigh] |
|
72
|
|
|
mat_ratio_u = sinogram / sinogram_u |
|
73
|
|
|
sinogram[mat_ratio_u > nhigh] = sinogram_u[mat_ratio_u > nhigh] |
|
74
|
|
|
sinogram[0] = list_top |
|
75
|
|
|
sinogram[-1] = list_bottom |
|
76
|
|
|
return sinogram |
|
77
|
|
|
|