matlab 彩色图像滤波
发布网友
发布时间:2022-04-25 00:01
我来回答
共3个回答
热心网友
时间:2023-10-16 05:22
I=imread('1.jpg');
I1=imnoise(I,'salt & pepper',0.05);
figure(3);
subplot(121);
imshow(I1);title('椒盐噪声');
subplot(122);
J1=I1(:,:,1);
J2=I1(:,:,2);
J3=I1(:,:,3);
H1=medfilt2(J1); %中值滤波
H2=medfilt2(J2);
H3=medfilt2(J3);
H(:,:,1)=H1;
H(:,:,2)=H2;
H(:,:,3)=H3;
imshow(H);title('中值滤波处理后图'); %显示中值滤波后的图像
你看我刚做的实验,就是三维分开搞,再组合在一起,效果蛮好。。。
热心网友
时间:2023-10-16 05:23
i=imread('lena.bmp');
inf=imfinfo('lena.bmp')
figure,imshow(I)
X=grayslice(I,64);
imshow(X,pink(64))
load trees
figure,image(10,10,X)
imwrite(X,map,'trees.bmp');
imfinfo('trees.bmp')
figure,imshow(X,map)
BW=im2bw(X,map,0.6);
figure,imshow(BW)
I=imread('lena.bmp');
inf=imfinfo('lena.bmp')
figure,imshow(I)
X=grayslice(I,64);
figure,imshow(X,pink(64))
A=imread('lena.bmp');
imshow(A)
B=fftshift(fft2(A));
figure;
imshow(log(abs(B)),[8,10])
clc;
clear all;
I=imread('lena.tif');
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %用中值滤波,*滤波,使用中心为-4,-8的拉普
% %拉斯滤波器,高斯低通滤波,拉普拉斯滤波器进行滤波处理
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure;%figure1
subplot(2,2,1);
imshow(I);
title('原始图像');
J=imnoise(I,'salt & pepper',0.04);%加椒盐噪声
title('加椒盐噪声');
subplot(2,2,2);
imshow(J);
K=medfilt2(J,[4,4])%进行中值滤波;
subplot(2,2,3);
imshow(K);
title('进行中值滤波');
h=ones(3,3)/9;%*滤波
w=h;
g=imfilter(I,w,'conv','replicate')
subplot(2,2,4);
imshow(g);
title('*滤波');
%使用中心为-4,-8的拉普拉斯滤波器,
w4=[1 1 1;
1 -4 1;
1 1 1];
w8=[1 1 1;
1 -8 1;
1 1 1];
f=im2double(I);
g4=f-imfilter(f,w4,'replicate');
g8=f-imfilter(f,w8,'replicate');
imshow(f);
figure;%figure2
subplot(1,2,1);
imshow(g4);
title('中心为-4的拉普拉斯滤波');
subplot(1,2,2);
imshow(g8);
title('中心为-8的拉普拉斯滤波');
h3=fspecial('gaussian',[3,3],0.5);%高斯低通滤波
figure;%figure3
B4=filter2(h3,I);
subplot(1,2,1);
imshow(B4,[ ]);
title('高斯低通滤波');
h4=fspecial('laplacian',0);%使用拉普拉斯滤波器
B5=filter2(h4,I);
subplot(1,2,2);
imshow(B5,[ ]);
title('拉普拉斯滤波器');
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %从空域的角度进行亮度变换
% %把灰度等级是10-100的变化到10-255
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure;%figure4
subplot(2,2,1);
imshow(I);
title('原始图像');
J2=imadjust(I,[],[],0.5);% 增强低灰度级
subplot(2,2,2);
imshow(J2);
title('增强低灰度级');
J3=imadjust(I,[ ],[ ],2);%增强高灰度级
subplot(2,2,3);
imshow(J3);
title('增强高灰度级');
a1=100/255;%把灰度等级是10-100的变化到10-255
a2=255/255;
a3=10/255;
J2=imadjust(I,[a3,a1],[a3,a2],[]);
subplot(2,2,4);
imshow(J2);
title('把灰度等级是10-100的变化到10-255');
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %从频域的角度进行亮度变换
% %fft2
% %由于能量主要集中在低频部分
% %所以对低频进行处理可以得到理想的效果
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
I=imread('lena.tif');
up=0.5;%设置处理频率上限
down=0.09%%设置处理频率下限
figure;%figure5
subplot(421);
imshow(I);
title('原始图像');
f=double(I);
subplot(4,2,3);
imshow(log(abs(f)),[]);
title('unit8转化为double');
g=fft2(f);
g=fftshift(g);
subplot(4,2,5);
imshow(log(abs(g)),[]);
title('FFT2变化后的图像');
[M,N]=size(g);% 转换数据矩阵
y1=max(max(abs(g)));%求出最大频率
y2=min(min(abs(g)));%%求出最小频率
y3=(y1-y2)*up+y2;%设置滤波上限
y4=(y1-y2)*down+y2;%%设置滤波下限
for i=1:M
for j=1:N
if (abs(g(i,j))<y4)
g(i,j)=g(i,j)^1.1;%对低频部分进行灰度增强
end
end
end
result=ifftshift(g);
J2=ifft2(result);
J3=uint8(abs(J2));
subplot(427);
imshow(J3,[ ]);
title('频域处理后的图像');
subplot(422)
imhist(I,64);
subplot(424)
imhist(f,64);
subplot(426)
imhist(g,64);
subplot(428)
imhist(J3,64);
热心网友
时间:2023-10-16 05:23
刚刚接触到MATLAB图像滤波。想对一张彩色的BMP的图像进行中值滤波,求代码。