Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: please someone help me to fix this error(Error using ==> kmeans at 382 An empty cluster error occurred in every replicate)
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  
john john

Posts: 18
Registered: 6/22/11
please someone help me to fix this error(Error using ==> kmeans at 382 An empty cluster error occurred in every replicate)
Posted: Feb 15, 2012 10:43 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

??? Error using ==> kmeans at 382 An empty cluster error occurred in every replicate.

Error in ==> segmentizeImage1 at 25 [cluster_idx cluster_center] = kmeans(ab,nColors,'distance','sqEuclidean', ...

Error in ==> bui_simple>start_snap_Callback at 108 segmentizeImage1;

Error in ==> gui_mainfcn at 96 feval(varargin{:});

Error in ==> bui_simple at 42 gui_mainfcn(gui_State, varargin{:});

Error in ==> @(hObject,eventdata)bui_simple('start_snap_Callback',hObject,eventdata,guidata(hObject))

??? Error while evaluating uicontrol Callback


the code is working, it can captures and recognize data, the problem later on it will goes into that error, can some1 explain it to me why it give's error? is it bug on kmeans.m on toolbox?


REFER TO THIS CODE BELOw:
x = wa; % this is where the image get from snapshot on video
rawImage = x;
I = imresize(rawImage,0.50);
cform = makecform('srgb2lab');
J = applycform(I,cform);
ab = double(J(:,:,2:3));
nrows = size(ab,1);
ncols = size(ab,2);
ab = reshape(ab,nrows*ncols,2);
nColors = 2;
[cluster_idx cluster_center] = kmeans(ab,nColors,'distance','sqEuclidean', ...
'Replicates',2);
pixel_labels = reshape(cluster_idx,nrows,ncols);
segmented_images = cell(1,2);
rgb_label = repmat(pixel_labels,[1 1 3]);
for k = 1:nColors
color = I;
color(rgb_label ~= k) = 0;
segmented_images{k} = color;
end
mean_cluster_value = mean(cluster_center,2);
[tmp, idx] = sort(mean_cluster_value);
hand_cluster_num = idx(2);
K = segmented_images{hand_cluster_num};
L = im2bw(segmented_images{hand_cluster_num},0.001);
s = regionprops(rgb_label, I, {'Centroid','BoundingBox'});
% s(hand_cluster_num).Centroid
% s(hand_cluster_num).BoundingBox
centroid_x = uint8(s(hand_cluster_num).Centroid(1));
centroid_y = uint8(s(hand_cluster_num).Centroid(2));
cropped_x = uint8(s(hand_cluster_num).BoundingBox(1))+1;
cropped_y = uint8(s(hand_cluster_num).BoundingBox(2))+1;
cropped_w = uint8(s(hand_cluster_num).BoundingBox(4))-2;
cropped_h = uint8(s(hand_cluster_num).BoundingBox(5))-2;
% apply gaussian blur to remove noise
PSF = fspecial('gaussian',7,10);
L = imfilter(L,PSF,'symmetric','conv');
% cropped region of interest from main image
M = L( cropped_y : (cropped_y+cropped_h), cropped_x: (cropped_x+cropped_w) );
% trim leading and leading zeroes
M(:, logical(sum(abs(M)) == 0)) = [];
cropped_h = size(M,1);
cropped_w = size(M,2);
non_zeroes = find(sum(abs(L))~=0);
cropped_x = non_zeroes(1);
% fill holes to remove flares
M = imfill(M, 'holes');
% get a shrunk sample from cropped image
N = imresize(M, 0.25);
[sample_height sample_width] = size(N);
% clip excess pixels
if(sample_height>50)
N = N(1:50,:);
end
if(sample_width>50)
N = N(:,1:50);
end
[sample_height sample_width] = size(N);
%pad both sides
htopad = double(25 - ceil(sample_height/2));
wtopad = double(25 - ceil(sample_width/2));
if((htopad>=0)&&(wtopad>=0))
N = padarray(N,[htopad wtopad]);
%for uneven padding, add padding to end
[sample_height sample_width] = size(N);
htopad = 50 - sample_height;
wtopad = 50 - sample_width;
N = padarray(N,[htopad wtopad],0,'post');
else
disp('Padding not performed...');
end
imshow(M);
%hold on;
% plot(centroid_x, centroid_y, 'bo');
% rectangle('Position', [ cropped_x cropped_y cropped_w cropped_h ], 'EdgeColor','y');
% hold off;
y = N;
z = imresize(y, [40 30]);
z = z(:);



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.