Ich möchte die konvexe Hülle der Handfläche mit der Funktion convhull() erhalten. Ich arbeite an einem Bild, das nur eine Handfläche enthält. Zuerst habe ich es in ein Binärbild konvertiert und dann Convhull-Funktion angewendet. Aber es gibt mir nicht das gewünschte Ergebnis. Bitte finden Sie den Fehler in meinem Code. Hier ist mein Code:Convhull() gibt nicht das gewünschte Ergebnis.
thresh1 = 0;
thresh2 = 20;
image = imread('C:\Users\...\1_depth.png');
subplot(3,3,1)
imshow(image)
image_bin1 = (image < thresh2);
image_bin2 = (thresh1 < image);
image_bin = abs(image_bin2- image_bin1);
image_bin_filt = medfilt2(image_bin, [18,18]);
subplot(3,3,2)
imshow(imcomplement(image_bin_filt));
BW = im2bw(image_bin_filt, 0.5);
BW = imcomplement(BW);
subplot(3,3,3)
imshow(BW)
title('Binary Image of Hand');
BW2 = bwareaopen(BW, 1000);
subplot(3,3,4)
imshow(BW2)
[y,x] = find(BW2);
k = convhull(x,y);
subplot(3,3,5)
imshow(BW2,'InitialMagnification', 'fit')
hold on;
plot(x,y, 'b.')
plot(x(k), y(k), 'r', 'LineWidth', 2)
title('Objects Convex Hull');
% Find centroid.
labeledImage = bwlabel(BW2);
measurements = regionprops(labeledImage, 'Centroid', 'BoundingBox');
%xCentroid = measurements.Centroid(1);
% yCentroid = measurements.Centroid(2);
centroids = cat(1, measurements.Centroid);
subplot(3, 3, 6);
imshow(BW2);
title('Binary Image with Centroid Marked', 'FontSize', 12);
hold on;
plot(centroids(:,1),centroids(:,2), 'b*')
% Crop the image and display it in a new figure.
boundingBox = measurements.BoundingBox;
croppedImage = imcrop(BW2, boundingBox);
% Get rid of tool bar and pulldown menus that are along top of figure.
%set(gcf, 'Toolbar', 'none', 'Menu', 'none');
subplot(3,3,7)
imshow(croppedImage, []);
title('Cropped Image', 'FontSize', 12, 'Interpreter', 'None');
% Again trying to plot the convex hull
CH_objects = bwconvhull(BW);
subplot(3,3,8)
imshow(CH_objects);
title('Objects Convex Hull');
[r,c]=find(CH_objects);
CH=convhull(r,c);
subplot(3,3,9)
imshow(CH_objects)
hold on;
plot(r(CH),c(CH),'*-');
Hier wird das Ergebnis des Codes Ich erhalte: https://ibb.co/gLZ555 Aber es ist nicht das gewünschte Ergebnis. Die konvexe Hülle ist nicht richtig, sie sollte nur Handfläche und nicht freien Platz enthalten. Außerdem bekomme ich zwei Zentroide statt einer. Warum ist es so? Eingangsbild, das ich verwendete, ist: https://ibb.co/hk28Q5
Ich möchte konvexe Hülle der Palme, die nur Palme darin enthält, berechnen und dann Zentroid der Palme berechnen. Es wird hilfreich sein, um die Form der Handfläche zu erkennen.
Bitte antworten Sie mit der Lösung für die gewünschte Ausgabe.
Vielen Dank! Es funktionierte. :) – Prachi