Skip to content

Commit 595846a

Browse files
committed
Match with the CPU implementation
1 parent 444e048 commit 595846a

File tree

3 files changed

+29
-16
lines changed

3 files changed

+29
-16
lines changed

docs/source/examples/raven_filter_example.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,44 @@
2323

2424
print("The shape of the sinogram is {}".format(cp.shape(sinogram)))
2525

26+
# Parameters
27+
v0 = 2
28+
n = 4
29+
u0 = 20
30+
2631
# Make a numpy copy
2732
sinogram_padded = np.pad(sinogram.get(), 20, "edge")
2833

2934
# GPU filter
30-
sinogram_gpu_filter = raven_filter(sinogram)
35+
sinogram_gpu_filter = raven_filter(sinogram, u0, n, v0)
3136

3237
# Size
3338
width1 = sino_shape[1] + 2 * 20
3439
height1 = sino_shape[0] + 2 * 20
3540

36-
# Parameters
37-
v0 = 2
38-
u0 = 20
39-
n = 2
40-
4141
# Generate filter function
4242
centerx = np.ceil(width1 / 2.0) - 1.0
4343
centery = np.int16(np.ceil(height1 / 2.0) - 1)
4444
row1 = centery - v0
4545
row2 = centery + v0 + 1
4646
listx = np.arange(width1) - centerx
47+
48+
print(np.arange(width1))
49+
print(listx)
50+
print(listx / u0)
51+
4752
filtershape = 1.0 / (1.0 + np.power(listx / u0, 2 * n))
4853
filtershapepad2d = np.zeros((row2 - row1, filtershape.size))
4954
filtershapepad2d[:] = np.float64(filtershape)
5055
filtercomplex = filtershapepad2d + filtershapepad2d * 1j
5156

57+
print("Centery: ", centery, "Row1: ", row1, "Row2: ", row2)
58+
59+
# plt.figure()
60+
# plt.imshow(filtercomplex.real)
61+
# plt.title("Uncorrected image")
62+
# plt.show()
63+
5264
# Generate filter objects
5365
a = pyfftw.empty_aligned((height1, width1), dtype='complex128', n=16)
5466
b = pyfftw.empty_aligned((height1, width1), dtype='complex128', n=16)

httomolibgpu/cuda_kernels/raven_filter.cu

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
extern "C" __global__ void
44
raven_filter(complex<float> *input, complex<float> *output, int width1, int height1, int u0, int n, int v0) {
55

6-
int centerx = (width1 + 1) / 2 - 1;
7-
int centery = (height1 + 1) / 2 - 1;
6+
int centerx = width1 / 2;
7+
int centery = height1 / 2;
88

99
int px = threadIdx.x + blockIdx.x * blockDim.x;
1010
int py = threadIdx.y + blockIdx.y * blockDim.y;
@@ -15,14 +15,15 @@ raven_filter(complex<float> *input, complex<float> *output, int width1, int heig
1515
return;
1616

1717
complex<float> value = input[py * width1 + px];
18-
if( py >= (centery - v0) && py <= (centery + v0 + 1) ) {
18+
if( py >= (centery - v0) && py < (centery + v0 + 1) ) {
1919

20-
double base = (px - centerx) / u0;
21-
double filtered_value = base;
20+
// +1 needed to match with CPU implementation
21+
float base = float(px - centerx + 1) / u0;
22+
float power = base;
2223
for( int i = 1; i < 2 * n; i++ )
23-
filtered_value *= base;
24+
power *= base;
2425

25-
filtered_value = 1.0f / (1.0 + filtered_value);
26+
float filtered_value = 1.f / (1.f + power);
2627
value *= complex<float>(filtered_value, filtered_value);
2728
}
2829

httomolibgpu/misc/raven_filter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@
5151

5252
def raven_filter(
5353
data: cp.ndarray,
54-
pad_y: int = 20,
55-
pad_x: int = 20,
56-
pad_method: str = "edge",
5754
uvalue: int = 20,
5855
nvalue: int = 4,
5956
vvalue: int = 2,
57+
pad_y: int = 20,
58+
pad_x: int = 20,
59+
pad_method: str = "edge",
6060
) -> cp.ndarray:
6161
"""
6262
Applies raven filter to a 3D CuPy array. For more detailed information, see :ref:`method_raven_filter`.

0 commit comments

Comments
 (0)