0

我正在使用自组织地图进行图像分割。由 3 个集群进行图像分割。示例图像是: 在此处输入图像描述

我已经像下面这样输入了matlab代码:

clear;
clc;
i=imread('DataSet/3.jpg'); 
I = imresize(i,0.5);
cform = makecform('srgb2lab');
lab_I = applycform(I,cform);
ab = double(lab_I(:,:,2:3));
nrows = size(ab,1);
ncols = size(ab,2);
ab = reshape(ab,nrows*ncols,2);
a = ab(:,1);
b = ab(:,2);
normA = (a-min(a(:))) ./ (max(a(:))-min(a(:)));
normB = (b-min(b(:))) ./ (max(b(:))-min(b(:)));
ab = [normA normB];
newnRows = size(ab,1);
newnCols = size(ab,2);
cluster = 3;
% Max number of iteration
N = 90;
% initial learning rate
eta = 0.3;
% exponential decay rate of the learning rate
etadecay = 0.2;
%random weight

w = rand(2,cluster);
%initial D
D = zeros(1,cluster);
% initial cluster index
clusterindex = zeros(newnRows,1);
% start 
for t = 1:N
   for data = 1 : newnRows
       for c = 1 : cluster
           D(c) = sqrt(((w(1,c)-ab(data,1))^2) + ((w(2,c)-ab(data,2))^2));
       end
       %find best macthing unit
       [~, bmuindex] = min(D);
       clusterindex(data)=bmuindex;

       %update weight
       oldW = w(:,bmuindex);
       new = oldW +  eta * (reshape(ab(data,:),2,1)-oldW);
       w(:,bmuindex) = new;

   end
   % update learning rate
   eta= etadecay * eta;
end

%Label Every Pixel in the Image Using the Results from KMEANS
pixel_labels = reshape(clusterindex,nrows,ncols);
%Create Images that Segment the I Image by Color.
segmented_images = cell(1,3);
rgb_label = repmat(pixel_labels,[1 1 3]);

for k = 1:cluster
    color = I;
    color(rgb_label ~= k) = 0;
    segmented_images{k} = color;
end
figure,imshow(segmented_images{1}), title('objects in cluster 1');
figure,imshow(segmented_images{2}), title('objects in cluster 2');
figure,imshow(segmented_images{3}), title('objects in cluster 3');

运行matlab代码后,没有图像分割结果。Matlab显示3图,图1显示完整图像,图2空白,图3空白。

请任何人帮我修改我的matlab代码,是任何错误的代码还是什么?

4

1 回答 1

0

new = oldW + eta * (reshape(ab(data,:),2,1)-oldW);

这条线对我来说看起来很可疑,为什么你在这里减去旧的权重,我认为这在那里没有任何意义,只需从那里删除 oldW 并再次检查你的结果。

谢谢你

于 2016-01-14T06:46:39.163 回答