K-SVD算法—图像解析,让你看透彻!(附代码)

举例:K-SVD最大的不同在字典更新这一步,K-SVD每次更新一个原子(即字典的一列)和其对应的稀疏系数,直到所有的原子更新完毕,重复迭代几次即可得到优化的字典和稀疏系数。如下。

             

如上图(左上),现在我们要更新第k个原子,即d_k..那我们需要知道在上一步迭代之后哪些信号使用了该原子,即稀疏系数不为0的部分是哪些?从左上图中很容易看出,x'的第k列T(x_k),也就是x的第k行中不为0的那部分所对应的T(y_k)即是我们要找的信号,结果见左下图蓝色部分。我们用d_k和稀疏系数x(k)'来重构这部分使用了d(k)的信号,它和T(y_k)的差值即E,右上图中绿色部分,接下来我们要使用最后这个图这个约束来更新x_k和d_k这两个值…如此反复,直到过完备字典D的所有原子更新完毕为止…求解这个x_k和d_k,直接对E进行SVD分解即可。

这里是我个人查资料后补充:

SVD decomposes E^R_k into  U\Delta V^T. The solution for d_k is the first column of U, the coefficient vector x^k_R as the first column of V \times \Delta (1, 1). After updated the whole dictionary, the process then turns to iteratively solve X, then iteratively solve D.


matlab代码

 
 function [A,x]= KSVD(y,codebook_size,errGoal)  
 
%============================== 
%input parameter 
% y - input signal 
% codebook_size - count of atoms 
%output parameter 
% A - dictionary 
% x - coefficent 

%============================== 
if(size(y,2)<codebook_size) 
   disp('codebook_size is too large or training samples is too small'); 
   return; 
end 
% initialization 
[rows,cols]=size(y);
 r=randperm(cols); 
A=y(:,r(1:codebook_size)); 
A=A./repmat(sqrt(sum(A.^2,1)),rows,1); 
ksvd_iter=10; 
for k=1:ksvd_iter 
 % sparse coding 
        x=OMP(A,y,5.0/6*rows); 
  % update dictionary 
    for m=1:codebook_size 
       mindex=find(x(m,:)); 
       if ~isempty(mindex) 
            mx=x(:,mindex); mx(m,:)=0; my=A*mx; resy=y(:,mindex); 

            mE=resy-my; [u,s,v]=svds(mE,1); A(:,m)=u; x(m,mindex)=s*v';
       end 
   end 
end

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值