I would like a function to compute the following operation:
I made this function that requires a matrix at its input, and returns the distances between every two lines of it in another matrix.
RGB_dist_full definition:
function[D]=RGB_dist_full(x)
I = nchoosek(1:size(x,1),2);
D = RGB_dist(x(I(:,1),:), x(I(:,2),:));
squareform(D)
end
RGB_dist definition:
function[distance]=RGB_dist(x,y)
distance=sqrt(sum((x-y).^2*[3;4;2],2));
end
Main program looks like this:
clc
clear all
rgbImage = imread('peppers.png');
K=6;
N=uint64(K*2);
rgb_columns = reshape(rgbImage, [], 3);
[unique_colors, m, n] = unique(rgb_columns, 'rows','stable');
color_counts = accumarray(n, 1);
[max_count, idx] = max(color_counts);
Imgsize=size(rgbImage);
U=unique_colors(1:N,:)
size(U)
x=[62,29,64;
63,31,62;
65,29,60;
63,29,62;
63,31,62;];
RGB_dist_full(x);
RGB_dist_full(U);
Why do I get 'Error using * MTIMES is not fully supported for integer classes. At least one input must be scalar. To compute elementwise TIMES, use TIMES (.*) instead.' for the second call of the function, whereas the first one returns the desired output?
double(rgbImage)
and carry on... – bla