Derive a colour palette from an image

1 回表示 (過去 30 日間)
Andy
Andy 2013 年 4 月 12 日
I have a question which asks to set the number of rows and columns (M and N) for the painting grid and resize an image to this required gridsize.
I used imresize like below, where B is my image.
B = imresize(B,[20,20]);
It then says use this command to derive the 8 colour palette.
[~, Palette] = kmeans(reshape(B(:),M*N,3),8,'E','s','S','U');
If i replace M and N with my grid values which are 20 and 20 i get this error, for the line above.
Error using .*
Integers can only be combined with integers of the same class, or scalar doubles.
Error in unifrnd (line 34)
r = mu + sig .* (2*rand(sizeOut)-1);
Error in kmeans (line 248)
C = unifrnd(Xmins(ones(k,1),:), Xmaxs(ones(k,1),:));
Am i going about this the right way, and if so what is the meaning of the error message?
Thanks

回答 (1 件)

Image Analyst
Image Analyst 2013 年 4 月 12 日
So did you try casting to double, like it hinted at, and try again?
  2 件のコメント
Andy
Andy 2013 年 4 月 12 日
Im not sure which value it is referring to but i tried casting all of them to double and got the same error message
Image Analyst
Image Analyst 2013 年 4 月 12 日
I don't have the stats toolbox so I can't replicate to help you.

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

カテゴリ

Help Center および File ExchangeGet Started with Image Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by