📄 testgenlloyd.m
字号:
% TestGenLloyd Test of the function GenLloyd
%----------------------------------------------------------------------
% Copyright (c) 2002. Karl Skretting. All rights reserved.
% Hogskolen in Stavanger (Stavanger University), Signal Processing Group
% Mail: karl.skretting@tn.his.no Homepage: http://www.ux.his.no/~karlsk/
%
% HISTORY: dd.mm.yyyy
% Ver. 1.0 26.11.2002 KS: function made
%----------------------------------------------------------------------
clear all;
Mfile='TestGenLloyd';
L=100;
X=randn(2,L);
X(:,(floor(L/2)+1):L)=2+X(:,(floor(L/2)+1):L);
F=GenLloyd(X,6,0);
figure(1);clf;
plot(X(1,:),X(2,:),'b.');hold on;
plot(F(1,:),F(2,:),'r*');
%
for j=1:L;
x=X(:,j);
temp=x'*x;
if (temp==0); temp=1; else temp=sqrt(temp); end;
if (sum(x)<0); temp=-temp; end;
X(:,j)=x/temp;
end
F=GenLloyd(X,4,1);
figure(1);clf;
plot(X(1,:),X(2,:),'b.');hold on;
plot(F(1,:),F(2,:),'r*');
% a larger test
L=5000;K=40;N=25;
TextureFile = 'C:\Karl\FraWWW\Bilder\Textures\D5D92_1.BMP'; % an image
X=imread(TextureFile);
[Mx,Nx,Cx]=size(X);
if (Cx==3)
X=rgb2gray(X);Cx=1;
disp([Mfile,': make grayscale image of color image.']);
end
B=double(X);
[X,H2]=SetFfromImage(B,L,[5,5]); % this picks blocks form B into X and normalize X
F=GenLloyd(X,K,1);
n1=13;
for n2=1:N
if (n2~=n1)
figure(1);clf;
plot(X(n1,:),X(n2,:),'b.');hold on;
plot(F(n1,:),F(n2,:),'r*');
xlabel(['coordinate number ',int2str(n1)]);
ylabel(['coordinate number ',int2str(n2)]);
pause;
end
end
% and not normalized, this takes much longer time
X=X-0.2;
F=GenLloyd(X(:,1:(L/10)),10,0); % do not use all in initialization
F=GenLloyd(X,F,0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -