spatial coordinates of BW image
1 回表示 (過去 30 日間)
古いコメントを表示
I have a BW image in which few pixels are white rest all are black.. I want to store the spatial co-ordinates of only white pixels in to 2D matrix having only 2 columns(to represent x y coordinates) and any number of rows.. How do I do that? Pl. help me.
0 件のコメント
採用された回答
Image Analyst
2013 年 11 月 6 日
I don't know why that would be necessary, but if you insist:
[rows, columns] = find(BW); % 2 1-D vectors.
xy = [columns, rows]; % Stitch together to form N by 2 (x,y) array.
2 件のコメント
Image Analyst
2013 年 11 月 6 日
Why? The binary already is the coordinates. You don't need the x,y or row,col coordinates unless you are going to do some kind of inefficient loop instead of the faster vectorized method. Tell me what you want to do and I can help you avoid slowing down your program by looping over x,y or col,row.
その他の回答 (1 件)
Jan
2013 年 11 月 6 日
Use find()
e.g.
A = randn(100,100) > .5; % example binary image
[row col] = find( A == 1 );
res = [ row col ];
This should give you the locations of the pixels containing a '1' in the matrix res.
2 件のコメント
Image Analyst
2013 年 11 月 6 日
res =[row col] is not (x,y) with your method - it's (y,x) because row = y and col = x.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!