How to get xy coordinates from a binary image matrix

24 visualizaciones (últimos 30 días)
Ian Hersom
Ian Hersom el 1 de Ag. de 2016
Comentada: Ayesha Shafique el 18 de Abr. de 2019
How do I get the xy coordinates of all the 1's in a binary matrix?

Respuesta aceptada

Chad Greene
Chad Greene el 1 de Ag. de 2016
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 comentarios
Image Analyst
Image Analyst el 1 de Ag. de 2016
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 el 18 de Abr. de 2019
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.

Iniciar sesión para comentar.

Más respuestas (1)

Juan Alberto Antonio Velazquez
Juan Alberto Antonio Velazquez el 3 de Mayo de 2018
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

Categorías

Más información sobre Geographic Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by