I have a binary image with white object and black background. How can I get the pixel coordinate for the center of the white image?
조회 수: 3 (최근 30일)
이전 댓글 표시
Attached is the starting RGB image, and I was able to isolate the colors and convert the shape I want to Binary where the background is black and the shape I want is white. How do I get the coordinates for the center of he the white image?
댓글 수: 0
답변 (2개)
Image Analyst
2016년 4월 14일
You forgot to attach the image, but anyway to get the (x,y) coordinates of the white pixels, do this:
[y, x] = find(binaryImage);
댓글 수: 4
gokool surya
2018년 4월 20일
Hello Image Analyst. I am interested in finding the parking spots from a black and white image and extracting the regions that were white (targets) and finding the co-ordinates of this region. For example, in the above comment, if the [y, x] gives us x = 3388x1 and y = 3388x1. There are many 'x' for one 'y' and vice versa. I am not sure how to proceed. Any help would be highly appreciated. Thanks in Advance
Image Analyst
2018년 4월 20일
I don't know what you have or what you want. If you have the binary image with white (targets) already segmented out, what exactly do you want to know? find() will give you the coordinates of all the pixels. So will regionprops(binaryImage, 'PixelList') will also give it to you. But I don't know why you need all the coordinates. Actually the binary image is already one representation of all the coordinates. But what are you going to do with them? Do you want the bounding box or centroid also or instead?
Zeinab Moradi
2021년 1월 30일
could you please help me how to find the center of a black object in white background ... additionall i want to know the coordinate of black pixels.... i am looking forward for yyour helppp...thank youuu
댓글 수: 1
Image Analyst
2021년 1월 30일
binaryImage = grayImage < 128; % Or whatever threshold works.
imshow(binaryImage);
title('BinaryImage', 'FontSize', 20);
drawnow;
props = regionprops(binaryImage, grayImage, 'Centroid', 'WeightedCentroid');
% Plot the centroid(s) in red and the weighted centroids in green.
imshow(grayImage);
hold on;
for k = 1 : numel(props)
plot(props(k).Centroid(1), props(k).Centroid(2), 'r+', 'MarkerSize', 30, 'LineWidth', 2);
plot(props(k).WeightedCentroid(1), props(k).WeightedCentroid(2), 'g+', 'MarkerSize', 30, 'LineWidth', 2);
end
title('Gray Image with weighted and unweighted centroids', 'FontSize', 20);
drawnow;
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!