spatial coordinates of BW image

조회 수: 1 (최근 30일)
MANI MANI
MANI MANI 2013년 11월 6일
편집: Jan 2013년 11월 6일
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.

채택된 답변

Image Analyst
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
MANI MANI
MANI MANI 2013년 11월 6일
Thanks..it works.. I hv got a circle on pupil for which I need spatial coordinates.
Image Analyst
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
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
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.
Jan
Jan 2013년 11월 6일
편집: Jan 2013년 11월 6일
right, that should read res=[col, row] and equals your answer.
However, I only saw your answer after I posted mine, so it's futile anyway.

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

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by