Calculating maximum distance from 3 different points

3 次查看(过去 30 天)
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