size differ when processing

14 ビュー (過去 30 日間)
kash
kash 2012 年 8 月 31 日
In my code below can u tell why the number of elements are different or size is different
>> img=imread('peppers.png');
>> flatImg = double(reshape(img,size(img,1)*size(img,2),size(img,3)));
idx = kmeans(flatImg,3)
size(flatImg)
196608 3
size(idx)
196608 1
please provide assistance

採用された回答

Image Analyst
Image Analyst 2012 年 8 月 31 日
You have 196608 pixels. In flatImg you rearranged them into rows where each column is the red, green, and blue values.
With kmeans, each of the 196608 pixels is classified as a "1", "2", or a "3" depending on its color, so it's a 1D array. There is no information along any second dimension like there was with flatImg.
There is no reason why they should be the same size because they represent different things. Do you think they should?
  3 件のコメント
Image Analyst
Image Analyst 2012 年 8 月 31 日
編集済み: Image Analyst 2012 年 8 月 31 日
What second and third dimension? You have a list of classifications for each pixel. For example, pixel 1 might be class 3 and pixel 2 might be class 2, etc. You have to reshape that "idx" into a 2D image (the same size as your original image) if you want the classified image. It will have the same number of gray levels as classes you have, obviously.
kash
kash 2012 年 9 月 1 日
ok thanks Analyst

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

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by