数字图像处理第二章

数字图像处理–灰度变换与空间滤波
空间域处理图像主要包括两部分:灰度变换和空间滤波,灰度变换是在图像的单个像素上操作,主要以对比度和阈值为目的,空间滤波可用过像素的邻域处理来锐化图像。

一、灰度变换
图像变换的常用基本函数:线性函数(反转和恒等)、对数函数(对数和反对数变换)和幂律函数(n次幂和n次根),这些变换函数主要可用来图像增强。
直方图处理:

直方图的概念:一幅图像中灰度级与出现这种灰度的概率之间关系的图形,灰度直方图是一种统计表达,反映了不同灰度级出现的统计概率(个数),其横坐标是:灰度级,纵坐标是:出现的个数(概率)
直方图的显示:暗图像的直方图系数聚集在较低的值附近,亮图像的直方图系数聚集在较高的值附近,低对比度的图像直方图系数中间值较大并且不均匀,高对比度的直方图系数比较均匀。
直方图均衡:将像素均衡化处理,使得像素相对集中, 处理后灰度范围变大,对比度变大,清晰度变大,所以能有效增强图像。
直方图匹配(也称直方图规定化):通俗的理解是将一幅图像的直方图与规定的直方图进行匹配,通过规定的直方图得到变换函数,再进行处理。

相关代码与图片如下
%1
clc,clear,close all;
f = imread('Fig0203(a).tif');
g1 = imadjust(f, [0 1], [1 0]);
figure
subplot(231)
imshow(f,[])
subplot(232)
imshow(g1,[])
g2 = imadjust(f, [0.5 0.75], [0 1]);
g3 = imadjust(f, [], [], 2);
subplot(233)
imshow(g2,[])
subplot(234)
imshow(g3,[])
g4 = imadjust(f, stretchlim(f),[]);
g5 = imadjust(f, stretchlim(f),[1 0]);
subplot(235)
imshow(g4,[]);
subplot(236)
imshow(g5,[])
%2
clc,clear,close all;
f = imread('Fig0205(a).tif');
g = im2uint8(mat2gray(log(1 + double(f))));
figure
subplot(121)
imshow(f,[])
subplot(122)
imshow(g,[])
%3
clc,clear,close all;
f = imread('Fig0206(a).tif');
g = intrans(f, 'stretch', mean2(tofloat(f)),0.9);
figure
subplot(121),imshow(f,[])
subplot(122),imshow(g,[])
%4
clc,clear,close all;
f = imread('Fig0203(a).tif');
figure
subplot(221),imhist(f)
h = imhist(f,25);
horz = linspace(0,255,25);
subplot(222),bar(horz,h)
axis([0 255 0 60000])
set(gca, 'xtick', 0:50:255)
set(gca, 'ytick', 0:20000:60000)
subplot(223),stem(horz,h,'fill')
axis([0 255 0 60000])
set(gca, 'xtick', 0:50:255)
set(gca, 'ytick', 0:20000:60000)
hc = imhist(f);
subplot(224),plot(hc)
axis([0 255 0 15000])
set(gca, 'xtick', 0:50:255)
set(gca, 'ytick', 0:20000:15000)
%5
clc,clear,close all;
f = imread('Fig0208(a).tif');
figure
subplot(221),imshow(f,[]);
g = histeq(f,256);
subplot(222),imhist(f),ylim('auto');
subplot(223),imshow(g,[]);
subplot(224),imhist(g),ylim('auto');
hnorm = imhist(f)./numel(f);
cdf = cumsum(hnorm);
figure
x = linspace(0,1,256);
plot(x,cdf)
axis([0 1 0 1]);
set(gca,'xtick',0:.2:1)
set(gca,'ytick',0:.2:1)
xlabel('Input intensity values','fontsize',9)
ylabel('Output intensity values','fontsize',9)
%6
clc,clear,close all;
f = imread('Fig0210(a).tif');
f1 = histeq(f,256);
figure
subplot(221),imshow(f,[]);
subplot(222),imhist(f),ylim('auto');
subplot(223),imshow(f1,[]);
subplot(224),imhist(f1),ylim('auto');
p = twomodegauss(0.15,0.05,0.75,0.05,1,0.07,0.002);
figure
subplot(221),plot(p),xlim([0 255]);
g = histeq(f, p);
subplot(222),imshow(g);
subplot(223),imhist(g),ylim('auto');
%7
clc,clear,close all;
f = imread('Fig0210(a).tif');
g1 = adapthisteq(f);
g2 = adapthisteq(f,'NumTiles',[25 25]);
g3 = adapthisteq(f, 'NumTiles',[25 25],'ClipLimit',0.05);
figure
subplot(141),imshow(f,[])
subplot(142),imshow(g1,[])
subplot(143),imshow(g2,[])
subplot(144),imshow(g3,[])
%8
clc,clear,close all;
w = ones(31);
f = imread('Fig0216(a).tif');
figure
subplot(231),imshow(f,[])
gd = imfilter(f,w);
subplot(232),imshow(gd,[]);
gr = imfilter(f,w,'replicate');
subplot(233),imshow(gr,[])
gs = imfilter(f,w,'symmetric');
subplot(234),imshow(gs,[]);
gc = imfilter(f,w,'circular');
subplot(235),imshow(gc,[]);
f8 = im2uint8(f);
g8r = imfilter(f8,w,'replicate');
subplot(236),imshow(g8r,[])
%9
clc,clear,close all;
gmean = @(A) prod(A, 1)^1 / size(A,1);
f = padarray(f , [m n], 'replicate');

%10
clc,clear,close all;
f = imread('Fig0217(a).tif');
w = fspecial('laplacian',0)
g1 = imfilter(f,w,'replicate');
figure
subplot(221),imshow(f,[])
subplot(222),imshow(g1,[])
f2 = tofloat(f);
g2=imfilter(f2,w,'replicate');
subplot(223),imshow(g2,[])
g = f2-g2;
subplot(224),imshow(g);
%11
clc,clear,close all;
f = imread('Fig0217(a).tif');
w4 = fspecial('laplacian',0);
w8 = [1 1 1;1 -8 1;1 1 1];
f = tofloat(f);
g4 = f - imfilter(f,w4,'replicate');
g8 = f - imfilter(f,w8,'replicate');
figure
subplot(131),imshow(f)
subplot(132),imshow(g4)
subplot(133),imshow(g8)
%12
clc,close,close all;
f = imread('Fig0219(a).tif');
fn = imnoise(f,'salt & pepper',0.2);
gm = medfilt2(fn);
gms = medfilt2(fn,'symmetric');
figure
subplot(141),imshow(f)
subplot(142),imshow(fn)
subplot(143),imshow(gm)
subplot(144),imshow(gms)

2-1

2-22-32-42-5

2-62-72-8

2-9

2-102-112-12

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值