How to find the center co-ordinates of different regions

조회 수: 1 (최근 30일)
Tania
Tania 2015년 5월 11일
댓글: Tania 2015년 5월 11일
Hi there,
Can anyone assist me how to find the center co-ordinates automatically and save the co-ordinate (x and y position) values in an array automatically? The shapes are different for the regions but each region has same pixel value.
Please have a look at my image and guide me how to find the center co-ordinates of each region and save them in an array automatically without using manual operation.
Any help will be highly appreciated.

채택된 답변

Image Analyst
Image Analyst 2015년 5월 11일
편집: Image Analyst 2015년 5월 11일
I thought you'd seen it before, but I guess not. See my image segmentation tutorial in my File Exchange http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862
Basically it's something like
grayImage = rgb2gray(rgbImage);
[labeledImage, numberOfBlobs] = bwlabel(grayImage ~= 0);
measurements = regionprops(labeledImage, 'Centroid');
allCentroids = [measurements.Centroid];
xCentroids = allCentroids(1:2:end);
yCentroids = allCentroids(2:2:end);
  댓글 수: 7
Image Analyst
Image Analyst 2015년 5월 11일
If you want to treat the black background as its own object, then you'll have to do that separately (well, that's the simplest and most straightforward way).
grayImage = rgb2gray(rgbImage);
[labeledImage, numberOfBlobs] = bwlabel(grayImage == 0);
measurements = regionprops(labeledImage, 'Centroid');
allCentroids = [measurements.Centroid];
xCentroids = allCentroids(1:2:end);
yCentroids = allCentroids(2:2:end);
Note the == 0 instead of ~= 0 so that we pick up only pure black pixels.
Tania
Tania 2015년 5월 11일
Thank you very much. That solved my problem.
Great help

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Statistics and Machine Learning Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by