本文主要是介绍matlab图像处理--LBG训练器应用 VQ压缩,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
I = double(imread('liftingbody.png'));
Bk = 4;
data = im2col(I, [Bk, Bk], 'distinct');
N = size(data, 2);
M = 100;
rng(999)
%随机选100个向量作为中心
rnd = randi([1, N], [1,M]);
centroid = data(:, rnd);%LBG训练次数为10D = zeros([100, N]);for iter = 1 : 10for i = 1 : Mfor j = 1 : ND(i,j) = sum( (centroid(: ,i) - data(:, j)).^2 );endend[~, Grp] = min(D);for i = 1 : Mcentroid(:, i) = mean ( data(:, Grp == i), 2 );end
end%encoding
X = zeros( size(I)/Bk );
MAT = ones([1, M]);
for i = 1 : N[~, X(i)] = min( sum((data(:, i)*MAT - centroid).^2) );
end%decoding
I2 = im2col( zeros(size(I)), [Bk, Bk], 'distinct' );for i = 1 : NI2(:, i) = centroid(:, X(i));
endVQimg = col2im(I2, [Bk, Bk], [size(I, 1), size(I, 2)], 'distinct');imshow(uint8(VQimg))
这篇关于matlab图像处理--LBG训练器应用 VQ压缩的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!