OpenCV中SVD分解函数compute
C++: static void SVD::compute(InputArray src, OutputArray w, OutputArray u, OutputArray vt, int flags=0 ) src – Decomposed matrix w – Computed singular values u – Computed left singular vectors v – Computed right singular vectors vt – Transposed matrix of right singular values flags – Opertion flags - see SVD::SVD().
使用示例
#include <opencv.hpp> using namespace cv; //参数分别为输入图像,输出图像,压缩比例 void SVDRESTRUCT(const cv::Mat &inputImg, cv::Mat &outputImg, double theratio) { cv::Mat tempt; cv::Mat U, W, V; inputImg.convertTo(tempt, CV_32FC1); cv::SVD::compute(tempt, W, U, V); cv::Mat w = Mat::zeros(Size(W.rows, W.rows), CV_32FC1); int len = theratio*W.rows; for (int i = 0; i < len; ++i) w.ptr<float>(i)[i] = W.ptr<float>(i)[0]; cv::Mat result = U*w*V; result.convertTo(outputImg, CV_8UC1); } int _tmain(int argc, _TCHAR* argv[]) { cv::Mat scrX = imread("1.png",0); cv::Mat result; SVDRESTRUCT(scrX, result,0.1); cv::imshow("1",result); waitKey(0); }
SVD本身是个O(N^3)的算法,大数据处理比较慢。
原图如下:
原图重构如下:
10%压缩如下:
1%压缩如下:
原文链接: https://www.cnblogs.com/didea/p/6044321.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/243549
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!