# 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?

조회 수: 20(최근 30일)
Aamil Patel 2016년 4월 14일
댓글: Image Analyst 2021년 1월 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?

댓글을 달려면 로그인하십시오.

### 답변(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표시숨기기 이전 댓글 수: 3
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?

댓글을 달려면 로그인하십시오.

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;

댓글을 달려면 로그인하십시오.

### Community Treasure Hunt

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

Start Hunting!

Translated by