-
Notifications
You must be signed in to change notification settings - Fork 0
/
display_functions.py
63 lines (46 loc) · 2.04 KB
/
display_functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from tomographic_functions import *
from Filter_Pict import result_visualisation
def animate_transform(original_image):
fig = plt.figure()
npImage = np.array(original_image)
floatImage = ImageMath.eval("float(a)", a=original_image)
steps = original_image.size[0]
radon = np.zeros((steps, len(npImage)), dtype='float64')
images = []
for step in range(steps):
rotation = floatImage.rotate(-step * 180 / steps)
npRotate = np.array(rotation)
radon[:, step] = sum(npRotate)
image = plt.imshow(radon, cmap="gray", animated=True)
images.append([image])
ani = animation.ArtistAnimation(fig, images, interval=50, blit=False, repeat=False)
writergif = animation.PillowWriter(fps=30)
ani.save("TransformAnimation.gif", writer=writergif)
plt.show()
def animate_reconstruction(original_image):
fig = plt.figure()
radon_image = radon_transform(original_image)
images = []
for i in range(181):
reconstructed_image = inverse_radon_transform(radon_image, i)
image = plt.imshow(reconstructed_image, cmap="gray", animated=True)
images.append([image])
# print(i)
ani = animation.ArtistAnimation(fig, images, interval=50, blit=False, repeat=False)
writergif = animation.PillowWriter(fps=30)
ani.save("ReconstructionAnimation.gif", writer=writergif)
plt.show()
def show_all_images(original_image, steps=180):
radon_image = radon_transform(original_image)
reconstructed_image = inverse_radon_transform(radon_image, steps)
result_visualisation(reconstructed_image.reshape(1, -1))
fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(15, 5))
ax1.imshow(original_image, cmap="gray")
ax1.set_title("Original Image")
ax2.imshow(radon_image, cmap="gray")
ax2.set_title("Sinogram")
ax3.imshow(reconstructed_image, cmap="gray")
ax3.set_title("Reconstructed Image")
plt.show()