필터 지우기
필터 지우기

How to get xy coordinates from a binary image matrix

조회 수: 49 (최근 30일)
Ian Hersom
Ian Hersom 2016년 8월 1일
댓글: Ayesha Shafique 2019년 4월 18일
How do I get the xy coordinates of all the 1's in a binary matrix?

채택된 답변

Chad Greene
Chad Greene 2016년 8월 1일
If M is your matrix and it looks like this:
M = logical(randi(2,5)-1)
M =
0 0 1 0 1
0 1 0 1 1
1 1 0 1 0
1 0 0 1 0
0 0 1 1 1
find the rows and colums of each 1 in M by
[rows,cols] = find(M)
Then x and y are whatever x and y values you have that correspond to the rows and columns of M.
  댓글 수: 2
Image Analyst
Image Analyst 2016년 8월 1일
And Ian, be careful to not make the very common beginner mistake of thinking (x,y) = (rows, columns). So if you want the variables to be names x and y, or xy, then do this:
[y, x] = find(M); % x and y are column vectors.
xy = [x, y]; % Two columns. Column 1=x, column 2=y;
DO NOT do what so many beginners do:
[x, y] = find(M); % WRONG!
Ayesha Shafique
Ayesha Shafique 2019년 4월 18일
Hi Sir,
Attached is the signal whose x y coordinates we want to extract. The one in yellow color making a wave-like pattern.
On x-axis: time
On y-axis: velocity
So that after getting the data points, if we plot these values in excel, it should draw/ exhibit the same wave pattern.
Any help would be appreciated.

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

추가 답변 (1개)

Juan Alberto Antonio Velazquez
Juan Alberto Antonio Velazquez 2018년 5월 3일
if you want to find the center of mass of a binary image
%Codigo que sirve para encontrar el centro de masa de una objeto en una %imagen clc; clear all; close all; dir='/Users/jalberto/Documents/PROYECTO DETECCION DE PERSONAS/ACTIVESHAPEMODEL/ASMNEW/ModeloFondo/Testing/fotomov1/sinfondo138'; I = imread([dir,'.png']); Im=im2bw(I); %figure, imshow(Im); [y,x]=find(Im==1); xy=[x,y]; media=mean(xy); figure, imshow(Im); hold on plot(media(:,1),media(:,2),'*b');
by Juan Alberto Antonio Velazquez from Toluca, México

카테고리

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