7. Sparse representation of Omp,somp algorithm and OPENCV implementation

Source: Internet
Author: User

First, preface

Since the 90 's, the sparse representation has gained inspiration from the vision of the human eye and is gradually being studied by people. has now evolved into an important means of information representation. The so-called sparse representation means that a signal in an over-complete dictionary can be expressed linearly by a few atoms,

The mathematical model can be expressed as follows:

The mathematical model solution is a np-hard problem, which means that the optimal solution can only be obtained by means of poor lifting, the time complexity is very large, and the exact solution can hardly be obtained. In this case, we often use greedy algorithm to obtain the sub-optimal solution of the model. This paper introduces a mainstream greedy algorithm--

Orthogonal match tracking (OMP).

Second, OMP algorithm

The core of the greedy algorithm is to select an optimal atom from the atom of the dictionary to represent the original signal each time. The biggest disadvantage of greedy algorithm is that, in the idea of greedy algorithm, it is considered that the global optimal is obtained by each local optimum, which is very easy to get into the local optimal solution and can not obtain the global optimal solution of the data.

The main idea of OMP as a representative algorithm in greedy algorithm lies in the following two points:

1 The larger the dictionary atom in the signal projection, the better the description of the signal;

2 each time the selected atom is orthogonal to the previous atom.

Between the two points above, the OMP algorithm is described as follows:

Was extracted from the Internet. That's probably it. However, it is worth noting that: such omp algorithm in the calculation of the effect is often not ORMP algorithm good, many people say that the OMP algorithm is often ORMP algorithm.

For example: Open source Toolbox spams on the OMP algorithm part, its core is the ORMP algorithm. The difference between the ORMP algorithm and the OMP algorithm is that another stretch of the dictionary atom is done after the residuals have been computed (see the following code section for concrete stretching), such as:

Three, SoMP algorithm

SoMP algorithm is called Synchronous OMP algorithm, the main idea is: Similar atoms have the same sparse characteristics. Therefore, when sparse representation of similar atoms, assuming that the sparse atom is in the same position, and its selection in the over-complete dictionary of the same atom, the OMP algorithm is the SOMP algorithm in the original signal is an atom

The special circumstances of the time. The OMP algorithm can be unified into the SOMP algorithm, and its solution process is almost the same as the OMP algorithm part.

Iv. implementation of the Code

The code is as follows:

1Cv::mat Ormpsparserepresentation::ompsparsel2 (ConstCv::mat Dict,ConstCv::mat Y,Const intK)2 {3     intR =dict.rows;4     intc =Dict.cols;5     intn =Y.cols;6Cv::mat ERR (R,1, cv_32f);7ERR =Y;8     intSize[] ={c,n};9Cv::mat A = Cv::mat (2, Size,cv_32f,cv::scalar (0. f));Tenqvector<int>index; OneCv::mat U = Cv::mat::ones (1, c,cv_32f); A Cv::mat Tmpa; -      for(inti =0; i<k;i++) -     { theCv::mat S = err.t () *Dict; -CV::p ow (S),2, S); -         if(S.rows! =1) -Cv::reduce (S,s,0, cv_reduce_sum); + cv::sqrt (s,s); -S = s/U; +         if(i!=0) A         { at              for(intj =0; J<index.size (); j + +) -             { -s.at<float> (0, index[j]) =0. F; -             } -         } -  in CV::P oint maxloc; -Cv::minmaxloc (s,null,null,null,&maxloc); to         intpos =maxloc.x; + Index.append (POS); -  the Cv::mat subdict; * Getcoldictformindex (dict,index,subdict); $ Panax Notoginseng Cv::mat invsubdict; - Cv::invert (SUBDICT,INVSUBDICT,CV::D ECOMP_SVD); the  +Tmpa = invsubdict*Y; AERR = y-subdict*Tmpa; the  + Cv::mat dict_t_dict; -Cv::multransposed (Subdict,dict_t_dict,1); $ Cv::mat invdict_t_dict; $ Cv::invert (DICT_T_DICT,INVDICT_T_DICT,CV::D ECOMP_SVD); -  -Cv::mat P = (Cv::mat::eye (r,r,cv_32f)-subdict*invdict_t_dict*subdict.t ()) *Dict; theCV::p ow (P,2, P); -Cv::reduce (P,p,0, cv_reduce_sum);Wuyi cv::sqrt (p,u); the     } -      for(inti =0; i<k;i++) Wu     { -         intTMPC =Index[i]; About         Const float*inp=tmpa.ptr<float>(i); $         float*outp=a.ptr<float>(TMPC); -          for(intj =0; j<n;j++) -         { -OUTP[J] =Inp[j]; A         } +     } the     returnA; -}
View Code
1 voidOrmpsparserepresentation::getcoldictformindex (ConstCv::mat Dict,Constqvector<int> Index, Cv::mat &Res)2 {3     if(index.size () = =0)4         return;5     if(!dict.data)6         return;7 8     intR =dict.rows;9     intc =index.size ();Ten  One Cv::mat dict_t; A Cv::transpose (dict,dict_t); -  -Cv::mat res_t =Cv::mat (C,r,dict.type ()); the  -      for(inti =0; I<index.size (); i++) -     { -         intTMPC =Index[i]; +         Const float*inp=dict_t.ptr<float>(TMPC); -         float*outp=res_t.ptr<float>(i); +          for(intj =0; j<r;j++) A         { atOUTP[J] =Inp[j]; -         } -     } - Cv::transpose (res_t,res); - res_t.release (); - dict_t.release (); in}
View Code

7. Sparse representation of the OMP,SOMP algorithm and OPENCV implementation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.