Azzera filtri
Azzera filtri

i have detected a object in a scene image , now i want to find centroid coordinates of this object in a whole image . How do i get this ?

2 visualizzazioni (ultimi 30 giorni)
A = imread('11.jpg');
boxImage=rgb2gray(A);
figure;
imshow(boxImage);
title('Image of a Object to be Detected');
B = imread('2.jpg');
sceneImage=rgb2gray(B);
figure;
imshow(sceneImage);
title('Image of a Cluttered Scene');
boxPoints = detectSURFFeatures(boxImage);
scenePoints = detectSURFFeatures(sceneImage);
figure;
imshow(boxImage);
title('100 Strongest Feature Points from Object Image');
hold on;
plot(selectStrongest(boxPoints, 100));
figure;
imshow(sceneImage);
title('300 Strongest Feature Points from Scene Image');
hold on;
plot(selectStrongest(scenePoints, 300));
[boxFeatures, boxPoints] = extractFeatures(boxImage, boxPoints);
[sceneFeatures, scenePoints] = extractFeatures(sceneImage, scenePoints);
boxPairs = matchFeatures(boxFeatures, sceneFeatures);
matchedBoxPoints = boxPoints(boxPairs(:, 1), :);
matchedScenePoints = scenePoints(boxPairs(:, 2), :);
figure;
showMatchedFeatures(boxImage, sceneImage, matchedBoxPoints, ...
matchedScenePoints, 'montage');
title('Putatively Matched Points (Including Outliers)');
[tform, inlierBoxPoints, inlierScenePoints] = ...
estimateGeometricTransform(matchedBoxPoints, matchedScenePoints, 'affine');
figure;
showMatchedFeatures(boxImage, sceneImage, inlierBoxPoints, ...
inlierScenePoints, 'montage');
title('Matched Points (Inliers Only)');
boxPolygon = [1, 1;... % top-left
size(boxImage, 2), 1;... % top-right
size(boxImage, 2), size(boxImage, 1);... % bottom-right
1, size(boxImage, 1);... % bottom-left
1, 1]; % top-left again to close the polygon
newBoxPolygon = transformPointsForward(tform, boxPolygon);
figure;
imshow(sceneImage);
hold on;
line(newBoxPolygon(:, 1), newBoxPolygon(:, 2), 'Color', 'y');
title('Detected Box');
plot(centroids(:,1), centroids(:,2), 'b*');
hold off

Risposte (2)

Brahmadev
Brahmadev il 29 Set 2023
Hi Avinash,
You can find the centroid of the detected image using the following code:
% Defining a polygon of Datatype polyshape for use in "centroid" as input
polyin = polyshape(newBoxPolygon(1:4, 1),newBoxPolygon(1:4, 2));
% Finding the centroid
[centroidPosX, centroidPosY] = centroid(polyin);
hold on
plot(centroidPosX, centroidPosY, "ro") % Plotting the centroid in the same figure
You can refer to the following documentation for more information on the “centroid” function:
Hope this helps in finding the centroid!

Image Analyst
Image Analyst il 29 Set 2023
It's a generic, general purpose demo of how to threshold an image to find blobs, and then measure things about the blobs (like centroid and bounding box, etc.), and extract certain blobs based on their areas or diameters.

Community Treasure Hunt

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

Start Hunting!

Translated by