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!