0
votes

I would like a function to compute the following operation: enter image description here

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?

1
well why would you want to keep this integer to begin with (sqrt(integer) is usually not an intager) ? just double(rgbImage) and carry on...bla
@natan Indeed, that solved the problem.Tanatos Daniel
I'll add this as an answer then...bla
@TanatosDaniel I did tell you to do this in the previous question you asked regarding this same procedure and you accepted my answer.... Curious as to why you're asking this again. stackoverflow.com/questions/24398054/…rayryeng
Oh. You did. I'm sorry. I read your post in a hurry, seemed like the solutions from here link and that's I marked it is an answer. I should've read it entirely. I'll be more careful from now on. Thanks!Tanatos Daniel

1 Answers

1
votes

For these types of calculations you want to cast to double precision , because sqrt(integer) is usually not an integer. For that just double(rgbImage) immediately after reading the image will do.