Calculating maximum distance from 3 different points

2 visualizzazioni (ultimi 30 giorni)
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 Commenti
Image Analyst
Image Analyst il 8 Set 2019
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 il 8 Set 2019
They were just randomly generated numbers, and I could pass all three in, but I was wondering if there was a shorter way?

Accedi per commentare.

Risposte (1)

Jyotish Kumar
Jyotish Kumar il 12 Nov 2019
Modificato: Jyotish Kumar il 12 Nov 2019
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.

Categorie

Scopri di più su Matrices and Arrays 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