哈工大深研院数字图像处理第一次大作业:不调用Matlab函数实现图像增强

写完作业了过来Mark一记~

题目是:

Image Enhancement
1. Histogram Equalization: Write a program for computing the histogram of the image (a) and implement the histogram equalization technique as we discussed in the class.

2. Remove the noise from the image (c). 

3. Filtering in the Frequency Domain: Implement the Gaussian highpass filters on test image (e).

Attention:
1. Don’t use any commercial tools such as matlab functions, Open CV or other library (except FFT functions). Please do it by c/c++, java or other languages.
2. Source codes and projects are required when you submit your report. Submitting names will be ‘Pro1_studentnumber_name.zip/rar’.
3. Each student should independently finish this work. 
4. Deadline: 2016-04-20.
5. All test images can be downloaded from the QQ group.

而本宝宝的报告是:

汇报人:张常乐 学号:15S158746 班级:电子与通信工程
程序清单:
1.Histogram_Equalization.m
2.Noise_Remove.m
3.Gaussian_Highpass_Filtering.m
程序说明:
1.依据灰度直方图均衡化处理原理,我首先得到了原始图像的灰度直方图Fig.1(a),从图像中我们可以看到,图像灰度集中分布于灰度值较低的区域,表现在图像上Fig.2我们可以看出整幅图像颜色昏暗,对比度不高,为了解决这个问题,我们采用图像直方图均衡化的处理方法,分别计算出每个灰度出现的频率和概率,并利用离散积分函数:S_k=(L-1)/MN ∑_(j=0)^(k-1)▒n_j ,k=0,1,2,…,L-1(1)
计算出灰度的累积分布情况。利用这个分布,构造出原始灰度向均衡化灰度转换的映射关系,并利用这种映射关系来对灰度图像进行均衡化处理。最终可以得到灰度直方图分布如Fig.1(b)所示的灰度分布以及Fig.3所示的处理后结果。

哈工大深研院数字图像处理第一次大作业:不调用Matlab函数实现图像增强_第1张图片哈工大深研院数字图像处理第一次大作业:不调用Matlab函数实现图像增强_第2张图片
2.针对Fig.4中存在的椒盐噪声,采用中值滤波可以达到很好的滤除效果。通过构建
1 1 1
1 1 1
1 1 1
这样的模板,将模板内的中值替代为模板中心的图像值,使这个模板扫过整幅图像便可以实现噪声滤除效果。同时,由于边界效应,我们将图像的边界进行了扩充。实践证明图像边界的扩充可以在处理后通过恰当的处理结果裁剪而消除影响,并且这种扩充对于图像来说将不会造成影响。这里有几点需要注意:
1)模板的维度必须是奇数维正方形,否则将会在模板中心选取时造成很大的困扰;
2)模板大小应当与需要处理的椒盐噪声的尺寸有关,同时,越大的模板将会对图像处理结果造成越模糊的影响。通过测试发现选用3*3的模板恰好可以满足本实验的要求;
3)针对中值选取,用于不允许使用Matlab自带的median以及sort函数,我采用了冒泡排序的方法,因为Matlab软件本身对于for循环处理的速度较慢,所以整个图像的处理速度显得较慢。
哈工大深研院数字图像处理第一次大作业:不调用Matlab函数实现图像增强_第3张图片哈工大深研院数字图像处理第一次大作业:不调用Matlab函数实现图像增强_第4张图片
3.针对题目3中要求的的图像锐化,可以采用高斯高通滤波器进行锐化处理。通过构造图像Fig.6所对应的归一化频率分布,构造空间频率分布,利用高斯高通滤波器表达式(GHPF):
H(u,v)=1-e^(-(D^2 (u,v))/(2〖D_0〗^2 ))           (2)
构造传递函数H(u,v),对原始图像x(m,n)进行频谱对称化(fftshift)后的快速傅里叶变换(FFT),再与传递函数相乘得到处理后的结果Y(u,v),最终对该结果进行逆傅里叶变换,得到我们需要的锐化图像y(m,n)。如图Fig.7所示。哈工大深研院数字图像处理第一次大作业:不调用Matlab函数实现图像增强_第5张图片哈工大深研院数字图像处理第一次大作业:不调用Matlab函数实现图像增强_第6张图片

程序代码也给大家贴上来好了

1.

%Name:Histogram_Equalization
%function:对直方图进行均衡化处理实现图像增强
%Author:Changle Zhang
%Student ID:15S158746
clear all;
close all;
clc;                                  %Initialization

fig = imread('a.jpg');                %import the image
subplot(121)
plot(fig);
title('(a)Gray distribution of image befort process');

[row,col] = size(fig);                %Image size
PixelsNum = row * col;                %Number of Pixels
freq = zeros(256,1);                  %record frequency of each gray level
prob = zeros(256,1);                  %record probability of each gray level
%calculate frequency and probability
for i = 1:row
    for j= 1:col
        value = fig(i,j);
        freq(value+1) = freq(value+1) + 1;
        prob(value+1) = freq(value+1) / PixelsNum;
    end
end

cums = zeros(256,1);                  %record the  cumulative distribution
probc = zeros(256,1);                 %record the probability of each distribution
output = zeros(256,1);                %gray level after H_E
counter = 0;
graylevel = 255;
%calculate cumulative distribution and output gray level
for i = 1:size(prob)
    counter = counter + freq(i);
    cums(i) = counter;
    probc(i) = cums(i) / PixelsNum;
    output(i) = round(probc(i) * graylevel);
end
%HE process
outputimage = uint8(zeros(row,col));  %Final image
for i = 1:row
    for j = 1:col
        outputimage(i,j) = output(fig(i,j)+1);
    end
end
%outputing
subplot(122)
plot(outputimage);
title('(b)Gray distribution of image after process');
figure
imshow(fig);
title('Image before histogram equalization');
figure
imshow(outputimage);
title('Image after histogram equalization');
2.
%Name:Noise_Remove
%function:利用3*3中值滤波模板去除含噪声图像中的椒盐噪声
%Author:Changle Zhang
%Student ID:15S158746
clear all;
close all;
clc;                                                    %Initialization

img=imread('c.jpg');                                    %Import image
imshow(img);
title('Image With Salt&pipe Noise');
[m n]=size(img);

Nmax=3;                                                 %Max filtering Radius(Nmax must be odd)

imgn=zeros(m+2*Nmax+1,n+2*Nmax+1);
imgn(Nmax+1:m+Nmax,Nmax+1:n+Nmax)=img;

imgn(1:Nmax,Nmax+1:n+Nmax)=img(1:Nmax,1:n);                                     %Upper Expansion
imgn(1:m+Nmax,n+Nmax+1:n+2*Nmax+1)=imgn(1:m+Nmax,n:n+Nmax);                     %Right Expansion
imgn(m+Nmax+1:m+2*Nmax+1,Nmax+1:n+2*Nmax+1)=imgn(m:m+Nmax,Nmax+1:n+2*Nmax+1);   %Lower Expansion
imgn(1:m+2*Nmax+1,1:Nmax)=imgn(1:m+2*Nmax+1,Nmax+1:2*Nmax);                     %Left Expansion


[height, width]=size(imgn);                             %Size of Expansived Image
x1=double(imgn);
x2=x1;
for i=1:height-Nmax+1
    for j=1:height-Nmax+1
        c=x1(i:i+(Nmax-1),j:j+(Nmax-1));                %get the initial filtering point
        e=c(1,:);                                       %first row of matrix 'c'
        for u=2:Nmax
            e=[e,c(u,:)];                               %make 'c' a row vector 'e'   
        end
        n1=Nmax*Nmax;                                   %Number of pixel in model
        for l=1:n1-1                                    %Sort the row vector
            for q=1:n1-1
                if e(q)>e(q+1)
                    c1 = e(q);
                    e(q) = e(q+1);
                    e(q+1) = c1;
                end
            end
         end
        mm = e((n1+1)/2);                               %mm is the median number
        x2(i+(Nmax-1)/2,j+(Nmax-1)/2)=mm;               %assignment median value for the center point
    end
end 
%keep the unassignment points
d=uint8(x2);
figure;
imshow(d(Nmax+1:m+Nmax,Nmax+1:n+Nmax),[]);
title('Image After Noise Removement');
3.
%Name:Gaussian_Highpass_Filtering
%function:利用高斯高通滤波器锐化图像
%Author:Changle Zhang
%Student ID:15S158746
clear all;
close all;
clc;                                                    %Initialization

img=imread('e.tif');                                    %Import image
imshow(img);
title('Image Before Sharpen');
[m n]=size(img);                                        %Get the image size m*n
%Generate normalization uniformly-spaced point in frequency domain
for i= 1:m
    if mod(n,2)==0                                      %n is even
        f1(i,:)=[-n+1:2:n-1]./(n-1);
        f2(:,i)=f1(i,:)';
    else                                                %n is odd
        f1(i,:)=[-n:2:n-2]./(n-1);
        f2(:,i)=f1(i,:)';
    end
end

D = 0.2;                                                %Gaussian end frequency 
r = f1.^2+f2.^2;                                        %Filerting radius
%Generate filering transformation H
for i =1:m
    for j = 1:n
        t=r(i,j)/(D*D);
        Hd(i,j)=1-exp(-t);
    end
end
X=fftshift(fft2(double(img)));                          %FFT
Y=X.*Hd;                                                %Apply high-pass filtering
output=real(ifft2(ifftshift(Y)));                       %Ifft and get the real part
figure;
imshow(output,[]);
title('Image After High-Pass filtering');


你可能感兴趣的:(算法,matlab,图像处理,数字图像处理)