-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathexample_oversampling.py
More file actions
34 lines (31 loc) · 1.1 KB
/
example_oversampling.py
File metadata and controls
34 lines (31 loc) · 1.1 KB
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
import numpy as np
import imageio
import matplotlib.pyplot as plt
from phase_retrieval import fienup_phase_retrieval
np.random.seed(12345)
image = imageio.imread('cameraman.png', as_gray=True)
magnitudes = np.abs(np.fft.fft2(image))
result = fienup_phase_retrieval(magnitudes,
steps=1000,
verbose=False)
image_padded = np.pad(image, 128, 'constant')
magnitudes_oversampled = np.abs(np.fft.fft2(image_padded))
mask = np.pad(np.ones((256,256)), 128, 'constant')
result_oversampled = fienup_phase_retrieval(magnitudes_oversampled,
steps=1000,
mask=mask,
verbose=False)
plt.figure(figsize=(10,10))
plt.subplot(221)
plt.imshow(image, cmap='gray')
plt.title('Image')
plt.subplot(222)
plt.imshow(result, cmap='gray')
plt.title('Result')
plt.subplot(223)
plt.imshow(image_padded, cmap='gray')
plt.title('Image padded')
plt.subplot(224)
plt.imshow(result_oversampled, cmap='gray');
plt.title('Reconstruction oversampled')
plt.show()