Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 工程数学软件 > MATLAB论坛
MATLAB论坛 一切MATLAB相关问题在此讨论。
回复
 
主题工具 显示模式
旧 2008-10-02, 02:34   #1
duyang1219
初级会员
 
注册日期: 2008-04-21
年龄: 41
帖子: 1
声望力: 0
duyang1219 正向着好的方向发展
默认 [求助]求各位大哥帮忙改错~

代码是关于full search pnn的码书编写的。。。。实在不知道该怎么改了。。我是一个刚学一个多月的超级菜鸟,,,很着急谢谢各位了
clear all;
close all;



%read the image detail
image=imread('lena.gif');
image=im2double(image);


%specify the size of the vector is 4, each vector is a 2*2 block
block_width= 4 ;

%according to the vecter size to generate an original codebook
ori_codebook=im2col(image,[block_width block_width],'distinct');
ori_codebook=ori_codebook';
[a b]=size(ori_codebook); %get the size of original codebook


%specify the final codebook size is 8*4, it means there are 8
%clusters(rows) of final codebook.
num_cluster=8;




%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%5 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%5%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%1. calculate the minimum distance of each vector in original vector.

%2. find the index of the first two nearest vector.

%3. merge the two vector and put their mean value into a new matrix.

%4. move the first two vectors away from the original codebook and then do
%do the same step for another vectors.

%5. test that if the new matrix(step 3) equal to the codebook we want,
%if yes save the codebook, if not, go back to step 1 to merge the vector again.

while a~=num_cluster

x=1;
m=a;


for y=1:a/2; % after the first merge, the column of new codebook must be the half of the original one.


% calculate the minimum distance of each vector in original vector.
for i=2:m
distance(x)=sum((ori_codebook(1,-ori_codebook(i,).^2);
x=x+1;
end

% find the index of the two nearest vector.
[min_value min_row]=min(distance);
min_row=min_row+1;



% merge the two vector and put their mean value into a new matrix.
codebook(y,=0.5*(ori_codebook(1,+ori_codebook(min_row,);



% move the nearest two vectors away from the original codebook and
% built a new codebook.
t=1;
for u=1:m
if u~=1&u~=min_row
tem_codebook(t,=ori_codebook(u,;
t=t+1;
end
end

% after moving away the two nearest vectors, get the size of the
% new codebook and then do the next loop.
ori_codebook=tem_codebook;
[m n]=size(ori_codebook)

end


% test that if the new matrix equal to the codebook we want,
% if yes, save the codebook if not, merge the vector again.
ori_codebook=codebook
[a b]=size(ori_codebook)
end


% save the codebook
new_codebook=ori_codebook
save new_codebook
duyang1219 当前离线   回复时引用此帖
回复


发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛启用 表情符号
论坛启用 [IMG] 代码
论坛禁用 HTML 代码



所有时间均为北京时间。现在的时间是 10:46


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.