|
1
|
|
|
# Copyright 2020 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 |
|
17
|
|
|
:platform: Unix |
|
18
|
|
|
:synopsis: A 2D/3D median-based dezinger plugin to apply to any data |
|
19
|
|
|
.. moduleauthor::Daniil Kazantsev <[email protected]> |
|
20
|
|
|
""" |
|
21
|
|
|
from savu.plugins.filters.denoising.base_median_filter import BaseMedianFilter |
|
22
|
|
|
from savu.plugins.driver.cpu_plugin import CpuPlugin |
|
23
|
|
|
from savu.plugins.utils import register_plugin |
|
24
|
|
|
|
|
25
|
|
|
import numpy as np |
|
26
|
|
|
from larix.methods.misc import MEDIAN_DEZING |
|
27
|
|
|
|
|
28
|
|
View Code Duplication |
@register_plugin |
|
|
|
|
|
|
29
|
|
|
class Dezinger(BaseMedianFilter, CpuPlugin): |
|
30
|
|
|
|
|
31
|
|
|
def __init__(self): |
|
32
|
|
|
super(Dezinger, self).__init__("Dezinger") |
|
33
|
|
|
|
|
34
|
|
|
def process_frames(self, data): |
|
35
|
|
|
input_temp = data[0] |
|
36
|
|
|
indices = np.where(np.isnan(input_temp)) |
|
37
|
|
|
input_temp[indices] = 0.0 |
|
38
|
|
|
if (self.parameters['dimension'] == '3D'): |
|
39
|
|
|
if (self.parameters['pattern'] == 'VOLUME_XY'): |
|
40
|
|
|
input_temp =np.swapaxes(input_temp,0,2) |
|
41
|
|
|
if ((self.parameters['pattern'] == 'VOLUME_XZ') or (self.parameters['pattern'] == 'SINOGRAM')): |
|
42
|
|
|
input_temp =np.swapaxes(input_temp,0,1) |
|
43
|
|
|
result = MEDIAN_DEZING(input_temp.copy(order='C'), self.parameters['kernel_size'], self.parameters['outlier_mu']) |
|
44
|
|
|
if (self.parameters['dimension'] == '3D'): |
|
45
|
|
|
if (self.parameters['pattern'] == 'VOLUME_XY'): |
|
46
|
|
|
result =np.swapaxes(result,0,2) |
|
47
|
|
|
if ((self.parameters['pattern'] == 'VOLUME_XZ') or (self.parameters['pattern'] == 'SINOGRAM')): |
|
48
|
|
|
result =np.swapaxes(result,0,1) |
|
49
|
|
|
return result |
|
50
|
|
|
|