-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathplot_fft_image_denoise.py
62 lines (44 loc) · 1.55 KB
/
plot_fft_image_denoise.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
from pathlib import Path
import numpy
from matplotlib import pyplot
from neodroidvision.regression.patching.denoise import fft_im_denoise
if __name__ == "__main__":
def plot_spectrum(im_fft):
"""
:param im_fft:
:type im_fft:"""
from matplotlib.colors import LogNorm
# A logarithmic colormap
pyplot.imshow(numpy.abs(im_fft), norm=LogNorm(vmin=5))
pyplot.colorbar()
def blur_im(im):
"""
:param im:
:type im:"""
############################################################
# Easier and better: :func:`scipy.ndimage.gaussian_filter`
############################################################
#
# Implementing filtering directly with FFTs is tricky and time consuming.
# We can use the Gaussian filter from :mod:`scipy.ndimage`
from scipy import ndimage
im_blur = ndimage.gaussian_filter(im, 4)
pyplot.figure()
pyplot.imshow(im_blur, pyplot.cm.gray)
pyplot.title("Blurred image")
def main(im_raw):
"""
:param im_raw:
:type im_raw:"""
pyplot.figure()
pyplot.imshow(im_raw, pyplot.cm.gray)
pyplot.title("Original image")
im_denoised = fft_im_denoise(im_raw)
pyplot.figure()
pyplot.imshow(im_denoised, pyplot.cm.gray)
pyplot.title("Reconstructed Image")
im22 = pyplot.imread(
str(Path.home() / "Data" / "Datasets" / "Denoise" / "moonlanding.png")
).astype(float)
main(im22)
pyplot.show()