Clear all; clc;
% FFT Transformation
I = imread ('cameraman. tif ');
A1 = fft2 (I );
A2 = ifft2 (A1 );
A3 = uint8 (A2 );
Fig, subplot (221), imshow (I );
Subplot (222); imshow (A3 );
% DCT Transformation
I = imread ('cameraman. tif ');
Figure, subplot (223); imshow (I );
I = im2double (I );
T = dctctx (8 );
B = blkproc (I, [8 8], 'p1 * x * p2', T, T ');
Mask = [1 1 1 1 0 0 0 0
1 1 1 0 0 0 0 0
1 1 0 0 0 0 0 0
1 0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0];
B2 = blkproc (B, [8 8], 'p1. * x', mask); % here is the dot multiplication (.*)
I2 = blkproc (B2, [8 8], 'p1 * x * p2', T', t );
Subplut (224); imshow (I2 );
% Histogram balancing
I = imread ('pout. tif ');
Figure, subplot (321); imshow (I );
Subplot (1, 322); imhist (I );
[J, T] = histeq (I, 64); % scale the image to 0 ~ 255, but only 64 gray levels
Subplot (323); imshow (j );
Subplot (324); imhist (j );
J = histeq (I, 32 );
Subplot (325); imshow (j); % scale the image to 0 ~ 255, but only 32 gray levels
Subplot (326); imhist (j );
Figure, plot ()/255, T); % transformation curve of the Transfer Function
% Grayscale stretch
I = imread ('pout. tif ');
Figure, subplot (221); imshow (I );
Subplot (1, 222); imhist (I );
[X, MAP] = imread ('pout. tif ');
Y = imadjust (x, [0.1 0.99], [0 1]);
Subplot (223); imshow (Y, MAP );
Subplot (224); imhist (y );
% Image space domain processing
[I, MAP] = imread ('pout. tif ');
J1 = imnoise (I, 'gaussian ', 0, 0.02 );
% Gaussian noise with an average value of 0 and a variance of 0.02 can be replaced by localvar
% J2 = imnoise (I, 'Salt & pepper ', 0.04); % salt and pepper noise with a stack density of 0.04
M4 = [0 1 0; 1 0 1; 0 1 0];
M4 = M4/4; % 4 neighborhood average filtering
I _filter1 = filter2 (M4, J1 );
Figure, subplot (321); imshow (I );
Subplot (322); imshow (J1 );
Subplot (323); imshow (I _filter1, MAP );
M8 = [1 1 1; 1 0 1; 1 1 1]; % 8 neighborhood average filtering
M8 = M8/8;
I _filter2 = filter2 (M8, J1 );
Subplot (324); imshow (I _filter2, MAP );
K1 = medfilt2 (J1, [3, 3]);
Subplot (325); imshow (K1 );
K2 = medfilt2 (J2, [7 7]);
Subplot (326); imshow (K2 );
% Frequency domain processing
I = imread ('pout. tif ');
Figure, subplot (221); imshow (I );
J1 = imnoise (I, 'Salt & pepper '); % overlay salt and pepper noise
Subplot (222); imshow (J1 );
F = double (J1); % data type conversion. MATLAB does not support the calculation of unsigned integer types of images.
G = fft2 (f); % Fourier Transformation
G = fftshift (g); % convert the Data Matrix
[M, N] = size (g );
Nn = 2; % second-order Butterworth low-pass filter
D0 = 50;
M = fix (M/2); n = fix (n/2 );
For I = 1: m
For j = 1: N
D = SQRT (I-m) ^ 2 + (J-N) ^ 2 );
H = 1/(1 + 0.414 * (D/D0) ^ (2 * NN); % calculate the low-pass filter Transfer Function
Result (I, j) = H * g (I, j );
End
End
Result = ifftshift (result );
J2 = ifft2 (result );
J3 = uint8 (real (J2 ));
Subplot (223); imshow (J3); % display the filtered image
[I, MAP] = imread ('pout. tif ');
Fig, subplot (221); imshow (I, MAP );
H2 = [-1-1-1;-1-9-1;-1-1-1];
J1 = filter2 (H2, I); % Qualcomm Filter
Subplot (222); imshow (J1, MAP );
I = imread ('pout. tif ');
Figure, subplot (221); imshow (I );
F = double (I); % data type conversion. MATLAB does not support the calculation of the unsigned integer type of the image.
G = fft2 (f); % Fourier Transformation
G = fftshift (g); % convert the Data Matrix
[M, N] = size (g );
Nn = 2; % second-order Butterworth High Pass Filter
D0 = 5;
M = fix (M/2 );
N = fix (n/2 );
For I = 1: m
For j = 1: N
D = SQRT (I-m) ^ 2 + (J-N) ^ 2 );
If (D = 0)
H = 0;
Else
H = 1/(1 + 0.414 * (D0/d) ^ (2 * NN); % calculate the transfer function
End
Result (I, j) = H * g (I, j );
End
End
Result = ifftshift (result );
J2 = ifft2 (result );
J3 = uint8 (real (J2 ));
Subplot (222); imshow (J3); % filtered image display
End