How to get x,y coordinates of each pixels in a connected component ??

조회 수: 5 (최근 30일)
nayomi ranamuka
nayomi ranamuka 2011년 7월 8일
댓글: Walter Roberson 2021년 4월 6일
Dear all,
I = imread('image.jpg');
I2 = im2bw(I) ;
st = regionprops( I2, 'PixelIdxList', 'PixelList');
We can get pixelId list and pixels of connected components as above. But I need to get the x,y coordinates of each pixels. Anybody can help me?
Thank you..

답변 (4개)

Andrei Bobrov
Andrei Bobrov 2011년 7월 8일
st = regionprops( I2, 'PixelList');
xy=cat(1,st.PixelList)
xy(:,2) = abs(xy(:,2) - size(I2,1)) + 1
plot(xy(:,1),xy(:,2),'g*')

Sean de Wolski
Sean de Wolski 2011년 7월 8일
[y x] = find(I2)

Paulo Silva
Paulo Silva 2011년 7월 8일
bw = imread('text.png');
L = bwlabel(bw);
s = regionprops(L, 'centroid');
XY=[s.Centroid];
ax=axes
hold on
imshow('text.png','Parent',ax)
plot(ax,XY(1:2:end),XY(2:2:end),'*')
  댓글 수: 1
nayomi ranamuka
nayomi ranamuka 2011년 7월 8일
This is useful to get coordinates from user interface.But I need to get coordinates from pixel Ids. But I don't know that it's possible or not.
Thank you

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


Sergio Arango
Sergio Arango 2021년 4월 6일
[x,y]=size(I2);
[~,y2]=size(st.PixelIdxList);
for i=1:y2
locs(i,1)=rem(st.PixelIdxList{1,i}(1),x);
locs(i,2)=fix(st.PixelIdxList{1,i}(1)/y)+1;
end
This code gives you the locations of the first pixel in each region. I don't know if this one's helpful, but I hope so :)

Community Treasure Hunt

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

Start Hunting!

Translated by