MATLAB 图像处理实例详解(六)--图像分割技术

图像分割技术

图像分割 : 根据灰度 , 颜色 , 纹理等,将图像进行分割.

常用的分割技术 :

边缘检测法  阈值分割法  区域分割法

阈值分割法 : 是最经典最流行的图像分割方法之一 , 也是最简单的分割方法 . 其关键是找合适的灰度阈值. 通常是根据图像的灰度

直方图来选取. 阈值分割特别适用于目标和背景处于不同灰度级范围的图像.

边缘分割技术

微分算子, Canny 算子 , LOG算子

常见的微分算子 : Sobel算子  Roberts 算子  Prewit 算子

图像中线段检测

函数 imfilter ( )

I = imread('gantrycrane.png');
I = rgb2gray(I);
h1 = [-1 -1 -1; 2 2 2; -1 -1 -1]; %水平
h2 = [-1 -1 2; -1 2 -1; 2 -1 -1]; %+45度
h3 = [-1 2 -1; -1 2 -1; -1 2 -1]; %竖直
h4 = [2 -1 -1; -1 2 -1; -1 -1 2]; %-45度

J1 = imfilter(I, h1); %线段检测
J2 = imfilter(I, h2);
J3 = imfilter(I, h3);
J4 = imfilter(I, h4);

J = J1 + J2 + J3 + J4; %四条线段叠加
figure;
subplot(121),imshow(I);
subplot(122),imshow(J);

微分算子

Roberts算子

函数 edge ( )

I = imread('rice.png');
I = im2double(I);
[J, thresh] = edge(I, 'Roberts', 35/255); %边缘检测 ,roberts算子, 阈值为归一化后的35/255
figure;
subplot(121),imshow(I);
subplot(122),imshow(J);

Prewitt 算子

函数 edge ( )

I = imread('cameraman.tif');
% I = imread('rice.png');
I = im2double(I);
[J, thresh] = edge(I, 'prewitt', [], 'both');%默认阈值, 从水平和竖直方向进行设置
figure;
subplot(121);imshow(I);
subplot(122);imshow(J);

Sobel 算子

函数 edge ( )

I = imread('gantrycrane.png'); %RGB彩色图
% imshow(I);
I = rgb2gray(I);
[J, thresh] = edge(I, 'sobel', [], 'horizontal');
figure;
subplot(121);imshow(I);
subplot(122);imshow(J);

Canny 算子

函数 edge ( )

LOG 算子

函数 edge ( )

I = imread('cameraman.tif');
I = im2double(I);
J = imnoise(I, 'gaussian', 0, 0.005);
[K, thresh] = edge(J, 'Log', [], 2.3);
figure;
subplot(121),imshow(I);
subplot(122),imshow(K);

Log 算子

阈值分割技术

全局阈值

直方图显示

I = imread('rice.png');
subplot(121),imshow(I);
subplot(122),imhist(I, 200); %直方图显示

全局阈值分割

I = imread('rice.png');
J = I > 120; %全局阈值为120 , 波谷大概是120
K = I > 130; %全局阈值为130
figure;
subplot(131),imshow(I);
subplot(132),imshow(J);
subplot(133),imshow(K);

Otsu阈值分割

I = imread('coins.png');
I = im2double(I);
T = graythresh(I); %获取阈值
J = im2bw(I, T); %图像分割
subplot(121),imshow(I);
subplot(122),imshow(J);

迭代式阈值分割法

clear, clc
I = imread('cameraman.tif');
I = im2double(I);
T0 = 0.01; %精度
% T1 = graythresh(I) %用Otsu求阈值
T1 = min(I(:)) + max(I(:)) / 2; %初始估计阈值
r1 = find(I > T1); %找出比阈值大的像素
r2 = find(I <= T1); %找出比阈值小的像素
T2 = (mean(I(r1)) + mean(I(r2))) / 2; %各个像素加和求平均
while abs(T2 - T1) < T0 %
    T1 = T2;
    r1 = find(I > T1);
    r2 = find(I <= T1);
    T2 = (mean(I(r1)) + mean(I(r2))) / 2;
end

J = im2bw(I, T2);
subplot(121),imshow(I);
subplot(122),imshow(J);

区域分割技术

区域生长法

将相邻的具有同种性质的像素或其他区域归并刀目前的区域中从而逐步增长区域

相似性度量 : 平均灰度值, 纹理, 颜色

缺点 : 往往造成过度分割

取决分割好坏的三个因素 : 种子点的选取  生长规则  终止条件

分水岭分割

clear,clc;
I = imread('circbw.tif');
J = watershed(I, 4); % 4个连通区域,默认为8
subplot(121),imshow(I);
subplot(122),imshow(J);

  • 54
    点赞
  • 443
    收藏
    觉得还不错? 一键收藏
  • 8
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值