First, preface
Graph is an important data structure, this paper mainly represents the image of the non-direction diagram. The so-called non-directed graph refers to the connection between the nodes of the graph through the edges without direction.
Representation of a non-direction graph:
G=<v,e> diagram, where: 1. V is a non-empty collection, called a vertex set. 2.E is a collection of unordered two tuples of elements in V, called Edge sets. For the image, each pixel can be regarded as a node, according to the specific node connection selection method, can be divided into KNN composition and sparse composition and so on. The so-called KNN composition refers to the node of each pixel is connected with the smallest point in the image and the pity Dorado distance, the value of the connection can be computed by least squares reconstruction. The same is true of the sparse composition, where each pixel is connected to the position atom in the dictionary of the remaining pixels. The specific algorithm can refer to the relevant literature.
Second, the realizationThis section mainly implements the graph connection of a single point. The sparse composition is solved by the OMP algorithm. The main code functions are as follows:
1 voidSparsegraphic::knnsparsegraphics (ConstQString FileName,ConstQpoint CurPos,2 Const intK, Qvector<qpoint> &respoint,Const intflag)3 {4 if(Curpos.x () <0|| Curpos.y () <0)5 return;6Cv::mat IMG =Gdalopencv::gdal2mat (fileName);7 introw =img.rows;8 intCol =Img.cols;9 if(Curpos.x () >=col | | curpos.y () >=row)Ten return; One if(Flag! =0&& Flag! =1) A return; -Cv::mat Imgvec = Img.reshape (1, row*col); - Cv::transpose (Imgvec,imgvec); the intCurposvec = Curpos.y () *col +curpos.x (); - Cv::mat Dict; - if(Curposvec! =0) - { +Cv::mat Dict1 = Imgvec.colrange (0, curposvec-1); -Cv::mat dict1_t =dict1.t (); +Cv::mat Dict2 =Imgvec.colrange (curposvec,imgvec.cols); ACv::mat dict2_t =dict2.t (); at Dict1_t.push_back (dict2_t); -Cv::mat dict_t =Dict1_t.clone (); -Dict =dict_t.t (); -Dict =Dict.clone (); - dict1.release (); - dict2.release (); in dict_t.release (); - dict1_t.release (); to dict2_t.release (); +}Else - { theCv::mat Dict1 = Imgvec.colrange (1, imgvec.cols); *Dict =Dict1.clone (); $ dict1.release ();Panax Notoginseng } -Cv::mat Curposimgvec = Imgvec.colrange (curposvec-1, Curposvec); theqvector<int>index; + for(inti =0; i<row*col;i++) A Index.push_back (i); the index.removeat (Curposvec); + - if(Flag = =0) $ { $Cv::mat Tmpcurposimgvec = Cv::repeat (Curposimgvec,1, dict.cols); -Cv::mat Submat = Dict-Tmpcurposimgvec; -Submat =Submat.mul (Submat); the cv::sqrt (Submat,submat); -Cv::reduce (Submat,submat,0, cv_reduce_sum);WuyiQuickSort (Submat,index,0, row*col-2); the for(inti =0; i<k;i++) - { Wu intr = index[i]/Col; - intc = index[i]%Col; About Qpoint MPos; $ Mpos.setx (c); - mpos.sety (r); - Respoint.push_back (mPos); - } A}Else + { theqvector<int>Tmpindex; -Cv::mat A =Ormpsparserepresentation::ompsparsel2 (dict,curposimgvec,tmpindex,k); $ for(inti =0; i<k;i++) the { the intr = index[tmpindex[i]]/Col; the intc = index[tmpindex[i]]%Col; the Qpoint MPos; - Mpos.setx (c); in mpos.sety (r); the Respoint.push_back (mPos); the } About } the}
Where: The code for sorting and OMP algorithm is shown in document 8 and document 7
Third, display
9. KNN and sparse composition