opencv-SVD奇异值分解

资料:https://blog.csdn.net/u012198575/article/details/99548136  

 

实例一:压缩图像

#include<opencv2/opencv.hpp>
#include<iostream>



int main(int argc, char** argv) {

    cv::Mat src = cv::imread("D:/bb/tu/lm.jpg", 0);
    //src是m行n列

    cv::Mat result;
    cv::Mat tempt;
    cv::Mat U, S, V;
    src.convertTo(tempt, CV_32FC1);
    cv::SVD::compute(tempt, S, U, V);//SVD分解
    // S是n行1列(CV_32F),U是m行n列(CV_32F),V是n行n列(CV_32F)
    
    cv::Mat s = cv::Mat::zeros(cv::Size(S.rows, S.rows), CV_32FC1);
    double theratio = 0.1;//压缩比例--数值越小,压缩越厉害
    int len = theratio * S.rows;
    for (int i = 0; i < len; ++i) s.ptr<float>(i)[i] = S.ptr<float>(i)[0];

    result = U * s * V; //压缩后还原

    cv::Mat outputImg;  //压缩后的图像
    result.convertTo(outputImg, CV_8UC1);
        
    cv::imshow("原图", src);
    cv::imshow("压缩后", outputImg);

    cv::waitKey(0);
    return 0;
}

opencv-SVD奇异值分解

 

 

 

 

 

 

 

opencv-SVD奇异值分解

相关文章:

  • 2021-09-29
  • 2021-09-04
  • 2021-05-05
猜你喜欢
  • 2021-09-19
  • 2021-06-27
  • 2021-05-14
  • 2021-06-12
  • 2021-10-15
  • 2021-06-21
相关资源
相似解决方案