MATLAB图像处理之分割处理

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均值

你可能感兴趣的:(MATLAB可视化,opencv,计算机视觉,matlab,深度学习)