How to get x,y coordinates of each pixels in a connected component ??
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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..
0 comentarios
Respuestas (4)
Andrei Bobrov
el 8 de Jul. de 2011
st = regionprops( I2, 'PixelList');
xy=cat(1,st.PixelList)
xy(:,2) = abs(xy(:,2) - size(I2,1)) + 1
plot(xy(:,1),xy(:,2),'g*')
0 comentarios
Paulo Silva
el 8 de Jul. de 2011
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),'*')
Sergio Arango
el 6 de Abr. de 2021
[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 :)
1 comentario
Walter Roberson
el 6 de Abr. de 2021
That looks to me as if it could be written in terms of ind2sub()
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!