以下为《直方图 程序代码》的无排版文字预览,完整内容请下载
直方图 程序代码
I1=imread('图片1.png');
[M,N]=size(I1);
subplot(2,2,1);
imshow(I1); %显示原图
title('原图');
subplot(2,2,2);
h1=imhist(I1);
bar(h1); %显示灰度直方图
axis([0 256,-inf,inf]);
%求变换函数
s=[];
s(1)=255*h1(1)/M/N;
for k=2:255
s(k)=s(k-1)+255*h1(k)/M/N;
end
%%绘制变换后的图像
I2=[];
for m=1:M
for n=1:N
for k=1:255
if I1(m,n)==k %遍历I1中的所有像素点
I2(m,n)=round(s(k));%取整
end
end
end
end
I2=uint8(I2); %由于运算后函数为double型,因此需用此句转换为uint8型以显示
subplot(2,2,3);
imshow(I2);
title('直方图');
subplot(2,2,4);
h2=imhist(I2);
bar(h2);
figure;
plot(s);
空间域滤波器
%空间域滤波
clc;close all;
I=imread('图片1.png');
w1=fspecial('average',[3 3]);
w2=fspecial('log',[5 5],0.5);
g1=imfilter(I,w1,'replicate');
g2=medfilt2(I);
subplot(2,2,1);imshow(I);title('原图');
subplot(2,2,3);imshow(g1);title('均值滤波');
subplot(2,2,4);imshow(g2);title('中值滤波');
频率域滤波
%巴特沃斯低通
figure(3);
I=imread('图片1.png');
subplot(221),imshow(I);
title('原始图像');
Y=fft2(im2double(I));%傅里叶变换
Y=fftshift(Y);%频谱搬移,直流分量搬移到频谱中心
subplot(222), imshow(log(abs(Y)+1),[]);
title('图像傅里叶变换取对数所得频谱');
[M,N]=size(Y);%获得图像的高度和宽度
h=zeros(M,N);%滤波器函数
%图像中心点
M0=M/2;
N0=N/2;
d0=40;
%巴特沃斯滤波器的阶数
n_0=2;
for x=1:M
for y=1:N
distance=sqrt((x-M0)^2+(y-N0)^2);
h(x,y)=1/(1+(distance/d0)^(2*n_0));
end
end
%滤波后结果
res=h.*Y;
res=real(ifft2(ifftshift(res)));
subplot(223),imshow(res);
title('巴特沃斯低通滤波所得图像');
subplot(224) 内容过长,仅展示头部和尾部部分文字预览,全文请查看图片预览。
for j=1:b
distance=sqrt((i-a0)^2+(j-b0)^2);
if distance
以上为《直方图 程序代码》的无排版文字预览,完整内容请下载
直方图 程序代码由用户“jingdia”分享发布,转载请注明出处