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空间转换成Lab空间
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均值
MATLAB图像处理之分割处理
于 2021-03-27 08:38:56 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)