https://www.docin.com/p-635866924.html
关于这片文章自己的实现
clear;
clc;
I=imread(‘d:\新建文件夹\724.jpg’);
figure();
imshow(I);
title(‘原图像’);
c=makecform(‘srgb2lab’);
I_lab=applycform(I,c);
ab=double(I_lab(:,:,2:3))
nrows=size(ab,1)
ncols=size(ab,2)
ab=reshape(ab,nrows*ncols,2)
ncolors=3;
[cluster_idx,cluster_center]=kmeans(ab,ncolors,‘distance’,‘sqEuclidean’,‘Replicates’,3);
pixel_labels=reshape(cluster_idx,nrows,ncols);
figure()
imshow(pixel_labels,[]);
title(‘聚类结果’);
segmented_images=cell(1,3);
rgb_labels=repmat(pixel_labels,[1 1 3]);
for k=1:ncolors
color=I;
color(rgb_labels~=k)=0;
segmented_images{k}=color;
end
figure();
imshow(segmented_images{1});
title(‘分割结果——区域1’);
figure();
imshow(segmented_images{2});
title(‘分割结果——区域2’);
figure();
imshow(segmented_images{3});
title(‘分割结果——区域3’);
OTSU阈值分割的实例
最新推荐文章于 2024-10-15 09:51:52 发布