MATLAB图像处理之分割处理

该博客介绍了如何使用MATLAB进行图像处理,通过读取图像并转换为Lab颜色空间,计算不同颜色区域的均值,然后利用欧氏距离确定像素所属颜色类别,最终实现图像的颜色分割,分别展示了分割后的红色、绿色、紫色、红紫色和黄色目标。
摘要由CSDN通过智能技术生成

fabric = imread(‘fabric.png’);%读取图像
figure; subplot(121); imshow(fabric), %显示
title(‘fabric’);
load regioncoordinates;%下载颜色区域坐标到工作空间
nColors = 6;
sample_regions = false([size(fabric,1) size(fabric,2) nColors]);
for count = 1:nColors
sample_regions(:,:,count) = roipoly(fabric,…
region_coordinates(:,1,count), …
region_coordinates(:,2,count));%选择每一小块颜色的样本区域
end
subplot(122),
imshow(sample_regions(:,:,2));%显示红色区域的样本
title(‘sample region for red’);
cform = makecform(‘srgb2lab’);%rgb空间转换成Lab空间结构
lab_fabric = applycform(fabric,cform);%rgb空间转换成L
ab空间
a = lab_fabric(:,:,2); b = lab_fabric(:,:,3);
color_markers = repmat(0, [nColors, 2]);%初始化颜色均值
for count = 1:nColors
color_markers(count,1)= mean2(a(sample_regions(:,:,count)));%a均值
color_markers(count,2)= mean2(b(sample_regions(:,:,count)));%b均值

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值