Reputation: 323
I have a question: how to use subclust() function in matlab with an image loaded with imread() function? I have a code
rgb = imread('6_rubets.jpg');
gr = rgb2gray(rgb);
[c, s] = subclust(gr, 0.3);
I need to get the cluster centers on this image, and in the result I need to classify pixels on the image. But I have the error:
Error using .*
Integers can only be combined with integers of the same class, or scalar doubles.
Error in subclust (line 169)
dx = (thePoint - X) .* new_accumMultp;
Error in lab_1 (line 3)
[c, s] = subclust(gr, 0.3);
What do I need to do to find a claster centers?
Thanks in advance
Upvotes: 0
Views: 644
Reputation: 104464
The reason why this doesn't work is because subclust
doesn't support inputs that are uint8
(or any integer I suppose...). I suspect that internally, subclust
is creating arrays / matrices of type double
, then when it is trying to do operations with those arrays / matrices with your image, you're getting that error. The operations done with mixing the different variable types is not allowed, as hinted by the error.
As such, try casting your image to double
, then run the code again. This won't change the actual numbers, but it will change the class of variable instead (double
). I did this and it worked for me. As an example, I used cameraman.tif
that's part of MATLAB's system path:
im = imread('cameraman.tif'); %// Image already grayscale
[c,s] = subclust(double(im), 0.3);
In your case, you would have to do:
rgb = imread('6_rubets.jpg');
gr = rgb2gray(rgb);
[c, s] = subclust(double(gr), 0.3);
Upvotes: 1