⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gentrainingvector.m

📁 将PSO和LBG结合在一步迭代过程中
💻 M
字号:
% =====================================================================
%                 PP algorithm 
%                 sub program for pp
%     Start Date: 15/07/2006
%   Last Changed: 21/08/2006
%          Usage: Before runing the program, make sure experimental image exist 
%  
%  Specification: The algorithm, proposed by Ji and Liao in 2006, incorporating
%                 both PSO algorithm and LBG to one iteration and using  
%                 particle-pair to explore in the problem space
%
% Copyright (c) Ji and Liao in 2006
% All rights Reserved
%==========================================================================

img_lena=imread('lena.gif');
img_lena=double(img_lena);      % 转换img_lena的类型为双精度型
[Line,Col]=size(img_lena);      % 读出图像的大小
figure;imshow(img_lena/255);           % 显示图像

q=4;                            % 设定向量维数为n*n
M=Line*Col/q/q;     % training vector size, i.e. C*C/L
trainingvector=zeros(Line*Col/q/q,q*q);     % 分割图像,得到zero矢量,tv(4096*16)
num_trainingvector=Line*Col/q/q; % number of the training vectors
% reshape 4*4 to 16*1,and get tv(4096*16) following
for i=0:Line/q-1
    for j=0:Col/q-1
        trainingvector(i*Col/q+1+j,:)=[img_lena(i*q+1,j*q+1:j*q+q),img_lena(i*q+2,j*q+1:j*q+q),...
                img_lena(i*q+3,j*q+1:j*q+q),img_lena(i*q+4,j*q+1:j*q+q)];
    end
end
% select 256 codevectors randomly from the training vectors following.
cbook_new=zeros(256,16); 
cbook_new=trainingvector(floor(rand(1,256)*M+1),:);
z_cluster=cbook_new;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -