資源簡介
基于lab空間下的圖像分割,matlab代碼,適合初學(xué)分割的人
代碼片段和文件信息
fabric?=?imread(‘d:\cs\DSC02030.JPG‘);%讀取圖像
figure;?subplot(121);?imshow(fabric)?%顯示
title(‘fabric‘);
load?regioncoordinates;%下載顏色區(qū)域坐標(biāo)到工作空間
nColors?=?6;
sample_regions?=?false([size(fabric1)?size(fabric2)?nColors]);
for?count?=?1:nColors
??sample_regions(::count)?=?roipoly(fabric...
??region_coordinates(:1count)?...
??region_coordinates(:2count));%選擇每一小塊顏色的樣本區(qū)域
end
subplot(122)
imshow(sample_regions(::2));%顯示紅色區(qū)域的樣本
title(‘sample?region?for?red‘);
cform?=?makecform(‘srgb2lab‘);%rgb空間轉(zhuǎn)換成L*a*b*空間結(jié)構(gòu)
lab_fabric?=?applycform(fabriccform);%rgb空間轉(zhuǎn)換成L*a*b*空間
a?=?lab_fabric(::2);?b?=?lab_fabric(::3);
color_markers?=?repmat(0?[nColors?2]);%初始化顏色均值
for?count?=?1:nColors
color_markers(count1)=?mean2(a(sample_regions(::count)));%a均值
color_markers(count2)=?mean2(b(sample_regions(::count)));%b均值
end
disp(sprintf(‘[%0.3f%0.3f]‘color_markers(21)...
????color_markers(22)));%顯示紅色分量樣本的均值
color_labels?=?0:nColors-1;
a?=?double(a);?b?=?double(b);
distance?=?repmat(0[size(a)?nColors]);%初始化距離矩陣
for?count?=?1:nColors
??distance(::count)?=?(?(a?-?color_markers(count1)).^2?+?...
?????(b?-?color_markers(count2)).^2?).^0.5;%計算到各種顏色的距離
end
[val
評論
共有 條評論