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?
採用された回答
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 件のコメント
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];
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 .
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
Youssef Khmou
2014 年 9 月 16 日
編集済み: Youssef Khmou
2014 年 9 月 16 日
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
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Image Arithmetic についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
