数字图像处理-第十章的前半部分

学习到第十章的前半部分

ice函数 g = ice('image',f);

ice 窗口操作

鼠标操作 结果
左键 按住并拖动来移动控制点
左键+Shift键 添加控制点。拖动(同时按住Shift键)可改变控制点的位置
左键+Control键 删除控制点

鼠标左键代表移动, 鼠标中键代表添加, 右键代表删除

GUI元素 描述
Smooth 选择则使用三次样条内插
Clamp Ends 选择则强制将三次样条的起始和结束曲线斜度设置为0
Show PDF 显示被映射函数影响的图像分量的概率密度函数(即直方图)
Show CDF 显示累计分布函数并非PDF(注意,PDF和CDF不能同时显示
Map Image 选中则启动图像映射,默认选中
Map Bars 选择则启动伪彩色和全彩色条带映射
Reset 重置

Reset All 重置所有
Input/Output| 显示坐标,Input为x轴,Output为y轴
Component

row 1 col 1 | row 1 col 2
Component | 为交互操作选择一个映射函数,就是选择图片的哪个分量进行操作

插入控制点

image

使用smooth

image

单色负片和彩色分量的反映射

image
image

应用:单色和彩色对比度增强

image
image


image
image

应用:伪彩色映射

image
image

应用:彩色平衡

image
image

应用:基于直方图的映射

彩色图像的空间滤波

彩色图像锐化

close all;
clear all;
f=imread('Fig0615.tif');
lapmask=[1 1 1;1 -8 1;1 1 1];
fen=imsubtract(f,imfilter(f,lapmask,'replicate'));
%也可以写成fen=f-imfilter(f,lapmask,'replicate');
subplot(1,2,1);
imshow(f);
title('原图');
subplot(1,2,2);
imshow(fen);
title('使用拉普拉斯算子增强的图像 ');

image

膨胀 A2=imdilate(A,B);

A=imread('2.png');
B=[0 1 0;1 1 1;0 1 0];
A2=imdilate(A,B);
subplot(1,2,1);
imshow(A)
title('原图');
subplot(1,2,2);
imshow(A2);
title('膨胀后的图');

image

腐蚀 g= imerode(f, se)

f = imread('Fig0908.tif');
g1 = imerode(f, strel('disk', 5));
g2 = imerode(f, strel('disk', 10));
g3 = imerode(f, strel('disk', 20));
subplot(2, 2, 1), imshow(f), title('原图');
subplot(2, 2, 2), imshow(g1), title('半径为5的圆盘腐蚀后的图');
subplot(2, 2, 3), imshow(g2), title('半径为10的圆盘腐蚀后的图');
subplot(2, 2, 4), imshow(g3), title('半径为20的圆盘腐蚀后的图');

image

开运算和闭运算

对于结构元素可以自己根据自己的需要定义比如:[0 1 0;1 1 1; 0 1 0],也可以使用strel来定义,而且用strel定义的结构元素,系统自动的进行分解,以提高系统的运算速度。
image


在实际的应用中,一副图像往往要经过相同或者不同的结构元素进行数次的膨胀、腐蚀操作,最常用的膨胀和腐蚀操作的组合有:开运算、闭运算、击中或击不中变换。开运算等效于先腐蚀再膨胀,闭运算等效于先膨胀再腐蚀。A开B等于B在A内所有完全匹配的平移的并集。
A闭B等于所有不与A重叠的B的平移的并集。

f=imread('Fig0910.tif');
se=strel('square',20);
fo=imopen(f,se);
fc=imclose(f,se);
foc=imclose(fo,se);
subplot(2,2,1);
imshow(f);
title('原图');
 
subplot(2,2,2);
imshow(fo);
title('开运算后的图像');
 
subplot(2,2,3);
imshow(fc);
title('闭运算后的图像');
 
subplot(2,2,4);
imshow(foc);
title('先开运算后闭运算后的结果');

image

f=imread('fingerprint.tif');
se=strel('square',3);
fo=imopen(f,se);
foc=imclose(fo,se);
subplot(1,3,1);
imshow(f);
title('原图');
 
subplot(1,3,2);
imshow(fo);
title('开运算后的图像');
 

subplot(1,3,3);
imshow(foc);
title('先开运算后闭运算后的结果');

image

形态学开运算完全删除不能包含结构元素的对象区域,平滑了对象的轮廓,断开了狭窄的连接,去掉了细小的突出部分。与开运算不同的是,闭运算一般会将狭窄的缺口连接形成细长的弯口,并填充比结构元素小的洞。
image

提取出图像的骨骼化或细化 I = bwmorph(I1, 'skel', Inf);

clc;  
clear all;  
I1 = imread('fingerprint.png');
I1=im2bw(I1);
subplot(1,3,1), imshow(I1);
title('原图');
I2 = bwmorph(I1, 'skel', Inf);
subplot(1,3,2), imshow(I2);
title('骨骼化后的图像');
I3 = bwmorph(I1, 'thin', Inf);
subplot(1,3,3), imshow(I3);
title('细长化后的图像');

image

g=endpoints(f)计算并应用查找表来计算二值图f的端点并以二值图返回它们。

f=imread('Fig0916.tif');
g=bwmorph(f,'skel', Inf);
g=endpoints(g);
figure(1),imshow(f);title('原图');
figure(2),imshow(g);title('骨骼化图像');

image

使用endpoints函数修剪骨骼化细化的毛刺

骨骼化和细化经常会产生无关的短“毛刺”或寄生成分。清除或去除这些短毛刺的过程称为修剪。函数endpoints() 可以实现这一目的,它识别并删除端点

clc;  
clear all;  
I1=imread('Fig0916.tif');
I2=bwmorph(I1, 'skel', Inf);
for k=1:5
    I3=I2&~endpoints(I2);
    subplot(1,3,1);
end
imshow(I1);
title('原图');
subplot(1,3,2), imshow(I2);
title('骨骼化后的图像');
I3 = bwmorph(I1, 'thin', Inf);
subplot(1,3,3), imshow(I3);
title('细化后的图像');

image

击中或击不中变换

load trees;
BW = im2bw(X, map, 0.4);
figure, imshow(BW);
interval = [0 -1 -1; 1 1 -1; 0 1 0];
BW2 = bwhitmiss(BW, interval);
figure, imshow(BW2);

image

点,线和边缘检测

点检测

imfilter函数进行点检测

f=imread('Fig1002.tif');
w=[-1 -1 -1;-1 8 -1;-1 -1 -1];
g=abs(imfilter(tofloat(f),w));
T=max(g(:));
g=g>=T;
subplot(1,2,1);imshow(f);title('原图'),
subplot(1,2,2);
imshow(g);
title('点检测后的图像');

image

ordfilt2函数进行点检测

g = imsubtract(ordfilt2(f,3*3,ones(3,3)),ordfilt2(f,1,ones(3,3)));
T=max(g(:));
g = g>= T;
subplot(1,2,1);
imshow(f);
title('原图');
subplot(1,2,2);
imshow(g);
title('点检测后的图像');
![image](http://note.youdao.com/yws/public/resource/5723d9340c2d8935f684911307ebfdd9/xmlnote/2C253F1B23A1466AA38CEEB1F1D0E94A/176)

线检测

f=imread('Fig1004.tif');
subplot(2,3,1);
imshow(f);
 title('原图');
w = [2 -1 -1; -1 2 -1;-1 -1 2];
g = imfilter(double(f),w);
subplot(2,3,2);
imshow(g,[]);
 title('+45度检测器后的图');
gtop = g(1:120,1:120);
gtop = pixeldup(gtop,4);
subplot(2,3,3);
imshow(gtop,[]) ;
 title('左上方放大的图');
gbot = g(end-119:end,end-119:end);
%pixeldup函数是将图像扩大m*n倍,通过复制每个像素点m*n次。
gbot = pixeldup(gbot,4);
subplot(2,3,4);
imshow(gbot,[]) ;
 title('右下方放大的图');
g = abs(g);
subplot(2,3,5);
imshow(g,[]);
 title('+45度检测器取绝对值后的图');
T = max(g(:));
g = g>=T;
subplot(2,3,6);
imshow(g);
 title('满足g>T的所有点');

image

使用函数edge检测边缘

f=imread('Fig1006.tif');
subplot(2,3,1);
imshow(f);
title('原图');
g1 = edge(f,'sobel','vertical');
subplot(2,3,2);
imshow(g1);
title('垂直sobel模板处理后的结果');
g2 = edge(f,'sobel',0.15,'vertical');
subplot(2,3,3);
imshow(g2);
title('指定垂直sobel模板处理后的结果');
g3 =edge(f,'sobel',0.15);
subplot(2,3,4);
imshow(g3);
title('指定垂直sobel模板和阈值处理后的结果');
wneg45=[-2 -1 0;-1 0 1;0 1 2];
gneg45=imfilter(tofloat(f),wneg45,'replicate');
T=0.3*max(abs(gneg45(:)));
gneg45=gneg45>=T;
subplot(2,3,5);
imshow(gneg45);
title('用指定模板和指定阈值计算-45度方向边缘处理后的结果');

wpos45=[0 1 2;-1 0 1;-2 -1 0];
gpos45=imfilter(tofloat(f),wpos45,'replicate');
T=0.3*max(abs(gpos45(:)));
gpos45=gpos45>=T;
subplot(2,3,6);
imshow(gpos45);
title('用指定模板和指定阈值计算+45度方向边缘处理后的结果');

image

原文地址:https://www.cnblogs.com/is-Tina/p/7456267.html