Calculating maximum distance from 3 different points

조회 수: 3 (최근 30일)
Sara Foster
Sara Foster 2019년 9월 8일
편집: Jyotish Kumar 2019년 11월 12일
So I generate a test array and three points (Q) using command window:
pixels = zeros(1,3,3,'uint8');
pixels(:,:,1) = [54,50,45];
pixels(:,:,2) = [48,52,43];
pixels(:,:,3) = [50,41,47];
Q1 = [54,48,50];
Q2 = [50,52,41];
Q3 = [45,43,47];
I use my first function which calculates the median of pixels and this is put into an array e.g P=[54,55,76].
I use my second function to calculate the distance between pixels, which is:
[squaredDistance] = PixelDistance(P,Q)
However, I need to subtract Q1 from P as well as Q2 from P and Q3 from P using squared distance formula e.g
P=[54,55,76]
Q1 = [54,48,50]
[squaredDistance] = PixelDistance(P,Q1)
The question is how do I subtract Q1,Q2, and Q3 given that the function only works with Q?
  댓글 수: 2
Image Analyst
Image Analyst 2019년 9월 8일
How is 76 in P the median of any subset of numbers in pixels? It's outside the range of any of them. Also, why are you using a 3-D array for pixels (one row by 3 columns by 3 planes) instead of a normal 3 rows-by-3 columns matrix?
I don't know what PixelDistance() does, but to have it operate on all 3 Q, just pass in all three Q one at a time:
[squaredDistance1] = PixelDistance(P,Q1)
[squaredDistance2] = PixelDistance(P,Q2)
[squaredDistance3] = PixelDistance(P,Q3)
Sara Foster
Sara Foster 2019년 9월 8일
They were just randomly generated numbers, and I could pass all three in, but I was wondering if there was a shorter way?

댓글을 달려면 로그인하십시오.

답변 (1개)

Jyotish Kumar
Jyotish Kumar 2019년 11월 12일
편집: Jyotish Kumar 2019년 11월 12일
Hi,
If the code is vectorizable, PixelDistance(P, [Q1;Q2;Q3]) should give the desired output.
If not, to achieve a shorter way to compute the distances w.r.t all Qs at once, the code needs to be vectorized.

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by