|
5 | 5 | import pyfftw |
6 | 6 | import pyfftw.interfaces.numpy_fft as fft |
7 | 7 | import httomolibgpu |
8 | | -from httomolibgpu.misc.raven_filter import raven_filter |
| 8 | +from httomolibgpu.prep.stripe import raven_filter |
9 | 9 |
|
10 | 10 | import matplotlib.pyplot as plt |
11 | 11 | import time |
|
23 | 23 |
|
24 | 24 | sino_shape = sinogram.shape |
25 | 25 |
|
26 | | -print("The shape of the sinogram is {}".format(cp.shape(sinogram))) |
| 26 | +sinogram_stack = cp.stack([sinogram] * 20, axis=1) |
| 27 | + |
| 28 | +print("The shape of the sinogram stack is {}".format(cp.shape(sinogram_stack))) |
27 | 29 |
|
28 | 30 | # Parameters |
29 | 31 | v0 = 2 |
30 | 32 | n = 4 |
31 | 33 | u0 = 20 |
32 | 34 |
|
33 | 35 | # Make a numpy copy |
34 | | -sinogram_padded = np.pad(sinogram.get(), 20, "edge") |
| 36 | +sinogram_padded = np.pad(sinogram_stack.get(), [(20, 20), (0, 0), (20, 20)], "edge") |
35 | 37 |
|
36 | 38 | start_time = time.time() |
37 | 39 | # GPU filter |
38 | | -sinogram_gpu_filter = raven_filter(sinogram, u0, n, v0) |
| 40 | +sinogram_gpu_filter = raven_filter(sinogram_stack, u0, n, v0) |
39 | 41 | print("--- %s seconds ---" % (time.time() - start_time)) |
40 | 42 |
|
41 | 43 | start_time = time.time() |
42 | 44 |
|
43 | 45 | # Size |
44 | | -width1 = sino_shape[1] + 2 * 20 |
45 | | -height1 = sino_shape[0] + 2 * 20 |
| 46 | +height, images, width = sinogram_padded.shape |
46 | 47 |
|
47 | 48 | # Generate filter function |
48 | | -centerx = np.ceil(width1 / 2.0) - 1.0 |
49 | | -centery = np.int16(np.ceil(height1 / 2.0) - 1) |
| 49 | +centerx = np.ceil(width / 2.0) - 1.0 |
| 50 | +centery = np.int16(np.ceil(height / 2.0) - 1) |
50 | 51 | row1 = centery - v0 |
51 | 52 | row2 = centery + v0 + 1 |
52 | | -listx = np.arange(width1) - centerx |
| 53 | +listx = np.arange(width) - centerx |
53 | 54 | filtershape = 1.0 / (1.0 + np.power(listx / u0, 2 * n)) |
54 | 55 | filtershapepad2d = np.zeros((row2 - row1, filtershape.size)) |
55 | 56 | filtershapepad2d[:] = np.float64(filtershape) |
56 | 57 | filtercomplex = filtershapepad2d + filtershapepad2d * 1j |
57 | 58 |
|
58 | 59 | # Generate filter objects |
59 | | -a = pyfftw.empty_aligned((height1, width1), dtype='complex128', n=16) |
60 | | -b = pyfftw.empty_aligned((height1, width1), dtype='complex128', n=16) |
61 | | -c = pyfftw.empty_aligned((height1, width1), dtype='complex128', n=16) |
62 | | -d = pyfftw.empty_aligned((height1, width1), dtype='complex128', n=16) |
63 | | -fft_object = pyfftw.FFTW(a, b, axes=(0, 1)) |
64 | | -ifft_object = pyfftw.FFTW(c, d, axes=(0, 1), direction='FFTW_BACKWARD') |
| 60 | +a = pyfftw.empty_aligned((height, images, width), dtype='complex128', n=16) |
| 61 | +b = pyfftw.empty_aligned((height, images, width), dtype='complex128', n=16) |
| 62 | +c = pyfftw.empty_aligned((height, images, width), dtype='complex128', n=16) |
| 63 | +d = pyfftw.empty_aligned((height, images, width), dtype='complex128', n=16) |
| 64 | +fft_object = pyfftw.FFTW(a, b, axes=(0, 2)) |
| 65 | +ifft_object = pyfftw.FFTW(c, d, axes=(0, 2), direction='FFTW_BACKWARD') |
| 66 | + |
| 67 | +sino = fft.fftshift(fft_object(sinogram_padded), axes=(0, 2)) |
| 68 | +for m in range(sino.shape[1]): |
| 69 | + sino[row1:row2, m] = sino[row1:row2, m] * filtercomplex |
| 70 | +sino = ifft_object(fft.ifftshift(sino, axes=(0, 2))) |
65 | 71 |
|
66 | | -sino = fft.fftshift(fft_object(sinogram_padded)) |
67 | | -sino[row1:row2] = sino[row1:row2] * filtercomplex |
68 | | -sino = ifft_object(fft.ifftshift(sino)) |
| 72 | +# Remove padding |
| 73 | +sino = sino[20:height-20, :, 20:width-20] |
69 | 74 |
|
70 | 75 | print("--- %s seconds ---" % (time.time() - start_time)) |
71 | 76 |
|
72 | 77 | #subplot(r,c) provide the no. of rows and columns |
73 | 78 | f, axarr = plt.subplots(2,2) |
74 | 79 |
|
| 80 | +sino_index = 10 |
| 81 | + |
75 | 82 | # use the created array to output your multiple images. In this case I have stacked 4 images vertically |
76 | | -axarr[0, 0].imshow(sinogram_padded) |
| 83 | +axarr[0, 0].imshow(sinogram_stack.get()[:, sino_index, :]) |
77 | 84 | axarr[0, 0].set_title('Original sinogram') |
78 | | -axarr[0, 1].imshow(sinogram_padded - sinogram_gpu_filter.get().real) |
| 85 | +axarr[0, 1].imshow(sinogram_stack.get()[:, sino_index, :] - sinogram_gpu_filter.get().real[:, sino_index, :]) |
79 | 86 | axarr[0, 1].set_title('Difference of original and GPU filtered') |
80 | | -axarr[1, 0].imshow(sinogram_padded - sino.real) |
| 87 | +axarr[1, 0].imshow(sinogram_stack.get()[:, sino_index, :] - sino.real[:, sino_index, :]) |
81 | 88 | axarr[1, 0].set_title('Difference of original and CPU filtered') |
82 | | -axarr[1, 1].imshow(sinogram_gpu_filter.get().real - sino.real) |
| 89 | +axarr[1, 1].imshow(sinogram_gpu_filter.get().real[:, sino_index, :] - sino.real[:, sino_index, :]) |
83 | 90 | axarr[1, 1].set_title('Difference of GPU and CPU filtered') |
84 | 91 |
|
85 | 92 | plt.show() |
|
0 commit comments