-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfft_Butterworth_filtering.pro
More file actions
161 lines (126 loc) · 4.91 KB
/
Copy pathfft_Butterworth_filtering.pro
File metadata and controls
161 lines (126 loc) · 4.91 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
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
PRO FFT_BUTTERWORTH_FILTERING
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; This procedure performes imaeg filtering in the Fourier domain via
; Low-pass and High-pass Butterworth frequency filters
;
; WARNING: Operate ON A GRAYSCALE IMAGE ONLY!
;
; Input: -
; Output: -
; External calls: CENTER_WINDOW_POS
;
; Programmer: Daniel Molina García (based on M. Messerotti's examples)
; Creation date: -
; Environment: i686 GNU/Linux 2.6.32-34-generic Ubuntu
; Modified: -
; Version: 0.1
;
; License: Copyright 2011 Daniel Molina García
;
; This program is free software: you can redistribute it
; and/or modify it under the terms of the GNU General Public
; License as published by the Free Software Foundation,
; either version 3 of the License, or (at your option) any
; later version.
;
; This program is distributed in the hope that it will be
; useful, but WITHOUT ANY WARRANTY; without even the implied
; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
; PURPOSE. See the GNU General Public License for more
; details.
;
; You should have received a copy of the GNU General Public
; License along with this program. If not, see
; <http://www.gnu.org/licenses/>.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Set indexed colortable display
DEVICE, DECOMPOSED = 0
; Read in "Mars" image from file and convert it to grayscale
READ_JPEG, !DIR + '/examples/data/marsglobe.jpg', image, $
/GRAYSCALE
; Determine image size
image_size = SIZE(image)
x_size = image_size[1]
y_size = image_size[2]
; Derive centered window position with x size to host 2 quadrants
CENTER_WINDOW_POS, 2 * x_size, y_size, x_win_pos, y_win_pos
; Load grayscale palette
LOADCT, 0
; Open graphic window
WINDOW, 1, XSIZE = (2 * x_size), YSIZE = y_size, XPOS = x_win_pos, YPOS = y_win_pos, $
TITLE = 'Original Grayscale Image and its Fourier Spectrum'
; Display original image in left quadrant
TV, image, 0, 0
; Compute FFT of image
image_fft = FFT(image)
; Display Fourier Spectrum in right quadrant
TV, HIST_EQUAL(SHIFT((ABS(image_fft)), x_size / 2, y_size / 2)), x_size, 0
PRESS_MOUSE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Low-Pass Butterworth frequency filter
; n = 2 Filter order
; C = 1.0 Filter magnitude 50% at point R=R0
; C = 0.414 Filter magnitude 1/SQRT(2)
; LPB_filter = 1 / (1 + C * (R / R0))^(2*n)
; with R - frequency image and R0 - nominal filter cut-off
; frequency
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Define filter parameters
n = 2
c = 1.0
r = DIST(x_size, y_size)
r0 = 15.0
; Compute filter mask
n = 2
lpb_filter = 1.0 / (1.0D + C * (R/R0))^(2*n)
; Display filter mask (resampled for better display)
WINDOW, 1, XSIZE = (2 * x_size), YSIZE = y_size, XPOS = x_win_pos, YPOS = y_win_pos, $
TITLE = 'Low-Pass Butterworth Filter Mask (3-D and 2-D View)'
SURFACE, CONGRID(SHIFT(LPB_filter, x_size / 2, y_size / 2), 100, 100), $
INDGEN(x_size / 4.) * 4., INDGEN(y_size / 4.) * 4., AZ = 15, $
CHARSIZE = 2.0, POS = [0.05, 0.05, 0.45, 0.95]
TVSCL, (SHIFT(lpb_filter, x_size / 2., y_size / 2)), x_size, 0
PRESS_MOUSE
; Apply filter mask in Fourier domain and inverse transform the masked
; domain
filtered = REAL_PART(fft(image_fft * lpb_filter, 1))
; Display filtered image and its Fourier spectrum
WINDOW, 1, XSIZE = (2 * x_size), YSIZE = y_size, XPOS = x_win_pos, YPOS = y_win_pos, $
TITLE = 'Low-Pass Butterworth Filtered Image and its Fourier Spectrum'
TV, filtered, 0, 0
TV, HIST_EQUAL(SHIFT(ABS(FFT(filtered)), x_size / 2, y_size / 2)), x_size, 0
PRESS_MOUSE
;;;;;;;;;;;;;;;;;;;;,
; High-Pass Butterworth frequency filter
;
; HPB_filter = 1 / (1 + C * (R0 / R))^(2*n)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Define filter parameters
n = 2
c = 1.0
r = DIST(x_size, y_size)
r0 = 50.0
; Compute filter mask
n = 2
hpb_filter = 1.0 / (1.0D + C * (R0/R))^(2*n)
; Display filter mask (resampled for better display)
WINDOW, 1, XSIZE = (2 * x_size), YSIZE = y_size, XPOS = x_win_pos, YPOS = y_win_pos, $
TITLE = 'High-Pass Butterworth Filter Mask (3-D and 2-D View)'
SURFACE, CONGRID(SHIFT(HPB_filter, x_size / 2, y_size / 2), 100, 100), $
INDGEN(x_size / 4.) * 4., INDGEN(y_size / 4.) * 4., AZ = 15, $
CHARSIZE = 2.0, POS = [0.05, 0.05, 0.45, 0.95]
TVSCL, (SHIFT(hpb_filter, x_size / 2., y_size / 2)), x_size, 0
PRESS_MOUSE
; Apply filter mask in Fourier domain and inverse transform the masked
; domain
filtered = REAL_PART(fft(image_fft * hpb_filter, 1))
; Display filtered image and its Fourier spectrum
WINDOW, 1, XSIZE = (2 * x_size), YSIZE = y_size, XPOS = x_win_pos, YPOS = y_win_pos, $
TITLE = 'High-Pass Butterworth Filtered Image and its Fourier Spectrum'
TV, filtered, 0, 0
TV, HIST_EQUAL(SHIFT(ABS(FFT(filtered)), x_size / 2, y_size / 2)), 1
PRESS_MOUSE
WDELETE
END