[ask] how to fix reshape error

1 回表示 (過去 30 日間)
Abdul Hamzah
Abdul Hamzah 2016 年 11 月 6 日
コメント済み: Walter Roberson 2016 年 11 月 6 日
hello everyone, btw i have a sample code like this :
[img_rgb, clrMap] = imread ('E:\FOTO\C360_2015-02-02-14-15-52-544.jpg');
[rows,columns,numclrchannels] = size(img_rgb);
img_hsv = rgb2hsv(img_rgb);
h_img=img_hsv(:,:,1);
s_img=img_hsv(:,:,2);
v_img=img_hsv(:,:,3);
nSteps = 3;
[center,U,obj_fcn]=fcm(h_img,nSteps);
[~,cluster_idx] = max(U);
subplot(1,2,1);
imshow (img_hsv);
subplot(1,2,2);
pixel_labels = reshape(cluster_idx,rows,columns);
imshow(pixel_labels,[]), title('image labeled by cluster index');
i want to label every cluster created on the HSV image processed by FCM function.
but the problem is i always have an error on displaying the output of pixel_label saying :
Error using reshape
To RESHAPE the number of elements must not change.
is there any other way to display HSV output image after the HSV image has been processed by FCM function properly? How to fix the error?
thx before.

回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 11 月 6 日
Without testing it out, I suspect that you need to change
[~,cluster_idx] = max(U);
to
[~,cluster_idx] = max(U, [], 2);
so that you take max across rows.
  2 件のコメント
Abdul Hamzah
Abdul Hamzah 2016 年 11 月 6 日
it finally works anyway but i don't get desired results....what should i do?? should i change the way it outputs the FCM results?
Walter Roberson
Walter Roberson 2016 年 11 月 6 日
Your original max() was correct. But you need
[center,U,obj_fcn]=fcm(h_img(:),nSteps);

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

カテゴリ

Help Center および File ExchangeModify Image Colors についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by