Use Vectorisation to perform the squared distance between two different arrays

3 ビュー (過去 30 日間)
ZEE
ZEE 2018 年 9 月 2 日
コメント済み: ZEE 2018 年 9 月 3 日
Hi, I'm trying to write a vectorised code to calculate the squared distance between an RGB point and different k Means, and then find the minimum squared distance. suppose that:
RGB= [55;60;100]
Means= [ 209;205;203, 115;110;20, 17;18;20 ]
and squared distance should compare the RGB with each Means(column vector).
for instance,
D1=[(55-209)^2+(60-205)^2+(100-203)^2].
How can I do this without using a loop?
  1 件のコメント
the cyclist
the cyclist 2018 年 9 月 2 日
Your specification of the Means variable is not going to give a valid array. If you meant it to be a column vector, it should be all semicolons, with no commas. Is that what you intended? Or is it a 3x3 matrix?

サインインしてコメントする。

採用された回答

the cyclist
the cyclist 2018 年 9 月 2 日
If I understand what you are trying to do, I would code this as
RGB = [55, 60, 100];
Means = [ 209, 205, 203;
115, 110, 20;
17, 18, 20 ]
D = sum((RGB-Means).^2,2)
and not define separate D1, D2, D3 variables.
  1 件のコメント
ZEE
ZEE 2018 年 9 月 3 日
suppose we want to compare all the RGB values in an image with each of the k means. will we be able to do this with vectorisation?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by