MATLAB: Size differ when processing

matrix manipulation

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

Best Answer

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?