今天早些时候,我正在编写一个基于http://www.mathworks.com/products/demos/image/color_seg_k/ipexhistology.html和Matlab答案的脚本。
在运行脚本多次时,我发现当finalSegmentedImage=segmented_images{1}用于组合图像(Icombine)时,得到的图像是不同的。为什么?如何解决这个问题,使结果重复(例如,segmented_images {1}图像将始终相同)?
非常感谢。
这是图片:
clc;
clear;
close all;
input_im=imread('C:\Users\Udell\Desktop\T2.jpg');
sz_im=size(input_im);
cform = makecform('srgb2lab');
lab_he = applycform(input_im,cform);
ab = double(lab_he(:,:,2:3));
nrows = size(ab,1);
ncols = size(ab,2);
ab = reshape(ab,nrows*ncols,2);
nColors = 3;
% repeat the clustering 3 times to avoid local minima
[cluster_idx, cluster_center] = kmeans(ab,nColors,'distance','sqEuclidean', 'Replicates',3);
pixel_labels = reshape(cluster_idx,nrows,ncols);
%imshow(pixel_labels,[]), title('image labeled by cluster index');
segmented_images = cell(1,3);
rgb_label = repmat(pixel_labels,[1 1 3]);
for k = 1:nColors
color = input_im;
color(rgb_label ~= k) = 0;
segmented_images{k} = color;
end
for k=1:nColors
%figure
title_string=sprintf('objects in cluster %d',k);
%imshow(segmented_images{k}), title(title_string);
end
finalSegmentedImage=segmented_images{1};
%imshow(finalSegmentedImage);
close all;
Icombine = [input_im finalSegmentedImage];
imshow(Icombine);
在运行脚本多次时,我发现当finalSegmentedImage=segmented_images{1}用于组合图像(Icombine)时,得到的图像是不同的。为什么?如何解决这个问题,使结果重复(例如,segmented_images {1}图像将始终相同)?
非常感谢。
这是图片:
Replicates
的意思是你想要重复分割那么多次,每次使用不同的初始点集。让我修改一下。 - rayryengReplicates
标志。 - rayryeng