Line | |
---|
1 | function J=imwhiten(I,alpha,cutoff) |
---|
2 | % IMWHITEN Whiten image |
---|
3 | % J = IMWHITEN(I,ALPHA,CUTOFF) approximatively whitens the power |
---|
4 | % spectrum of the natural image I. The algorithm assumes that the |
---|
5 | % modulus of the spectrum decays as 1/f^ALPHA (f is the frequency). |
---|
6 | % |
---|
7 | % IMWHITEN(I) uses ALPHA=1 (typical value for natural images). |
---|
8 | % |
---|
9 | % IMWHITEN(I,ALPHA,CUTOFF) also applies a low-pass filter with cutoff |
---|
10 | % frequency equal to CUTOFF x FN, where FN is the Nyquist |
---|
11 | % frequency (half of the sampling frequency). |
---|
12 | % |
---|
13 | |
---|
14 | if ~exist('alpha'), alpha = 1 ; end |
---|
15 | if ~exist('cutoff'), cutoff = [] ; end |
---|
16 | |
---|
17 | [M,N]=size(I) ; |
---|
18 | |
---|
19 | % Frequency domain |
---|
20 | fn = 0.5 ; % Nyquist freq (=1/2T, T=1) |
---|
21 | fx_range=linspace(-fn, fn, N) ; |
---|
22 | fy_range=linspace(-fn, fn, M) ; |
---|
23 | [fx fy]=meshgrid(fx_range, fy_range) ; |
---|
24 | |
---|
25 | % Whitening filter |
---|
26 | rho=sqrt(fx.*fx+fy.*fy); |
---|
27 | filt=rho ; |
---|
28 | |
---|
29 | % Low-pass filter |
---|
30 | if ~isempty(cutoff) |
---|
31 | fcut = cutoff * fn ; |
---|
32 | filt = filt .* exp(-(rho/fcut).^4); |
---|
33 | end |
---|
34 | |
---|
35 | % Apply filter |
---|
36 | J = real(ifft2(fft2(I).*fftshift(filt))) ; |
---|
Note: See
TracBrowser
for help on using the repository browser.