当前位置:网站首页>What is the saturate operation in opencv

What is the saturate operation in opencv

2022-06-13 04:54:00 Haohong image algorithm

OpenCV Medium saturate operation ( Saturation operation ) What the hell is going on ?

Just try with two practical examples .

We use it CV_8U Type to try ,CV_8U For the range of 0~255

First example :

//OpenCV edition :3.0.0
//VS edition :2013

// Blogger WeChat /QQ 2487872782
// If you have any questions, you can contact the blogger 
// If you need image processing development, please also contact the blogger 
// Image processing technology exchange QQ Group  271891601

#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;


int main()
{
    

	cv::Mat A1(2, 3, CV_8UC1, cv::Scalar(254));
	cout << "A1 The data in is :\n" << A1 << endl << endl;

	cv::Mat B1(2, 3, CV_8UC1, cv::Scalar(2));
	cout << "B1 The data in is :\n" << B1 << endl << endl;

	cv::Mat C1;
	cv::add(A1, B1, C1);
	cout << "C1 The data in is :\n" << C1 << endl << endl;

	return(0);
}

The operation results are as follows :
 Insert picture description here
According to the truth , The result should be 256, But because the type of output matrix is also CV_8U, and CV_8U For the range of 0~255, So the value is set to 255.

Second example :

//OpenCV edition :3.0.0
//VS edition :2013

#include <opencv2/opencv.hpp>

#include <iostream>
using namespace std;


int main()
{
    

	cv::Mat A1(2, 3, CV_8UC1, cv::Scalar(254));
	cout << "A1 The data in is :\n" << A1 << endl << endl;

	cv::Mat B1(2, 3, CV_8UC1, cv::Scalar(2));
	cout << "B1 The data in is :\n" << B1 << endl << endl;

	cv::Mat C1;
	cv::subtract(B1, A1, C1);
	cout << "C1 The data in is :\n" << C1 << endl << endl;

	return(0);
}

The operation results are as follows :
 Insert picture description here
According to the truth , The result should be -252, But because the type of output matrix is also CV_8U, and CV_8U For the range of 0~255, So the value is set to 0.
Through these two examples , You should understand OpenCV Medium saturate operation ( Saturation operation ) What the hell is going on .

原网站

版权声明
本文为[Haohong image algorithm]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/164/202206130454021673.html