数字图像处理—图像分割
(一)点、线和边缘检测
1.1 点检测
1.2 线检测
1.3 使用函数edge的边缘检测
(二)使用霍夫变换的线检测
2.1 函数hough
2.2 函数houghpeaks
2.3 函数houghlines
(三)阈值处理
3.1 基本全局阈值处理
3.2 使用 Otsu’s 方法的最佳全局阈值处理
3.3 使用图像平滑改进全局阈值处理
3.4 使用边缘改进全局阈值处理
3.5 基于局部统计的可变阈值处理
3.7 使用移动平均的图像阈值处理
(四)基于区域的分割
4.1 区域生长
4.2 区域分离和聚合
(五)使用分水岭变换的分割
5.1 使用距离变换的分水岭分割
5.2 使用梯度的分水岭分割
5.3 控制标记符的分水岭分割
数字图像处理—图像分割
概述:

1、在对图像的研究和应用中,人们往往仅对图像中的某些部分感兴趣,这些部分一般称为目标或前景。
2、为了辨识和分析目标,需要将有关区域分离提取出来,在此基础上对目标进一步利用,如进行特征提取和测量。
3、图像分割就是指把图像分成各具特性的区域并提取出感兴趣目标的技术和过程。
4、特性可以是灰度、颜色、纹理等,目标可以对应单个区域,也可以对应多个区域。
5、图像分割是图像识别和图像理解的基本前提步骤。
(一)点、线和边缘检测
1.1 点检测
使用如下图所示的模板,如果:
在这里插入图片描述
|R|>=T
则在模板中心位置检测到一个点。其中,T是阈值,R是模板计算值。

基本思想: 如果一个孤立点与它周围的点不 同,则可以使用上述模板进行检测。

注意: 如果模板响应为0,则表示在灰度级为常数的区域。

函数:
g = abs(imfilter(tofloat(f), w)) >= T;

f = imread("C:\matlabTuPian\photo\DIP3E_CH05_Original_Images\Fig0524(b)(blurred-impulse).tif");
w = [-1 -1 -1;-1 8 -1;-1 -1 -1];                    % 点Fig0524(b)(blurred-impulse)检测掩模
g = abs(imfilter(double(f),w));
T = max(g(:));
g = g>=T;
subplot(1,2,1);imshow(f);title('(a)原图像');
subplot(1,2,2);imshow(g);title('(b)点检测');

f = imread("C:\matlabTuPian\photo\DIP3E_Original_Images_CH09\Fig0905(a)(wirebond-mask).tif");     % 图像大小:486×486
w = [2 -1 -1;-1 2 -1;-1 -1 2];          % +45°方向检测线
g = imfilter(double(f),w);
gtop = g(1:120,1:120);                  % 左上角区域
gtop = pixeldup(gtop,4,4);                % 通过复制像素将图像扩大gtop*4倍
gbot = g(end-119:end,end-119:end);      % 右下角区域
gbot = pixeldup(gbot,4,4);
g1 = abs(g);                             % 检测图的绝对值
T = max(g1(:));
g2 = g1>=T;subplot(3,2,1);imshow(f);title('(a)连线模板图像');
subplot(3,2,2);imshow(g,[]);title('(b)+45°线处理后的结果');
subplot(3,2,3);imshow(gtop,[]);title('(c)(b)中左上角的放大效果');
subplot(3,2,4);imshow(gbot,[]);title('(d)(b)中右下角的放大效果');
subplot(3,2,5);imshow(g1,[]);title('(e)(b)的绝对值');
subplot(3,2,6);imshow(g2);title('(f)满足g>=T的所有点');

f = imread("C:\matlabTuPian\photo\DIP3E_Original_Images_CH04\Fig0438(a)(bld_600by600).tif");     % 图像大小:486×486
subplot(3,2,1),imshow(f),title('(a)原始图像');
[gv, t] = edge(f,'sobel','vertical');
subplot(3,2,2),imshow(gv),title('(b)Sobel模板处理后结果');
gv = edge(f, 'sobel', 0.15, 'vertical');
subplot(3,2,3),imshow(gv),title('(c)使用指定阈值的结果');
gboth = edge(f, 'sobel', 0.15);
subplot(3,2,4),imshow(gboth),title('(d)指点阈值确定垂直边缘和水平边缘的结果');
w45 = [-2 -1 0;-1 0 1; 0 1 2];
g45 = imfilter(double(f), w45, 'replicate');
T = 0.3 * max(abs(g45(:)));
g45 = g45 >= T;
subplot(3,2,5),imshow(g45),title('(e)-45°方向边缘');
f45= [0 1 2;-1 0 1;-2 -1 0];
h45= imfilter(double(f), f45,'replicate');
T = 0.3 * max(abs(h45(:)));
h45 = h45 >= T;
subplot(3,2,6),imshow(h45),title('(f)+45°方向边缘');

f = imread("C:\matlabTuPian\photo\DIP3E_Original_Images_CH04\Fig0438(a)(bld_600by600).tif");     % 图像大小:486×486
[g_sobel_default,ts] = edge(f,'sobel');
[g_log_default,tlog] = edge(f,'log');
[g_canny_default,tc] = edge(f,'canny');g_sobel_best = edge(f,'sobel',0.05);
g_log_best = edge(f,'log',0.003,2.25);
g_canny_best = edge(f,'canny',[0.04 0.10],1.5);subplot(3,2,1);imshow(g_sobel_default);title('(a)默认sobel');
subplot(3,2,2);imshow(g_sobel_best);title('(b)最佳sobel');
subplot(3,2,3);imshow(g_log_default);title('(c)默认LoG');
subplot(3,2,4);imshow(g_log_best);title('(d)最佳LoG');
subplot(3,2,5);imshow(g_canny_default);title('(e)默认canny');
subplot(3,2,6);imshow(g_canny_best);title('(f)最佳canny');

% 创建合成图像
f = zeros(101, 101);
f(1, 1) = 1;
f(101, 1) = 1;
f(1, 101) = 1;
f(101, 101) = 1;
f(51, 51) = 1;% 显示合成图像
figure;
subplot(121), imshow(f); % 采用完整语法形式调用hough函数
[ H, theta, rho ] = hough(f, 'ThetaRes', 1, 'RhoRes', 1);
subplot(122), imshow(H, [], 'XData', theta, 'YData', rho, 'InitialMagnification', 'fit');
axis on;
axis normal;
xlabel('\theta'); % 加上\后x坐标轴显示θ,否则显示theta
ylabel('\rho');

f=imread("C:\matlabTuPian\photo\DIP3E_Original_Images_CH10\Fig1025(a)(building_original).tif");
figure(1)
imshow (f);title('The Original image')
level=graythresh(f);
f=imbinarize(f);
[H, theta, rho] = hough(f, 'ThetaResolution', 0.2);
figure(2)
imshow(H, [], 'XData', theta, 'YData', rho, 'InitialMagnification', 'fit')
axis on, axis normal
hold on
xlabel('\theta'), ylabel('\rho')
peaks = houghpeaks(H,2);%检测2个峰值点
plot(theta(peaks(:, 2)), rho(peaks(:, 1)), ...'linestyle', 'none', 'marker', 's', 'color', 'w')
title('The peak point location')
lines = houghlines(f, theta, rho, peaks);
figure(3)
imshow(f), hold on
for k = 1:length(lines)xy=[lines(k).point1 ; lines(k).point2];plot(xy(:,1), xy(:,2), 'LineWidth', 4, 'Color', [.8 .8 .8]);
end
title('Hough-transformation result')

f = imread("C:\matlabTuPian\photo\DIP3E_Original_Images_CH10\Fig1038(a)(noisy_fingerprint).tif");
count=0;
T=mean2(f);
done=false;
while ~donecount=count+1;g=f>T;Tnext=0.5*(mean(f(g))+mean(f(~g)));done=abs(T-Tnext)<0.5;T=Tnext;
end
disp('count的值为:');
disp(['count=',num2str(count)]) %打印输出count的值
disp('T的值为:');
disp(['T=',num2str(T)])  %打印输出T的值
g=im2bw(f,T/255);
figure;subplot(1,3,1);imshow(f);title('(a)带噪声的指纹');
subplot(1,3,2);imhist(f);title('(b)直方图');
subplot(1,3,3);imshow(g);title('(c)用全局阈值分割的结果');

f2 = imread("C:\matlabTuPian\photo\DIP3E_Original_Images_CH10\Fig1039(a)(polymersomes).tif");
subplot(221),imshow(f2),title('原始图像');
subplot(222),imhist(f2),title('原始图像直方图');
count = 0;
T = mean2(f2);
done = false;
while ~done
count  = count+1;
g = f2>T;
Tnext = 0.5*(mean(f2(g))+mean(f2(~g)));
done = abs(T-Tnext)<0.5;
T =Tnext;
end
g = im2bw(f2,T/255);
subplot(223),imshow(g,[]),title('用基本全局算法分割结果')
[T,SM] = graythresh(f2);
SM
T*255
g = im2bw(f2,T);
subplot(224),imshow(g),title('用Otsu’s算法分割结果')

f = tofloat(imread("C:\matlabTuPian\photo\DIP3E_Original_Images_CH10\Fig1042(a)(septagon_small_noisy_mean_0_stdv_10).tif"));
subplot(231),imshow(f),title('原图像');
subplot(232),imhist(f),title('原图像直方图');
sx = fspecial('sobel');
sy = sx';
gx = imfilter(f,sx,'replicate');
gy = imfilter(f,sy,'replicate');
grad = sqrt(gx.*gx+gy.*gy);
grad = grad/max(grad(:));h =imhist(grad);
Q = percentile2i(h,0.999);markerImage = grad>Q;
subplot(233),imshow(markerImage),title('以99.9%进行阈值处理后的梯度幅值图像');
fp = f.*markerImage;
subplot(234),imshow(fp),title('原图像与梯度幅值乘积的图像');
hp = imhist(fp);
hp(1) = 0;
subplot(235),bar(hp),title('原图像与梯度幅值乘积的直方图');
T = otsuthresh(hp);
T*(numel(hp)-1)
g = im2bw(f,T);
subplot(236),imshow(g),title('改进边缘后的图像')

f = tofloat(imread("C:\matlabTuPian\photo\DIP3E_Original_Images_CH10\Fig1048(a)(yeast_USC).tif"));
subplot(231),imshow(f),title('原始图像');
subplot(232),imhist(f),title('原始图像的直方图');
hf = imhist(f);
[Tf,SMf] = graythresh(f);
gf = imbinarize(f,Tf);
subplot(233),imshow(gf),title('对原始图像进行分割的图像');
w= [-1 -1 -1;-1 8 -1;-1 -1 -1];
lap = abs(imfilter(f,w,'replicate'));
lap = lap/max(lap(:));
h = imhist(lap);
Q = percentile2i(h,0.995);
markerImage = lap >Q;
fp = f.*markerImage;
subplot(234),imshow(fp),title('标记图像与原图像的乘积');
hp = imhist(fp);
hp(1) =0;
subplot(235),bar(hp)
T = otsuthresh(hp);
g = im2bw(f,T);
subplot(236),imshow(g),title('修改边缘后的阈值处理图像')

f = tofloat(imread("C:\matlabTuPian\photo\DIP3E_Original_Images_CH10\Fig1043(a)(yeast_USC).tif"));
subplot(2,2,1),imshow(f);title('(a) 酵母细胞的图像');
[TGlobal] = graythresh(f);
gGlobal = im2bw(f, TGlobal);
subplot(2,2,2),imshow(gGlobal);title('(b)用 Otsus 方法分割的图像');
g = localthresh(f, ones(3), 30, 1.5, 'global');
SIG = stdfilt(f, ones(3));
subplot(2,2,3), imshow(SIG, [ ]) ;title('(c) 局部标准差图像');
subplot(2,2,4),imshow(g);title('(d)  用局部阈值处理分割的图像 ');

I1=imread("C:\matlabTuPian\photo\DIP3E_Original_Images_CH10\Fig1049(a)(spot_shaded_text_image).tif");
T1=graythresh(I1);
I2=imbinarize(I1,T1);
I3=movingthresh(I1,20,0.5);
subplot(231),imshow(I1),title('原图');
subplot(232),imshow(I2),title('使用Otsu的处理结果');
subplot(233),imshow(I3),title('使用移动平均的处理结果');I4=imread("C:\matlabTuPian\photo\DIP3E_Original_Images_CH10\Fig1050(a)(sine_shaded_text_image).tif");
T2=graythresh(I4);
I5=imbinarize(I4,T2);
I6=movingthresh(I4,20,0.5);
subplot(234),imshow(I4),title('原图');
subplot(235),imshow(I5),title('使用Otsu的处理结果');
subplot(236),imshow(I6),title('使用移动平均的处理结果');

f = imread("C:\matlabTuPian\photo\DIP3E_Original_Images_CH06\Fig0621(a)(weld-original).tif");
subplot(2,2,1),imshow(f);
title('(a)显示有焊接缺陷的图像');
%函数regiongrow返回的NR为是不同区域的数目,参数SI是一副含有种子点的图像
%TI是包含在经过连通前通过阈值测试的像素
[g,NR,SI,TI]=regiongrow(f,1,0.26);%种子的像素值为255,65为阈值
subplot(2,2,2),imshow(SI);
title('(b)种子点');
subplot(2,2,3),imshow(TI);
title('(c)通过了阈值测试的像素的二值图像(白色)');
subplot(2,2,4),imshow(g);
title('(d)对种子点进行8连通分析后的结果');

f = imread("C:\matlabTuPian\photo\DIP3E_Original_Images_CH09\Fig0938(a)(cygnusloop_Xray_original).tif");
subplot(231),imshow(f),title('原始图像');
g32 = splitmerge(f,32,@predicate) %使用最小块为32进行分割
subplot(232),imshow(g32),title('使用最小块为32进行分割图像');
g16 = splitmerge(f,16,@predicate) %使用最小块为16进行分割
subplot(233),imshow(g16),title('使用最小块为16进行分割图像');
g8= splitmerge(f,8,@predicate) %使用最小块为8进行分割
subplot(234),imshow(g8),title('使用最小块为8进行分割图像');
g4 = splitmerge(f,4,@predicate) %使用最小块为4进行分割
subplot(235),imshow(g4),title('使用最小块为4进行分割图像');
g2 = splitmerge(f,2,@predicate) %使用最小块为2进行分割
subplot(236),imshow(g2),title('使用最小块为2进行分割图像');

f = imread("C:\matlabTuPian\photo\DIP3E_Original_Images_CH10\Fig1056(a)(blob_original).tif");
subplot(221),imshow(f),title('原始图像');
h = fspecial('sobel');
fd = tofloat(f);
g = sqrt(imfilter(fd,h,'replicate').^2+imfilter(fd,h,'replicate').^2);
subplot(222),imshow(g,[]),title('梯度和分水岭分割幅度图像');
L =watershed(g);
wr = L == 0;
subplot(223),imshow(wr),title('严重分割过分割后图像');
g2 = imclose(imopen(g,ones(3,3)),ones(3,3));
L2 = watershed(g2);
wr2 = L2 == 0;
f2 = f;
f2(wr2) = 255;
subplot(224),imshow(f2),title('平滑梯度图像后的分水岭变换');

f = imread("C:\matlabTuPian\photo\DIP3E_Original_Images_CH10\Fig1057(a)(small_blobs-original).tif");
subplot(241),imshow(f),title('原始图像');
h = fspecial('sobel');
fd = tofloat(f);
g = sqrt(imfilter(fd,h,'replicate').^2+imfilter(fd,h,'replicate').^2);
L =watershed(g);
wr = L == 0;
subplot(242),imshow(wr),title('梯度幅度图像进行分水岭变换图像');
rm = imregionalmin(g);  %计算图像中所有的局部小区域的位置
subplot(243),imshow(rm),title('梯度幅值的局部小区域图像');
im = imextendedmin(f,2);  %用于计算比临近点更暗的图像中“低点”的集合
fim = f;
fim(im) = 175;
subplot(244),imshow(f,[]),title('内部标记符图像');
Lim = watershed(bwdist(im));
em = Lim == 0;
subplot(245),imshow(em,[]),title('外部标记符图像');
g2 = imimposemin(g,im|em);  %用来修改一幅图像,使得其只在指定的位置处取得局部最小值
subplot(246),imshow(g2),title('修改后的梯度幅值图像');
L2 = watershed(g2);
f2 = f;
f2(L2 == 0) = 255;
subplot(247),imshow(f2),title('最后的分割图像');

数字图像处理——图像分割相关推荐

  1. 数字图像处理-图像分割-复习总结

    文章目录 数学图像处理 图像分割 图像分割基础 基于边界的图像分割(非连续性分割) 边缘检测 **一阶差分算子**(掌握) 二阶差分算子 边缘检测算子的比较(掌握) 基于阈值的图像分割(相似性分割) ...

  2. 数字图像处理-图像分割

    单色图像的分割算法通常基于图像亮度值的两个基本特性:不连续性和相似性.在第一种类别中,处理方法是基于亮度的突变来分割一幅图像,如图像中的边缘.在第二种类别中,主要方法是根据事先定义的准则把图像分割成相 ...

  3. matlab哈夫点线对偶运算,数字图像处理—图像分割—哈夫(Hough)变换及哈夫变换原理—检测直线...

    1.检测直线 n个点在一条直线上,连续的满足直线方程:同样,离散的也满足直线方程. 直线解决方法:先确定所有有任意2点决定的直线(需约 次运算以确定n(n - 1)/ 2条线).在找出接近具体直线的点 ...

  4. 数字图像处理第十章——图像分割

    数字图像处理第十章 数字图像处理---图像分割 (一)点.线和边缘检测 1.1 点检测 1.2 线检测 1.3 使用函数edge的边缘检测 (二)使用霍夫变换的线检测 2.1 函数hough 2.2 ...

  5. 数字图像处理实验目录

    matlab学习与操作和图像的傅里叶变换和频域处理 matlab学习与操作 实验内容: 6. 读入两幅彩色图像,并分别显示图像的尺寸信息,裁剪两幅图片为相同的正方形尺寸,并保存为两幅新的图片A和B. ...

  6. matlab图像处理ppt,数字图像处理(MATLAB版).ppt

    数字图像处理 图像分割 Contents Contents 8.1 图像分割定义 图像分割处理定义: 将数字图像划分成互不相交(不重叠)区域的过程. 区域(region) 定义: 像素的连通集. 连通 ...

  7. 数字图像处理——第十章 图像分割

    数字图像处理--第十章 图像分割 文章目录 数字图像处理--第十章 图像分割 写在前面 1 点.线和边缘检测 1.1 孤立点的检测 1.2 线检测 1.3 边缘检测 2 阈值处理 2.1 单一全局阈值 ...

  8. 数字图像处理之matlab实验(六):图像分割

    在图像处理领域,我们更关注的是一些关于目标的分析或者描述信息,比如图片里面是否有猫,以及是什么品种的猫?在在做这一步之前,我们需要先把图像中的猫分割出来.可以说图像分割是最基础也是最重要的一步操作,会 ...

  9. 数字图像处理第十章 图像分割

    图像分割 1 基础知识 2 点.线和边缘检测 2.1 点检测 2.2 线检测 2.3 边缘检测 3 使用霍夫变换的线检测 3.1 函数hough 3.2 函数houghpeaks和函数houghlin ...

最新文章

  1. MFC按钮添加提示文字
  2. 欢迎使用CSDN-markdown编辑器2018
  3. 强化学习(四)—— Actor-Critic
  4. 【JavaScript框架封装】实现一个类似于JQuery的缓存框架的封装
  5. myBatis异常提示For input string: {1=null}
  6. 第02讲:夯实根基,Web 网页基础
  7. 服务器此时无法接受控制信息,您无法修改域或信任信息,因为无法联系一个主域控制器(PDC)仿真器,请确认当前域的PDC仿真器和网络都联机并正常运行。...
  8. 为了搞清楚CDN的原理,我头都秃了...
  9. linux glibc安装mysql_Linux安装MySQL-5.6.24-1.linux_glibc2.5.x86_64.rpm
  10. @程序员,这份 2 万人收藏的计算机科学速成课速码!
  11. Mybatis学习笔记(九) —— Mybatis逆向工程
  12. mysql compopr_MySql应用的基本操作语句
  13. 机房管理--如何应对学生关闭极域电子教室
  14. 妇产科学习题---有答案
  15. 数字资产期权新手入门手册 | TokenInsight
  16. 马哥教育SRE笔记【作业】week04
  17. php-resque 简单的php消息队列
  18. 【word操作】论文页眉页脚设置
  19. linux中dd命令详解,Linux基础知识之dd命令详解
  20. 解决:springboot生成jar运行没有主清单属性

热门文章

  1. linux命令复制到桌面,技术|使用 xclip 在 Linux 命令行中复制粘贴
  2. C++第一章第十一题
  3. 转载 SqlTransaction 已完成;它再也无法使用”解决方法
  4. 激光SLAM生成并保存pcd点云地图
  5. matlab错误dparsfa,[转载]总结:新版dparsfA的文件夹内容旧版dparsf的总结
  6. 计算机来源与发展历程
  7. [转]文本框TextField的事件
  8. CAD发布为GeoServer地图服务
  9. 基于JAVA基于web的学校工资管理系统计算机毕业设计源码+系统+lw文档+部署
  10. 酷冷至尊NR200装机——教你没钱也能换电脑!