《MATLAB图像处理实例详解》:CH_7(图像分割技术)

本文详细探讨了MATLAB中图像分割的应用,包括提取线段、微分算子、阈值分割和区域分割技术,为图像处理提供实用方法。
摘要由CSDN通过智能技术生成

图像分割技术

①提取线段

close all;clear all;clc;
I=imread('E:\Matlab_exercise\图片素材\xianduan.jpg');
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];%135°斜线
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算子
close all;clear all;clc;
I=imread('E:\Matlab_exercise\图片素材\gray.jpg');
I=im2double(I);
[J,thresh]=edge(I,'roberts',35/255);%边缘检测,采用Roberts算子,图像分割阈值为35/255
figure;
subplot(121);imshow(I);
subplot(122);imshow(J);

%prewitt算子
close all;clear all;clc;
I=imread('E:\Matlab_exercise\图片素材\gray.jpg');
I=im2double(I);
[J,thresh]=edge(I,'prewitt',[],'both');%边缘检测,水平和垂直边缘都检测
figure;
subplot(121);imshow(I);
subplot(122);imshow(J);

%sobel算子
%eg.1
close all;clear all;clc;
I=imread('E:\Matlab_exercise\图片素材\gray.jpg');
I=im2double(I);
[J,thresh]=edge(I,'sobel',[],'horizontal');%边缘检测,检测水平边缘
figure;
subplot(121);imshow(I);
subplot(122);imshow(J);

%eg.2
close all;clear all;clc;
I = imread('E:\Matlab_exercise\图片素材\lenn.jpg');
subplot(241);imshow(I,[]);title('原图');

J1 = edge(I,'sobel',0.06);
subplot(242);imshow(J1,[]);title('sobel 0.06');
J2 = edge(I,'sobel',0.09);</
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值