Help me to resolve this Error In My GUI ( I am doing hand signal recognition) - An empty cluster error occurred in every replicate.

1 view (last 30 days)
I already made the GUI and snapshot working well, meanwhile sometimes I got this error can some1 explain it to me why?
THIS IS THE ERROR
??? Error using ==> kmeans at 382
An empty cluster error occurred in every replicate.
Error in ==> segmentizeImage1 at 12
[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
REFER THE CODE BELOW ( I used it to track and crop the hand automatically):
warning off stats:kmeans:EmptyCluster;
rawImage = x; %x = is the image taken on snapshot
I = rawImage;
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.000);
s = regionprops(rgb_label, I, {'Centroid','BoundingBox'});
% s(hand_cluster_num).Centroid
% s(hand_cluster_num).BoundingBox
centroid_x = uint16(s(hand_cluster_num).Centroid(1));
centroid_y = uint16(s(hand_cluster_num).Centroid(2));
cropped_x = uint16(s(hand_cluster_num).BoundingBox(1))+1;
cropped_y = uint16(s(hand_cluster_num).BoundingBox(2))+1;
cropped_w = uint16(s(hand_cluster_num).BoundingBox(4))-2;
cropped_h = uint16(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');
y = M;
z = imresize(y, [40 30]);
z = z(:);

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!