convert xy coordinates into binary matrix
古いコメントを表示
I have XY coordinates of shape boundary. the points are double and I show an example on the figure. How can I represent these points in a binary matrix?
Thanks already

回答 (1 件)
Walter Roberson
2018 年 9 月 7 日
編集済み: Walter Roberson
2018 年 9 月 28 日
0 投票
5 件のコメント
AA
2018 年 9 月 7 日
Walter Roberson
2018 年 9 月 7 日
poly2mask creates the binary matrix which is all you asked for in "How can I represent these points in a binary matrix?". If you want to display the binary matrix you can do so with
image(TheBinaryMatrix); colormap(gray(2))
or with
imshow(TheBinaryMatrix);
Or are you trying to create and display a binary matrix and also draw the original plot on top of it? Or is the problem that the displayed binary matrix is not blue line with a white background?
image(TheBinaryMatrix);
colormap([1 1 1; 0 0 1]);
Daniel Devaprakash
2018 年 9 月 28 日
編集済み: Walter Roberson
2018 年 9 月 28 日
Hi Walter,
I have x (ranging from 3-4), y (0-1) coordinates of a contour (92 values); convert it into shape using alpha shape function, and then use the poly2mask function to obtain the binary image. The binary image matrix has 1 in only one element of the matrix and the rest are 0's.
For the binary image to represent the actual shape, I multiplied the co-ordinate values by 100, and then the binary image resembled the actual shape.
Code snippet:
x = x.*100; y = y.*100;
shape = alphaShape(x,y);
shape.Alpha = 1;
bw =poly2mask(shape.Points(:,1)',shape.Points(:,2)',256,256);
imshow(bw); colormap([1 1 1; 0 0 1]);
Could you please let me know if this is the correct approach to solve this problem Thank you for your time and help.
Cheers,
Danny Devaprakash
Walter Roberson
2018 年 9 月 28 日
You are retrieving the original points, not any information about the alpha shape implied by the points.
Daniel Devaprakash
2018 年 9 月 28 日
Hi Walter,
Thank you for your help.
Cheers, Danny Devaprakash
カテゴリ
ヘルプ センター および File Exchange で Surface and Mesh Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!