Finding the centroid of a binary image
古いコメントを表示
vid_c111=read(v,1);
J = imcrop( vid_c111,[766 212 80 150]);
fontSize = 20;
subplot(2, 1, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize, 'Interpreter', 'None');
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
binaryImage = grayImage > 150;
[rows, columns, numberOfColorBands] = size(J);
if numberOfColorBands > 1
grayImage = J(:, :, 3);
end
binaryImage = bwareaopen(binaryImage, 1000);
subplot(2, 1, 2);
imshow(binaryImage, []);
title('Binary Image', 'FontSize', fontSize, 'Interpreter', 'None');
labeledImage = bwlabel(binaryImage, 8);
blobMeasurements = regionprops(labeledImage, 'Centroid');
numberOfBlobs = size(blobMeasurements, 1);
hold on;
for k = 1 : length(blobMeasurements)
x = blobMeasurements(k).Centroid(1);
y = blobMeasurements(k).Centroid(2);
plot(x, y, 'r+', 'MarkerSize', 30, 'LineWidth', 3);
end
The code above was what I used to try and find the centroid of two blobs in my image. Instead of finding the center, it only found the center of the entire image. Any help???
3 件のコメント
Guillaume
2018 年 4 月 17 日
What do the grayImage and binaryImage look like in your figure?
Also, you are aware that you're not using the video frame you've just loaded, but some other image that is already in grayImage before you load that frame?
Guillaume
2018 年 4 月 17 日
Please don't edit your question to remove the useful parts nor remove your comments as it is necessary context to the answer you've accepted.
Rena Berman
2018 年 5 月 15 日
(Answers Dev) Restored edit
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Image Processing Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!