How to get xy coordinates from a binary image matrix

29 次查看(过去 30 天)
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
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 中查找有关 Geographic Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by