How to convert row and column data into x,y,flag format?

6 ビュー (過去 30 日間)
Kayleigh Jayne Moloney
Kayleigh Jayne Moloney 2019 年 5 月 15 日
コメント済み: Rik 2019 年 5 月 15 日
I want to store row and column data for BW1 file.
Data is stored in an array like so:
I want to have a file like:
X Y FLAG
1 1 0
2 1 1
3 1 1
4 1 0
5 1 1
1 2 0
2 2 1
3 2 0
4 2 1
5 2 0
X corresonds to column number.
Y corresonds to row number.
Flag number is the number already stored in the array corresponding to the row and column number.
Code:
A=imread('inismor1.jpg');
G=rgb2gray(A);
BW1=edge(G,'canny');
imshow(BW1)

回答 (2 件)

Rik
Rik 2019 年 5 月 15 日
BW1=[0 0 1;1 1 0];%example matrix
[Y,X]=ndgrid(1:size(BW1,1),1:size(BW1,2));
data=[X(:) Y(:) BW1(:)];
  2 件のコメント
Kayleigh Jayne Moloney
Kayleigh Jayne Moloney 2019 年 5 月 15 日
Thank you so much!!
Rik
Rik 2019 年 5 月 15 日
You're welcome. If my answer helped you, please consider marking it as accepted answer (unless you prefer the solution provided by Andrei). If it didn't solve your question, don't hesitate to post a comment explaining your remaining issues.

サインインしてコメントする。


Andrei Bobrov
Andrei Bobrov 2019 年 5 月 15 日
out = [fullfact(size(BW1)),BW1(:)];

カテゴリ

Help Center および File ExchangeImages についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by