How to represent the value of X and Y Pixels in array of Two Dimensions using Matlab

Hi , Suppose if this is my image
I need to find the x, y coordinates of white pixels in image. I am getting the value of x and y coordinates separately one after the other, i want to represent it in 2 dimensional array matrix like [x,y] ,how can i represent it in 2 D matrix?
Then i need to calculate the farthest distance in that box ? how to solve this?

 Réponse acceptée

The provided answer is correct, you only need some processing steps, the image contains white borders , you need to crop it using some software, after that, you need to convert into grayscale and then to double instead of unit8 :
X=rgb2gray(X);
X=im2double(X);
% then the command provided above.

12 commentaires

Thank You Youssef khmou ,
Actually this image i have converted to gray then applied threshold , then edge detection, this image is the output after edge detection .
Using 'find' i am getting x and y coordinates , how to represent it in matrix??
Not a square matrix but a very thin matrix :
[y, x] = find(binaryImage);
M=[y,x];
Lakshya
Lakshya le 16 Sep 2014
Modifié(e) : Lakshya le 16 Sep 2014
Thank you so much....
Now i need to calculate the distance between those coordinates , this can be done by using distance formula. But i need to compare each coordinate with all other coordinate in matrix, then find the farthest distance between them.
like [x1,y1] with [x2,y2],, in next iteration [x1,y1] with [x3,y3] and so on till [xn,yn].
Similarly [x2,y2] with all other coordinates in matrix.
Suppose the matrix you obtained is M :
N=length(M);
The euclidean distances form a matrix of dimensions NxN where the diagonal elements are 0, you can basically use two dimensional loop :
D=zeros(N);
for x=1:N
for y=1:N
D(x,y)=sqrt((M(x,1)-M(y,1))^2-(M(x,2)-M(y,2))^2);
end
end
Its not working out...
this is my program where a(i,j) is my image
count=1;
for(i=1:x)
for(j=1:y)
if a(i,j)~=1;
x(count)=j;
y(count)=i;
x(1,:)= x(count);
y(:,1)= y(count);
count=count+1;
a(i,j) = sqrt((y(count)-y(:,1))^2 + (x(count)-x(1,:))^2);
end;
end;
end;
[x,y]=find(a);
xy=[x,y]
My problem is i want to store the value of x(count) and y(count) in some temporary variable. How to assign the value ???
here i have used x(1:,) and y(:,1)
but i am getting error
"Index exceeds matrix dimensions "
I tried the the loop i proposed and it is working, try to verify your program .
Lakshya
Lakshya le 16 Sep 2014
Modifié(e) : Lakshya le 16 Sep 2014
I tried out your program..
i am not getting any answer...
and i have a doubt... why ur using 'zeros', coz i need to find pixel values with ones... and my image is not a square matrix.. its MxN
earlier after obtaining the matrix M of coordinates of white pixels, you wanted to calculate the distance between each point M(x,y) and the rest of the points, the two dimensional loop works,zeros is a variable initialization :
for x=1:N
for y=1:N
D(x,y)=sqrt((M(x,1)-M(y,1))^2-(M(x,2)-M(y,2))^2);
end
end
The diagonal is zero because it is a distance between a point M(x,y) and itself.
ok, but i am not getting any result...
can you provide me your code.....
And in my code , is this statement correct....??
x(1,:)= x(count);
y(:,1)= y(count);
actually i am getting error at this line...
x(1,:) means the x,y coordinates of the 1st point, but y(:,1) is the x coordinates of all points, that is where you get the error, the distance between the x and y points is sqrt((M(x,1)-M(y,1))^2-(M(x,2)-M(y,2))^2)
k attach me your complete code ,,, ill just try

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Computational Geometry dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by