Text Figure (4.2) 1D Discrete Fourier Transform
Text Figure (4.2) 1D Discrete Fourier Transform
Text Figure (4.2) 1D Discrete Fourier Transform
xlabel('x');
in (a)'); xlabel('u');
xlabel('x');
in (c)'); xlabel('u');
0.1
0.8
0.08
0.6
0.06
|F(u)|
f(x)
0.4
0.04
0.2
0.02
20
40
60
80
100
20
40
60
80
100
0.2
0.8
0.15
0.6
|F(u)|
f(x)
0.1
0.4
0.05
0.2
0
20
40
60
x
80
100
20
40
60
u
80
100
4.4)
%Matlab Code
close all; clear all;
img = imread('Fig4.03(a).jpg');
imgfft = abs(fftshift(fft2(img)));
figure;
subplot(1,2,1);
imshow(img);
subplot(1,2,2);
imshow(imscale01(log10(imgfft+1)));
%Matlab Code
close all; clear all;
img = imread('Fig4.04(a).jpg');
imgfft = fftshift(fft2(img));
imgfft(size(img,1)/2+1, size(img,2)/2+1) = 0;
imgfilt = abs((ifft2(imgfft)));
figure;
imshow(imscale01(imgfilt));
%Matlab Code
close all; clear all;
img = imread('Fig4.04(a).jpg');
[x,y] = size(img);
lp = zeros(size(img));
cx = x/2; cy = y/2; std = 30;
for i=1:x; for j=1:y;
lp(i,j) = exp(-[(i-cx)^2 + (j-cy)^2]/std^2);
end end
hp = 1-lp;
lpplot = lp(1:8:x, 1:8:y); hpplot = hp(1:8:x, 1:8:y);
imglp = fftshift(fft2(img)); imglp = imglp .* lp;
imghp = imglp; imghp = imghp .* hp;
imglp = abs((ifft2(imglp))); imghp = abs((ifft2(imghp)));
figure;
subplot(2,2,1);
subplot(2,2,2);
subplot(2,2,3);
subplot(2,2,4);
%Matlab Code
close all; clear all;
img = imread('Fig4.04(a).jpg');
[x,y] = size(img);
lp = zeros(size(img));
cx = x/2; cy = y/2; std = 30;
for i=1:x;
for j=1:y;
lp(i,j) = exp(-[(i-cx)^2 + (j-cy)^2]/std^2);
end
end
hp = 1-lp; hp = hp + 0.5*max(hp(:));
imghp = fftshift(fft2(img)); imghp = imghp .* hp;
imghp = abs((ifft2(imghp)));
figure; imshow(imscale01(imghp));
%Matlab Code
close all; clear all;
img = zeros(500,500);
x = 500; y = 500;
cx = 250; cy = 250;
for i=1:x;
for j=1:y;
if(sqrt([i-cx]^2 + [j-cy]^2) < 5)
img(i,j) = 1;
end
end
end
imgfft = (fftshift(ifft2(img)));
a = ones(1,500);
a(1:2:500) = -1;
plota = real(imgfft(250,:)).*a;
img2
= zeros(size(img));
img2(128,128) = 1; img2(128, 500-128) = 1; img2(250, 250) = 1; img2(500-128, 128) = 1;
img2(500-128, 500-128) = 1; img3 = conv2(img2, imgfft,'same');
idx = 1:size(img,2)+1:length(img(:));
plotb = real(img3(idx));
figure;
subplot(3,2,1);
subplot(3,2,2);
subplot(3,2,3);
subplot(3,2,4);
subplot(3,2,5);
subplot(3,2,6);
imshow(imscale01(img));
plot((plota)); axis tight;
imshow(imscale01(0.5*log10(abs(imgfft)+1)));
imshow(imscale01(img2));
plot((plotb)); axis tight;
imshow(imscale01(0.5*log10(abs(img3)+1)));
-4
x 10
2
1
0
100
200
-4
x 10
2
1
0
100
200
300
400
500
300
400
500
imshow(imscale01(20*log10(1+h1)));
imshow(imscale01(20*log10(1+h2)));
imshow(imscale01(20*log10(1+h5)));
imshow(imscale01(20*log10(1+h20)));
plot(h1(250,:)); axis tight;
plot(h2(250,:)); axis tight;
plot(h5(250,:)); axis tight;
plot(h20(250,:)); axis tight;
-4
-4
x 10
-4
-4
x 10
x 10
x 10
3
3
15
2.5
2.5
5
1
400
1.5
1.5
200
10
200
400
0.5
0.5
200
400
200
400
= H5;
= abs(ifft2(H15.*imgfft));
= abs(ifft2(H80.*imgfft));
figure;
subplot(3,2,1); imshow(imscale01(img)); subplot(3,2,2); imshow(imscale01(h5));
subplot(3,2,3); imshow(imscale01(h15)); subplot(3,2,4); imshow(imscale01(h30));
subplot(3,2,5); imshow(imscale01(h80)); subplot(3,2,6); imshow(imscale01(h230));
imshow(imscale01(img(380:460,380:460)));
imshow(imscale01(h100(380:460,380:460)));
imshow(imscale01(h80(380:460,380:460)));
imshow(imscale01(img));
imshow(imscale01(h100));
imshow(imscale01(h80));
imshow(imscale01(img));
imshow(imscale01(abs(lapimg)));
imshow(imscale01((real(lapimg))));
imshow(imscale01(real(img - abs(lapimg))));
%Matlab Code Note: I used a Gaussian HP Filter since I dont trust my Laplacian
close all; clear all;
img
= im2double(imread('Fig4.29(a).jpg'));
imgfft = fftshift(fft2(img));
[x,y] = size(img); cx = x/2; cy = y/2;
k = zeros(x,y);
for i=1:x;
for j=1:y;
D(i,j)
= sqrt([i-cx]^2 + [j-cy]^2);
k(i,j) = (-1)^(i+j);
end
end
H
= 1-exp(-.5*[D/50].^2);
himg = real(ifft2(H.*imgfft)).*k;
img1
= img + himg;
img17
= 1.7*img + himg;
figure;
subplot(2,2,1);
subplot(2,2,2);
subplot(2,2,3);
subplot(2,2,4);
imshow(imscale01(img));
imshow(imscale01(himg));
imshow(imscale01(img1));
imshow(imscale01(img17));
%Matlab Code
close all; clear all;
img
= im2double(imread('Fig4.30(a).jpg'));
imgfft = fftshift(fft2(img));
BHPF
= zeros(size(imgfft));
x = size(BHPF,1); y = size(BHPF,2); cx = x/2; cy = y/2;
Do = floor(0.05*x);
for i=1:x;
for j=1:y;
D(i,j)
= sqrt([i-cx]^2 + [j-cy]^2);
if(D(i,j) == 0) D(i,j)=0.01; end
BHPF(i,j) = 1 / (1 + [Do/D(i,j)]^(4));
end
end
imgBHPF = abs(ifft2(imgfft .* (BHPF)));
imgHFE
= abs(ifft2(imgfft .* (0.5 + 2*BHPF)));
imgHFEeq = floor(255*imscale01(imgHFE));
[hist1, bins1] = hist(double(imgHFEeq(:)),0:255);
hist1 = hist1./length(imgHFEeq(:));
CDF1 = cumsum(hist1);
img1eq = zeros(size(imgHFEeq));
for i=0:255
img1eq(find(imgHFEeq==i)) = CDF1(i+1);
end
figure;
subplot(2,2,1);
subplot(2,2,2);
subplot(2,2,3);
subplot(2,2,4);
imshow(imscale01(img));
imshow(imgBHPF+.4);
imshow(imscale01(imgHFE));
imshow(imscale01(img1eq));
Original Image
Acknowledge: I would like to thank my former student Brad Ratliff for providing these
images.