Function calculating distance between pixels in 1x1x3 arrays
Show older comments
I have a function which calculates square distance between pixels, however it wants to calculate the distance between 2 pixels which has a 1x1x3 array.
For example, inputs P and Q both have 1 row, 1 column and 3 colour layers, and single output is squared distance.
I found this function on matlab forums which calculates squared distance and it gives correct results: https://ww2.mathworks.cn/matlabcentral/answers/479129-how-can-i-have-multiple-arrays-as-an-input-for-my-function
function [SquaredDistance] = PixelDistance(P,Q)
P1 = P(1); P2 = P(2); P3 = P(3);
Q1 = Q(1); Q2 = Q(2); Q3 = Q(3);
SquaredDistance = (P1-Q1)^2 + (P2-Q2)^2 + (P3-Q3)^2;
end
However, if I have a table (as an example) like this: (where :,:,1 is red values :,:,2 is green values etc)
Colours(:,:,1) =
143
156
231
Colours(:,:,2) =
37
139
142
Colours(:,:,3) =
30
22
65
How do we calculate squared value using input commands such as P = Colours(1,1,:) and Q = Colours(3,1,:) using the code?
Accepted Answer
More Answers (1)
Sara Foster
on 7 Sep 2019
0 votes
1 Comment
Jos (10584)
on 8 Sep 2019
I do not get this question, sorry. Also, do not pose a new question as an answer here but open a new thread, or put it as a comment/follow-up on a given answer, to avoid confusion :-)
Categories
Find more on Performance and Memory in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!