Matlab Learning 12-Image Enhancement for Image Processing


foreword

The basic idea of ​​image enhancement is
to allow a certain frequency to pass (retain some frequency components), limit or reduce other frequencies (eliminate some frequency components).
The quality of the transfer function is the key to the quality of the filter.
According to the filtering characteristics, especially the frequency components that are eliminated or retained, the frequency domain enhancement methods can be divided into:

- Low-pass filtering
Basic principle:
keep the low-frequency components in the image and remove the high-frequency components.
Function:
to remove or weaken the influence of noise and blur the edge contour, which belongs to image smoothing processing technology. Because: the edge and noise in the image correspond to the high frequency part in the Fourier spectrum of the image.
Including:
Ideal Low-Pass Filter (ILPF)
Butterworth Low-Pass Filter (BLPF)
Exponential Low-Pass Filter (ELPF)
Ladder Low-Pass Filter (TLPF)
Gaussian Low-Pass Filter (GLPF)
-
The basic principle of high-pass filtering
is to retain the high-frequency components in the image and remove the low-frequency components.
Function:
Highlight the edge contour of the object, which belongs to the image sharpening processing technology.
Because: the edge in the image corresponds to the high frequency part in the Fourier spectrum of the image.
Effect:
The edge of the object is sharpened, but the gray level of the smooth area is weakened, darkened or even close to black.
Because: most of the energy in the image is concentrated in the low-frequency components, and the high-pass filter will filter out most of the low-frequency components.
Including:
Ideal High Pass Filter (IHPF)
Butterworth High Pass Filter (BHPF)
Exponential High Pass Filter (EHPF)
Trapezoidal High Pass Filter (THPF) Gaussian
High Pass Filter (GHPF)
High Frequency Enhancement Filter
·High Frequency Lifting Filter
- Band Pass & Band Stop Filter
- Homomorphic Filter

1. Ideal low-pass filter

Effect
insert image description here

the code

%理想低通滤波
f1xy=imread("img/eight.tif");
subplot(2,3,1),imshow(f1xy),xlabel("(a)原始图像");

f2xy=imnoise(f1xy,'salt & pepper',0.05);
subplot(2,3,2),imshow(f2xy),xlabel("(b)噪声图像");


fxy=double(f2xy);
Fuv=fft2(fxy);
FftShift=fftshift(Fuv);
AbsFftShift=abs(FftShift);
LogAbsFftShift=log(AbsFftShift);
subplot(2,3,3),imshow(LogAbsFftShift,[]),xlabel("(c)噪声图像的傅里叶幅度谱对数图像"),colormap(gray),colorbar;

%图的尺寸
[N1,N2]=size(FftShift);
% 截至频率D0=50时的滤波效果
D0=50;
%中心点
n1=fix(N1/2);
n2=fix(N2/2);
for i=1:N1
    for j=1:N2
        d=sqrt((i-n1)^2+(j-n2)^2);
        if(d<D0)
            G(i,j)=FftShift(i,j);
        else
            G(i,j)=0;
        end
    end
end
% 反变换
G=ifftshift(G);
g=ifft2(G);
g=uint8(real(g));
subplot(2,3,4),imshow(g),xlabel("(d)滤波图像(D0=50)");



D0=80;
for i=1:N1
    for j=1:N2
        d=sqrt((i-n1)^2+(j-n2)^2);
        if(d<D0)
            G(i,j)=FftShift(i,j);
        else
            G(i,j)=0;
        end
    end
end
% 反变换
G=ifftshift(G);
g=ifft2(G);
g=uint8(real(g));
subplot(2,3,6),imshow(g),xlabel("(e)滤波图像(D0=80)");

2. Butterworth low-pass filter

Effect
insert image description here

the code

% 巴特沃斯低通滤波
f1xy=imread("img/eight.tif");
subplot(2,3,1),imshow(f1xy),xlabel("(a)原始图像");

f2xy=imnoise(f1xy,'salt & pepper',0.05);
subplot(2,3,2),imshow(f2xy),xlabel("(b)噪声图像");

% 傅里叶变换
fxy=double(f2xy);
Fuv=fft2(fxy);
FftShift=fftshift(Fuv);
AbsFftShift=abs(FftShift);
LogAbsFftShift=log(AbsFftShift);
subplot(2,3,3),imshow(LogAbsFftShift,[]),xlabel("(c)噪声图像的傅里叶幅度谱对数图像"),colormap(gray),colorbar;

[N1,N2]=size(FftShift);

% 阶数n=2,截至频率D0=40时的滤波效果
n=2;
D0=40;
%中心点
n1=fix(N1/2);
n2=fix(N2/2);
for i=1:N1
    for j=1:N2
        d=sqrt((i-n1)^2+(j-n2)^2);
        H=1/(1+(sqrt(2)-1)*(d/D0)^(2*n));
        G(i,j)=H*FftShift(i,j);
    end
end
% 反变换
G=ifftshift(G);
g=ifft2(G);
g=uint8(real(g));
subplot(2,3,4),imshow(g),xlabel("(d)滤波图像({\itn}=2,{\itD}0=40)");


% 阶数n=2,截至频率D0=60时的滤波效果
n=2;
D0=60;
%中心点
n1=fix(N1/2);
n2=fix(N2/2);
for i=1:N1
    for j=1:N2
        d=sqrt((i-n1)^2+(j-n2)^2);
        H=1/(1+(sqrt(2)-1)*(d/D0)^(2*n));
        G(i,j)=H*FftShift(i,j);
    end
end
% 反变换
G=ifftshift(G);
g=ifft2(G);
g=uint8(real(g));
subplot(2,3,6),imshow(g),xlabel("(e)滤波图像(n=2,D0=60)");

3. Gaussian high-pass filter

Effect
insert image description here

the code

% 高斯高通滤波
fxy=imread("img/lena.bmp");
subplot(2,2,1),imshow(fxy),xlabel("(a)原始图像");

% 傅里叶幅度谱的对数图像显示
fxy=double(fxy);
Fuv=fft2(fxy);%二维傅里叶变换
ShiftFuv=fftshift(Fuv);
AbsShiftFuv=abs(ShiftFuv);%傅里叶幅度谱
LogAbsShiftFuv=log(AbsShiftFuv);%傅里叶幅度谱可视化
subplot(2,2,2),imshow(LogAbsShiftFuv,[]),xlabel("(b)傅里叶幅度谱对数图像");



% 截至频率D0=10时的滤波效果
[N1,N2]=size(ShiftFuv);
D0=10;
%中心点
n1=fix(N1/2);
n2=fix(N2/2);
for i=1:N1
    for j=1:N2
        d=sqrt((i-n1)^2+(j-n2)^2);
        Huv=1-exp(-d^2/(2*D0^2));% 高斯高通公式
        G(i,j)=Huv*ShiftFuv(i,j);
    end
end
% 反变换
G=ifftshift(G);
g=ifft2(G);
g=uint8(real(g));
subplot(2,2,3),imshow(g),xlabel("(c)滤波图像(D0=10)");

% 截至频率D0=20时的滤波效果
[N1,N2]=size(ShiftFuv);
D0=20;
%中心点
n1=fix(N1/2);
n2=fix(N2/2);
for i=1:N1
    for j=1:N2
        d=sqrt((i-n1)^2+(j-n2)^2);
        Huv=1-exp(-d^2/(2*D0^2));
        G(i,j)=Huv*ShiftFuv(i,j);
    end
end
% 反变换
G=ifftshift(G);
g=ifft2(G);
g=uint8(real(g));
subplot(2,2,4),imshow(g),xlabel("(d)滤波图像(D0=20)");

Summarize

The relationship between frequency domain enhancement and spatial domain enhancement

Spatial filtering enhancement is divided into smoothing filtering and sharpening filtering. From the point of view of space domain,
smoothing filter can reduce the local gray scale fluctuation and noise interference;
domain filter.

The basic principle of spatial filtering enhancement is to use the convolution of the image and the template.
·According to the convolution theorem, the convolution of the image and the template in the space domain is equal to the product of the Fourier transform of the image and the Fourier transform of the template in the frequency domain.
According to the basic principle of image frequency domain enhancement, frequency domain image enhancement is the product of frequency domain original image and frequency domain transfer function, that is, the product of the Fourier transform of the image and frequency domain transfer function.
Click to get the source code

Guess you like

Origin blog.csdn.net/CHengYuP/article/details/125986252
Recommended