在Matlab中,我已将 RGB 图像转换为 CIE Lab 色彩空间。
Lab = applycform(rgbImage, makecform('srgb2lab'));
L = Lab(:, :, 1);
a = Lab(:, :, 2);
b = Lab(:, :, 3);
如何量化和组合这3个频道?
...
为了进行比较,这就是我用RGB做的事情:
在主程序中
R = rgbImage(:, :, 1);
G = rgbImage(:, :, 2);
B = rgbImage(:, :, 3);
binsR = 4;
binsG = 4;
binsB = 4;
quantR = Quantize(binsR, R, 255);
quantG = Quantize(binsG, G, 255);
quantB = Quantize(binsB, B, 255);
quantColors = (binsB*binsG*quantR) + (binsB+quantG) + quantB;
Quantize.m
function quant = Quantize(bins, data, maxdata)
quant = data * (bins/maxdata);
quant = floor(quant);
quant(quant >= (bins - 1)) = (bins - 1);
end
答案 0 :(得分:1)
事实证明我找到了解决方案:D
好消息是:
代码相对简单!
在主程序中
labImage = applycform(rgbImage, makecform('srgb2lab'))
labImage = lab2double(labImage)
L = labImage(:, :, 1)
a = labImage(:, :, 2)
b = labImage(:, :, 3)
bins_L = 10
bins_a = 10
bins_b = 10
quant_L = QuantizeMT(bins_L, L)
quant_a = QuantizeMT(bins_a, a)
quant_b = QuantizeMT(bins_b, b)
quantColors = sqrt(quant_L.^2 + quant_a.^2 + quant_b.^2)
<强> QuantizeMT.m 强>
function quant = QuantizeMT(bins, data)
% Number of divider is number of segments (bins) minus 1
thresh = multithresh(data, bins-1)
% Quantize image (or channel) based on segments
quant = imquantize(data, thresh)
end
注意:
multithresh
函数无法检测到一些略微不同的值,从而产生一些相同的阈值。基于imquantize
文档:&#34;离散量化级别的值必须以单调递增的顺序。&#34;因此,最好使用lab2double
函数。multithresh
和imquantize
函数应与任何颜色空间兼容。尽管某些RGB图像存在异常,但multithresh
步的误差通常在B(蓝色)通道中。我不知道为什么。但是当我对整个图像使用imquantize
时,我没有问题,而不是逐个频道。PS :我使用Matlab R2012b。