Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
| Download
Views: 6249
License: OTHER
1
import numpy as np
2
import matplotlib.pyplot as plt
3
4
from skimage import io
5
from skimage.viewer import ImageViewer
6
from skimage.viewer.widgets import Slider
7
from skimage.viewer.plugins.base import Plugin
8
9
10
image = io.imread('../../images/clock_motion.png')
11
M, N = image.shape
12
13
## Should pad, but doesn't make much difference in this case
14
MM, NN = 2 * M + 1, 2 * N + 1
15
16
def hann(image):
17
wy = np.hanning(image.shape[0])[:, None]
18
wx = np.hanning(image.shape[1])
19
20
21
## Apply Hann window to prevent ringing
22
wy = np.hanning(M)[:, None]
23
wx = np.hanning(N)
24
25
f = np.zeros((MM, NN))
26
f[:M, :N] = wy * wx * image
27
28
F = np.fft.fft2(f)
29
30
v, u = np.ogrid[:MM, :NN]
31
v -= (MM - 1) // 2
32
u -= (NN - 1) // 2
33
34
35
def apply_inverse_filter(image, T, a, b, K=5, clip=500):
36
uavb = u * a + v * b
37
H = T * np.sinc(uavb) * np.exp(-1j * np.pi * uavb)
38
H = np.fft.fftshift(H)
39
40
HH = 1./H
41
HH[np.abs(HH) > K] = K
42
43
gg = np.abs(np.fft.ifft2(F * HH))
44
gg = gg[:M, :N]
45
gg = np.clip(gg, 0, clip)
46
gg -= gg.min()
47
gg /= gg.max()
48
49
return gg
50
51
viewer = ImageViewer(image)
52
53
plugin = Plugin(image_filter=apply_inverse_filter)
54
plugin += Slider('T', 0, 1, value=0.5, value_type='float', update_on='release')
55
plugin += Slider('a', -0.1, 0.1, value=0, value_type='float', update_on='release')
56
plugin += Slider('b', -0.1, 0.1, value=0, value_type='float', update_on='release')
57
plugin += Slider('K', 0, 100, value=15, value_type='float', update_on='release')
58
plugin += Slider('clip', 0, 1000, value=750, value_type='float', update_on='release')
59
viewer += plugin
60
viewer.show()
61
62