以下为《数字图像处理作业》的无排版文字预览,完整格式请下载
下载前请仔细阅读文字预览以及下方图片预览。图片预览是什么样的,下载的文档就是什么样的。
Chapter 4
%% 4.4(b) 验证卷积定理
b1 = [7,6,5,4,-4,-5,-6,-7];
b2 = [2,2,-5,-5,6,6,-7,-7];
N1 = length(b1);
N2 = length(b2);
ans1 = conv(b1,b2);
t = fft([b1,zeros(1,N2-1)]).*fft([b2,zeros(1,N1-1)]);
ans2 = ifft(t);
disp(num2str(ans1-ans2));
% 经验算结果为0
%% 4.9 利用滤波器进行频域滤波
im = imread('twins.tif');
im = rgb2gray(im);
ff = fftshift(fft2(im));
figure(2)
subplot(2,4,1),imshow(im),title('原始图像');
subplot(2,4,2),imshow(mat2gray(log(abs(ff)))),title('频域图像');
[a,b] = size(im);
[x,y] = meshgrid(-b/2:b/2-1,-a/2:a/2 - 1);
z = sqrt(x.^2 + y.^2);
fil = (z15);
imf2 = ifft2(ff.*fih);
subplot(2,4,4),imshow(abs(imf2/256)),title('理想高通滤波');
fig = mat2gray(fspecial('gaussian', 256, 30));
imf3 = ifft2(ff.*fig);
subplot(2,4,7),imshow(abs(imf3/256)),title('高斯滤波');
d=15;n=2;
fibl = 1./(1+(sqrt(2)-1)*((x.^2+y.^2)/d^2).^n);
fibh = 1-fibl;
imf4 = ifft2(ff.*fibl);
imf5 = ifft2(ff.*fibh);
subplot(2,4,5),imshow(abs(imf4/256)),title('巴特沃斯低通');
subplot(2,4,6),imshow(abs(imf5/256)),title('巴特沃斯高通');
Chapter5
clc;
clear all;
f = imread('flowers.tif');
fg = rgb2gray(f);
f = im2uint8(f(30:285,60:315));
figure,imshow(f)
%?ó5%?·????éù
f_sp = imnoise(f,'salt & pepper',0.05);
figure,imshow(f_sp)
%average filtering
a3 = fspecial('average');
f_sp_a3 = filter2(a3,f_sp);
figure,imshow(f_sp_a3/256)
%median filtering
f_sp_m3 = medfilt2(f_sp);
figure,imshow(f_sp_m3)
%the outlier method
f_sp_out = outlier(f_sp,0.2);
figure,imshow(f_sp_out)
%pseudo_median filtering
for i = 1:256
for j = 1:256
if(i==1 || i==256 || j==1 || j==256 )
f_sp_psemed(i,j) = f_sp(i,j);
else
f_sp_psemed(i,j) = 0.5*max1(min1(f_sp(i,j-1),f_sp(i-1,j),f_sp(i,j)),min1(f_sp(i-1,j),f_sp(i,j),f_sp(i+1,j)),min1(f_sp(i,j),f_sp(i+1,j),f_sp(i,j+1))) + 0.5*min1(max1(f_sp(i,j-1),f_sp(i-1,j),f_sp(i,j)),max1(f_sp(i-1,j),f_sp(i,j),f_sp(i+1,j)),max1(f_sp(i,j),f_sp(i+1,j),f_sp(i,j+1)));
end
end
end
figure,imshow(f_sp_psemed)
function y = max1(a,b,c)
max=a;
if maxc
min=c;
end
y = min;
function res=outlier(im,d)
% OUTLIER(IMAGE,D) removes salt and pepper noise using an outlier method.
% This is done by using the following algorithm:
%% For each pixel in the image, if the difference between its grey value
% and the average of its eight neighbours is greater than D, it is
% classified as noisy, and its grey value is changed to that of the
% average of its neighbours.
%% IMAGE can be of type UINT8 or DOUBLE; the output is of type
% UINT8. The threshold value D must be chosen to be between 0 and 1.
f=[0.125 0.125 0.125; 0.125 0 0.125; 0.125 0.125 0.125];
imd=im2double(im);
imf=filter2(f,imd);
r=abs(imd-imf)-d>0;
res=im2uint8(r.*imf+(1-r).*imd);
chapter6
clc
clear all;
f = imread('cameraman.tif');
[x,y] = meshgrid(1:256,1:256);
%% (a)s=1+sin(x/3+y/5)
s1 = 1+sin(x/3+y/5);
ts1 = (double(f)/128+s1)/4;
fig 内容过长,仅展示头部和尾部部分文字预览,全文请查看图片预览。 ];
B3 = [1 0 0;
0 0 0;
0 0 1];
figure,imshow(A1)
figure,imshow(B1)
%erosion
ce = imerode(A1,B1);
figure,imshow(ce)
%dilation
cd = imdilate(A1,B1);
figure,imshow(cd)
% opening
ci = imopen(A1,B1);
figure,imshow(ci)
% closing
cc = imclose(A1,B1);
figure,imshow(cc)
[文章尾部最后300字内容到此结束,中间部分内容请查看底下的图片预览]请点击下方选择您需要的文档下载。
以上为《数字图像处理作业》的无排版文字预览,完整格式请下载
下载前请仔细阅读上面文字预览以及下方图片预览。图片预览是什么样的,下载的文档就是什么样的。