Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
|
![]() |
#1 |
初级会员
注册日期: 2008-04-21
年龄: 41
帖子: 1
声望力: 0 ![]() |
![]()
代码是关于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, ![]() ![]() 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, ![]() ![]() ![]() % 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, ![]() ![]() 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 |
![]() |
![]() |