图像预处理——matlab

参考此书:数字图像处理与机器视觉,第二版,张铮

—————————————————————————————————————
%图像预处理
RGBIm = imread(‘lena.jpg’);%读入图片
GRAYImage = rgb2gray(RGBIm);%图像灰度转换
threshold = graythresh(GRAYImage);%阈值
BW = im2bw(RGBIm,threshold);%二值化图像
imshow(BW );
—————————————————————————————————————

%%
%图像反转
RGBIm = imread(‘lena.jpg’);%读入图片
doubleimage = double(RGBIm);
doubleimage = -doubleimage +256-1;
H = uint8(doubleimage);
subplot(1,2,1);imshow(doubleimage);
subplot(1,2,2);imshow(H);

—————————————————————————————————————

%%
%直方图均衡
RGBIm = imread(‘lena.jpg’);%读入图片
gray = rgb2gray(RGBIm);
figure;
subplot(2,2,1);imshow(gray);
subplot(2,2,2);imhist(gray);%获得直方图
histIm = histeq(gray);%直方图均衡后的图片
subplot(2,2,3);imshow(histIm);
subplot(2,2,4);imhist(histIm);%获得直方图

—————————————————————————————————————

%%
%线性平滑滤波器
RGBIm = imread(‘lena.jpg’);%读入图片
gray = rgb2gray(RGBIm);
noiseIm = imnoise(gray,‘salt & pepper’,0.02);%添加椒盐噪声
K1 = filter2(fspecial(‘average’,3),noiseIm)/255; %进行33模板平滑滤波
K2 = filter2(fspecial(‘average’,5),noiseIm)/255; %进行5
5模板平滑滤波
%K3 = filter2(fspecial(‘average’,7),noiseIm)/255;%进行77模板平滑滤波
%K4 = filter2(fspecial(‘average’,9),noiseIm)/255;%进行9
9模板平滑滤波
K3 = filter2(fspecial(‘gaussian’),noiseIm)/255; %进行gaussian滤波
K4 = filter2(fspecial(‘prewitt’),noiseIm)/255; %用于边缘增强,大小为【3 3】,无参数
figure;
subplot(2,3,1);imshow(RGBIm);title(‘原始图像’);
subplot(232);imshow(noiseIm);title(‘添加椒盐噪声’);
subplot(233),imshow(K1);title(‘33模板平滑滤波’);
subplot(234),imshow(K2);title('5
5模板平滑滤波’);
subplot(235),imshow(K3);title(‘高斯滤波’);
subplot(236),imshow(K4);title(‘prewitt滤波’);

—————————————————————————————————————

%%
%中值滤波器
RGBIm = imread(‘lena.jpg’);%读入图片
gray = rgb2gray(RGBIm);
noiseIm &

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值