Azzera filtri
Azzera filtri

How to get xy coordinates from a binary image matrix

52 visualizzazioni (ultimi 30 giorni)
How do I get the xy coordinates of all the 1's in a binary matrix?

Risposta accettata

Chad Greene
Chad Greene il 1 Ago 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 Commenti
Image Analyst
Image Analyst il 1 Ago 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 il 18 Apr 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.

Accedi per commentare.

Più risposte (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

Categorie

Scopri di più su Image Processing Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by