我已经完成了一项编程,通过使用从000到111的RGB方法,可以在图像中计算多达8种颜色。我需要对其进行一些修改。到目前为止,我宣布如果大于128的数字将等于1&低于128将为0.它将计算8种颜色。如果我说部分从0-64,65-128,129-192,193-255进行,如何增加颜色数量。
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))
答案 0 :(得分:1)
增加间隔数会增加您所计算的基数:而不是2^3=8
量化颜色,您将获得4^3=64
量化颜色。
rgb = imread( ... ); %// read you image here
qImage = zeros( size(rgb(:,:,1)) ); %// preallocate result
intervals = permute([64, 128, 192, 256], [1 3 2]); %// the quantization intervals
base = numel(intervals);
for ci=1:size(rgb,3) %// for each channel
whichInterval = bsxfun( @le, rgb(:,:,ci), intervals ); %// select per pixel, which interval is relevant
[~, q] = max( whichInterval, [], 3 ); %// get index of relevant interval
qImage = qImage*base + (q-1); %// -1 to convert from matlab's 1-based indexing
end