我已經完成了一個編程,可以通過使用從000到111的RGB方法計算圖像中的8種顏色。我需要對其進行一些修改。到目前爲止,我聲明的數字,如果128以上將等於1 &低於128將是0.它會計數8種顏色。如何增加顏色數量?下面是代碼的一個例子數到8種顏色:計算圖像中顏色的百分比數
rgbImage = imread('football.jpg');
imshow(rgbImage);
[w,h,d] = size(rgbImage)
redChannel = rgbImage(:,:, 1);
greenChannel = rgbImage(:,:, 2);
blueChannel = rgbImage(:,:, 3);
quantizedImage=zeros(size(rgbImage));
count=zeros(1,8);
for i = 1:w
for j = 1:h
if redChannel(i,j) > 128,
aredChannel2 = 1;
else
aredChannel2=0;
end
quantizedImage(i,j,1)=aredChannel2*255;
if greenChannel(i,j) > 128,
agreenChannel2 = 1;
else
agreenChannel2=0;
end
quantizedImage(i,j,2)=agreenChannel2*255;
if blueChannel(i,j) > 128,
ablueChannel2 = 1;
else
ablueChannel2=0;
end
quantizedImage(i,j,3)=ablueChannel2*255;
bin=4*aredChannel2+2*agreenChannel2+ablueChannel2+1;
count(bin)=count(bin)+1;
end
end
figure, imshow(uint8(quantizedImage));
正如上面的代碼最多隻能計算8種顏色。假設我想將顏色數增加到64個顏色數。 –
@rayryeng你能幫我解決這個問題嗎? –