数字图像处理期末复习2018-12-21

数字图像处理期末复习2018-12-21


数字图像处理期末复习2018-12-21


愉快先生

数字图像处理期末复习2018-12-21

0.204

·

字数 5547 · 阅读 1834

2018-12-22 19:35

(数字图像冈萨雷斯第二版教材)

一、基本原理

i= imread('filename') ; imwrite(i,image.jpg);

imshow(i); imshow(i,[]);%0~255映射 imshow(i,[min max])%指定映射区间min到max

解释:见博客:https://blog.csdn.net/Michael__Corleone/article/details/68483407

问题:在使用imshow(A)显示一张灰度图片时,显示出的是一张纯白的图片。(A为double类型的图像矩阵)

原因:在matlab中,为了保证精度,经过了运算的图像矩阵A其数据类型会从unit8型变成double型。

imshow()显示图像时对double型是认为在0~1范围内,即大于1时都是显示为白色。

imshow显示uint8型时是0~255范围。

使用imshow(A,[]),即可把图像矩阵A显示为正常的灰度图像。

原理:imshow(A,[])是将A的最大值(max(A))和最小值(min(A))分别作为纯白(255)和纯黑(0),

中间的K值相应地映射为0到255之间的标准灰度值,这样就可以正常显示了。

相当于将double型的矩阵A拉伸成为了0-255的uint8型的矩阵,因此就可以正常显示。

见数字图像处理第二版P14 索引=下标

二、图像灰度变换和空间滤波

教材P24

g=imadjust(f,[low high],[new_low new_high],gamma)

1.将f中灰度值映射为图g中新值。

2.low high (输入的值)在0到1之间

3.gamma>1突出亮区; gamma<1突出暗区

G = intrans(F, 'log', C, CLASS)

g=c*log(1+f)

G = intrans(F, 'stretch', M, E)

g=1./(1+(m./f).^E) %m是阈值在0到1之间 E是斜率

使图像亮的地方更亮,暗的地方更暗,从而增加图像的可视细节

平均滤波器: h = fspecial('average',hsize)

高斯滤波器: h = fspecial('gaussian',hsize,sigma)

圆盘滤波器: h = fspecial('disk',radius)

运动滤波器: h = fspecial('motion',len,theta)

教材P50

sobel算子 : h = fspecial('sobel')

prewitte算子 : h = fspecial('prewitte')

log算子 : h = fspecial('log',hsize,sigma)

lapalase算子 : h = fspecial('laplacian',alpha)

g=ordfilt2(f,order,domain)

最小滤波器:g=ordfilt2(f,1,ones(m,n));

最大滤波器:g=ordfilt2(f,m*n,ones(m,n));

最知名的中值滤波器:g=ordfilt2(f,(m*n+1)/2,ones(m,n));

中值滤波器专用实现:g=medfilt2(f,[m n],padopt);

%数组[m n]定义一个大小为m*n的邻域(在该邻域上计算中值)

%padopt指定三个可能的边界填充选项之一:

%zeros(默认值),symmetric指出f按照镜像反射方式沿边界扩展

%indexed表示若f是double类的则用1填充,否则用0填充。

默认形式:g=medfilt2(f);使用一个大小为3*3的邻域并用0填充边界计算中值。

中值滤波器对椒盐噪声处理很好。

三、图像傅里叶变换和频率与处理

如果看了此文你还不懂傅里叶变换,那就过来掐死我吧【完整版】

f=imread('C:\Users\liulang\Desktop\test.jpg');g=rgb2gray(f);% 利用imread读出一副图像,显示图像 f = imread (.);

f = im2double(g); % 将图片类型转成double类型;

h=fspecial('average');% 利用fspecial生成一个空间滤波器,滤波器类型自定义 h= fspecial();

PQ=paddedsize(size(f))% 利用paddedsize设计频率滤波器的大小 PQ=paddedsize(size(f));

H=freqz2(h,PQ(2),PQ(1))% 利用freqz2生成相应的频域滤波器H = freq2(h, PQ(2),PQ(1));

F=fftshift(fft2(f,PQ(1),PQ(2)))% 利用函数fft2计算图像的傅里叶变换 F = fft2 (f, PQ(1),PQ(2)));要中心平移,产生的滤波器原点在矩阵中心处

f=imfilter(f,h);% 利用imfilter和h进行空间滤波;

J=F.*H;J=ifft2(J);J=abs(J);% 将F和H相乘,在做ifft2变换,再取实部,再进行剪切,得到频域滤波结果

J=J(1:size(f,1),1:size(f,2));%size里面两个参数

figure,subplot(131),imshow(g,[]),title('灰度图')% 对比频域滤波和空间滤波的区别

subplot(132),imshow(J,[]),title('频域滤波')

subplot(133),imshow(f,[]),title('空间滤波')

频率域滤波的基本步骤.jpg

四、图像复原


image.png

答:退化后的图像=退化函数*原图像+一个加性噪声

空间域:卷积

空间域卷积操作:h是退化函数,f是原图像,+噪声函数,g是退化后图片

频率域:乘积

频域乘积操作:H是退化函数,F是原图像,+噪声,G是退化后的图像

高斯噪声,Rayleigh噪声,指数噪声,均匀噪声,salt-and-pepper噪声,伽马噪声。

六种

答:

1.均匀区域法是评估噪声最简单的方法。均匀区域法从图像中选择均匀区域, 通过计算这些均匀区域的标准差获取图像的噪声评估结果。需要说明的是,均匀区域是指该区域是平坦的,且在区域内像素值之间的差异不大。

2.分块法是假设图像由大量均匀的小块构成, 利用各小块的方差进行噪声估计。

答:空间滤波:均值滤波器,统计排序滤波器,自适应滤波器。

频率域滤波消除周期噪声:带阻滤波器,带通滤波器,陷波滤波器,最佳陷波滤波

在自适应中值滤波算法中,A步骤里面会先判断是否满足Zmin<Zmed<ZmaxZmin<Zmed<Zmax。

这一步骤实质是判断当前区域的中值点是否是噪声点,

通常来说是满足Zmin<Zmed<ZmaxZmin<Zmed<Zmax这个条件的,

此时中值点不是噪声点,跳转到B;

考虑一些特殊情况,如果Zmed=ZminZmed=Zmin或者Zmed=ZmaxZmed=Zmax,

则认为是噪声点,应该扩大窗口尺寸,在一个更大的范围内寻找一个合适的非噪声点,

随后再跳转到B,否则输出的中值点是噪声点;

接下来考虑跳转到B之后的情况:判断中心点的像素值是否是噪声点,判断条件为Zmin<Zxy<ZmaxZmin<Zxy<Zmax,

原理同上,因为如果Zxy=ZminZxy=Zmin或者Zxy=ZmaxZxy=Zmax,

则认为是噪声点。

如果不是噪声点,我们可以保留当前像素点的灰度值;

如果是噪声点,则使用中值替代原始灰度值,滤去噪声。

空间噪声滤波器函数

f = spfilt(g,type,m,n,parameter)

----<线性和非线性空间滤波器>----

% f = spfilt(g,'amean',m,n) 算术均值滤波器

% f = spfilt(g,'gmean',m,n) 几何均值滤波器

% f = spfilt(g,'hmean',m,n) 谐波均值滤波器

% f = spfilt(g,'chmean',m,n,q) 逆谐波均值滤波器 ,Q 缺省值为 1.5

% f = spfilt(g,'median',m,n) 中值滤波器

% f = spfilt(g,'max',m,n) 最大值滤波器

% f = spfilt(g,'min',m,n) 最小值滤波器

% f = spfilt(g,'midpoint',m,n) 中点滤波器

% f = spfilt(g,'atrimmed',m,n,d) 修正的阿尔法均值滤波器

  1. 模型估计法:建立退化模型,考虑引起退化的环境因素。


逆滤波公式

J = deconvwnr(I,PSF)

J = deconvwnr(I,PSF,NSR)

J = deconvwnr(I,PSF,NCORR,ICORR)

I是退化图像

PSF系统函数(点扩散函数)

NSR信噪比

NCORR:噪声的自相关函数

ICORR:退化图像的自相关函数

J:复原图像

clc,clear,close all;

i=imread('C:\Users\liulang\Desktop\wind.jpg')

figure,subplot(321),imshow(i,[]),title('原图你懂的'),

L=100;

T=11;

PSF=fspecial('motion',L,T);

blu=imfilter(i,PSF,'circular','conv');

subplot(322),imshow(blu,[]),title('跑得快')

noise = 0.1*randn(size(i)); % 生成噪声信号

blurredNoisy = imadd(blu,im2uint8(noise)); % 加入图像

subplot(323),

imshow (blurredNoisy,[]);

title('有噪声并且运动模糊')

i1=deconvwnr(blu,PSF);

subplot(324),

imshow(i1),title('逆滤波-运动模糊')

subplot(325),

i2=deconvwnr(blurredNoisy,PSF),imshow(i2),title('逆滤波-有噪声有运动模糊')

NSR=sum(noise(:).^2)/sum(im2double(i(:)).^2);

i3=deconvwnr(blurredNoisy,PSF,NSR);

subplot(326),imshow(i3),title('空间信噪比-维纳滤波???')

NP=abs(fftn(noise)).^2;%对噪声傅里叶变换 fftn 能量谱

NCORR=fftshift(real(ifftn(NP)));%噪声自相关函数,平不平移都可以

IP=abs(fftn(im2double(i))).^2;%图像功率谱

ICORR=fftshift(real(ifftn(IP)));%图像自相关函数

figure, i4=deconvwnr(blurredNoisy,PSF,NCORR,ICORR);

imshow(i4),title('自相关-维纳滤波????')

五、图像重建

降低振铃现象

中心切片定理指出:f(x,y)在某一方向上的投影函数gθ(R)的一维傅立叶变换函数Gθ(ρ)是原函数f(x,y)的二维傅立叶变换函数F(ρ, θ)在(ρ, θ)平面上沿同一方向且过原点的直线上的值。

1.计算每个投影的一维傅里叶变换

2.用一个滤波函数w乘以每个傅里叶变换,就是加窗。

3.得到每个滤波后的一维反傅里叶变换。

4.将3得到的求和

滤波反投影法(加汉明窗)复原的图像很好的消除了晕环现象。

'Ram-Lak' 矩形窗

'Shepp-Logan' 正弦窗 平滑了图像,损失了部分高频信息

'Cosine' 余弦窗

'Hamming' 通用hanmming窗 降低了高频噪声, 可得到Hamming滤波器和Hanning滤波器

'Hann'

'none'

clear;close all; clc;

g = phantom ('Modified Shepp-Logan',600);

subplot(241);imshow(g,[]);title ('original image')

theta = 0:0.5:179.5;

[R,xp] = radon(g,theta);

f3 = iradon(R,theta,'Shepp-Logan');

subplot(245);imshow(f3,[]);title ('Reconstructed Image with Shepp-Logan filter')

f4 = iradon(R,theta,'Cosine');

subplot(246);imshow(f4,[]);title ('Reconstructed Image with Cosine filter')

f5 = iradon(R,theta,'Hamming');

subplot(247);imshow(f5,[]);title ('Reconstructed Image with Hamming filter')

六、图像分割

clc;clear

f = imread('Fig1006(a)(building).tif');

subplot(231);imshow(f);title('原始图像')

gv1 = edge(f,'sobel','vertical');

subplot(232);imshow(gv1);title('sobel边缘')

gv2 = edge(f,'prewitt','vertical');

subplot(233);imshow(gv2);title('prewitt边缘')

gv3 = edge(f,'roberts','vertical');

subplot(234);imshow(gv3);title('robert边缘')

gv4 = edge(f,'log');

subplot(235);imshow(gv4);title('log边缘')

gv5 = edge(f,'canny');

subplot(236);imshow(gv5);title('canny边缘')

[H, theta, rho] = hough(BW)

[H, theta, rho] = hough(BW, Parameter1, Parameter2)

BW是二值图像

Parameter1:指定了theta方向的分辨率

Parameter2:指定了lamda方向的分辨率

H:hough变换空间矩阵

Theta和rho:为返回的theta和lamda值

peaks = houghpeaks(H, numpeaks)

H是hough变换矩阵空间

Numpeaks指定峰值的数目

Peaks是容纳峰值的行列坐标的矩阵

lines = houghlines(BW, theta, rho, peaks)

lines = houghlines(..., param1, val1, param2, val2)

从hough变换空间选出候选峰值后,利用峰值所对应的theta和rho值找到直线的位置。

clc;clear;close all;

f = imread('building.tif');

subplot(231);imshow(f);title('原始图像')

[bw,tc] = edge(f,'canny',[0.04 0.10],1.5);

subplot(232);imshow(bw);title('边缘检测结果')

[H,theta,rho] = hough(bw,1);

subplot(233);imshow(H,[]);title ('hough变换空间')

axis on, axis normal

[r,c] = houghpeaks(H,5);

subplot(234);plot(theta(c),rho(r),'linestyle','none',...

'marker','s','color','k')

title('带有所选5个峰值的位置的 Hough 变换')

lines = houghlines(f,theta,rho,r,c);

subplot(235)

imshow(f);hold on;

for k = 1:length(lines)

xy = [lines(k).point1;lines(k).point2];

plot(xy(:,2),xy(:,1),'LineWidth',4,'Color','r');

hold on;

end

title('Hough 变换峰值对应的线段')

clc;clear;close all;

f = imread('fingerprint.tif');

subplot(221);imshow(f,[]);title(原图');

subplot(222);imhist(f);title(直方图');

T = mean2(f);

done = false;

while ~done

g = f>=T;

Tnext = 0.5*(mean(f(g)) + mean(f(~g)));

done = abs(T - Tnext) < 0.5;

T = Tnext;

end

g = f<=T;

subplot(2,2,3:4);imshow(g,[])

title(分割结果')

clc;clear;close all;

f = imread('small-blob.tif');

subplot(221);imshow(f,[]);title(原始图像');

subplot(222);imhist(f);title('直方图');

T = mean2(f);

done = false;

while ~done

g = f>=T;

Tnext = 0.5*(mean(f(g)) + mean(f(~g)));

done = abs(T - Tnext) < 0.5;

T = Tnext;

end

g = im2bw(f,T/255);

subplot(2,2,3);imshow(g,[]); title('迭代阈值处理后的图像')

th = graythresh(f);

g1 = im2bw(f,th);

subplot(2,2,4);imshow(g1,[]);title(Otsu阈值处理后的图像')

clc;clear;close all;

f = imread('cell.tif');

f= rgb2gray(f);

subplot(221);imshow(f,[]);title('original image');

zones = ones(3,3);

mean = uint8(imfilter(double(f),zones/9));

std = uint8(stdfilt(f,zones));

subplot(222);imshow(std,[]);title('standard image');

a=10;b=0.5;

g = (f>a*std & f>b*mean);

subplot(223);imshow(g,[]);title('local segmented image');

th = graythresh(f);

g1 = im2bw(f,th);

subplot(224);imshow(g1,[]);title('Otsu segmented image')

clc;clear;close all;

f = imread('word.tif'); [M,N]=size(f);

f0= double(f);

subplot(131);imshow(f,[]);title('original image');

f1 = f0(:);

maf = ones(1,20)/20;

ma =filter(maf,1,f1);

k =0.5;

g = f1 > k*ma;

g = reshape (g,M,N);

subplot(132);imshow(g,[]);title(moving thresh segmented image');

TH = graythresh(f);

g1 = im2bw(f,TH);

subplot(133);imshow(g1,[]);title('otsu segmented image');

[G, NR, SI, TI] = regiongrow(F, S, T).

F:被分割的图像

S:种子点图像或者一个标量(灰度值,所有具有这个灰度的像素都被记为种子点)

T:阈值数组或者标量,确定相似准则。

G:输出的分割图像

NR:输出的区域个数

SI:种子点图像

TI:阈值测试图像

clear; close all; clc;

I = imread('Fig1014(a)(defective_weld).tif');

subplot(221);imshow (I,[]);title('original image');

[G, NR, SI, TI] = regiongrow(I, 255, 0.26*255);

subplot(222);imshow (SI,[]);title('seed image');

subplot(223);imshow (TI,[]);title('threshold image');

subplot(224);imshow (G,[]);title('segmented image');

[vals, r, c] = qtgetblk(I, S, dim)

[vals, idx] = qtgetblk(I, S, dim)

vals:四叉树分解中尺寸为dim*dim大小的块的值;

r,c为块的左上角的行列坐标;

S:为qtdecomp返回的稀疏矩阵;

I:输入图像。

clear; close all; clc;

I = imread('Fig1022(a)(gel-image).tif');

subplot(231);imshow (I,[]);title('original image');

th = graythresh (I);

bw = im2bw(I,th);

subplot(232);imshow(bw,[]);title('bw image');

subplot(233);imshow(~bw,[]);title('negative of bw image');

d = bwdist(bw);

subplot(234);imshow (d,[]);title('bw distance image');

L = watershed (-d);

w = L==0;

subplot(235);imshow (w,[]);title('water shed lines');

final = I; final(w)=255;

subplot(236);imshow (final,[]);title('superpose image');

- 局域图像梯度的分水岭分割算法:掌握梯度图像平滑的方法:开运算和闭运算。

- 梯度幅度图像在沿对象边缘处有较高的值,而在其它地方值较小。

理想情况下,在沿对象边缘处产生分水岭。

clear;close all; clc;

I = imread('Fig1022(a)(gel-image).tif');

subplot(231);imshow (I,[]);title('original image');

th = graythresh (I);

bw = im2bw(I,th);

subplot(232);imshow(bw,[]);title('bw image');

subplot(233);imshow(~bw,[]);title('negative of bw image');

h= fspecial ('sobel');

f= double (I);

fx = imfilter (f,h);

fy = imfilter (f,h');

fm = hypot (fx,fy);

subplot(234);imshow (fm,[]);title('gradient image');

L = watershed (fm);

w = L==0;

subplot(235);imshow (w,[]);title('water shed lines');

final = f; final(w)=255;

subplot(236);imshow (final,[]);title('superpose image');

clear;close all; clc;

I = imread('Fig1022(a)(gel-image).tif');

subplot(231);imshow (I,[]);title('original image');

th = graythresh (I);

bw = im2bw(I,th);

h= fspecial ('sobel');

f= double (I);

fx = imfilter (f,h);

fy = imfilter (f,h');

fm = hypot (fx,fy);

subplot(232);imshow (fm,[]);title('gradient image');

rm = imregionalmin (fm);

subplot(233);imshow (rm,[]);

title('localmin of gradient image');

im = imextendedmin (f,2);

fim = f;

fim(im)=175;

subplot(234);imshow (fim,[]);title('inner marker image');

Lim = watershed(bwdist(im));

w = Lim==0;

g = imimposemin(fm,imw);

L = watershed(g);

w2 = L==0

subplot(235);imshow (w2,[]);title('water shed lines');

final = f; final(w2)=255;

subplot(236);imshow (final,[]);title('superpose image');

七、彩色图像处理

I=imread('i_peppers_gray.bmp');

GS8=grayslice(I,8);

GS64=grayslice(I,64);

subplot(1,3,1), imshow(I), title('原始灰度图像');

subplot(1,3,2), subimage(GS8,hot(8)), title('分成8层伪彩色');

subplot(1,3,3), subimage(GS64,hot(64)), title('分成64层伪彩色');

图像分割是把图像分成各具特性的区域并提取出感兴趣目标的技术和过程。

rgb=imread('flower608.jpg');

rgb1=im2double(rgb);

r=rgb1(:,:,1);

g=rgb1(:,:,2);

b=rgb1(:,:,3);

r1=r(129:256,86:170);

r1_u=mean(mean(r1(:)));

[m,n]=size(r1);

sd1=0.0;

for i=1:mfor j=1:n

sd1=sd1+(r1(i,j)-r1_u)*(r1(i,j)-r1_u);

end

end

r1_d=sqrt(sd1/(m*n));

r2=zeros(size(rgb1,1),size(rgb1,2));

ind=find((r>r1_u-1.25*r1_d)&(r<r1_u+1.25*r1_d));

r2(ind)=1;

result = cat(3,r2,g,b);

Imshow(result,[])

S1=(S>0.3*(max(max(S))));

F=S1.*H;

日记本

5


免责声明:本文作者:“地球脑瓜崩”,版权归作者所有,观点仅代表作者本人。本站仅提供信息存储分享服务,不拥有所有权。信息贵在分享,如有侵权请联系ynstorm@foxmail.com,我们将在24小时内对侵权内容进行删除。
(49)
「三十三」MATLAB图像变换之Rado
上一篇 2024年04月23日
创新声卡驱动下载(win7系统怎么装创新
下一篇 2024年04月23日

相关推荐

返回顶部