#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
void Reverse(Mat img,Mat src)
{
for (int i = 0;i < img.rows;i++)
{
for (int j = 0;j < img.cols;j++)
{
src.at<uchar>(i, j) = 255 - img.at<uchar>(i, j);
}
}
}
void Log(Mat img, Mat src,int c)
{
for (int i = 0;i <img.rows;i++)
{
for (int j = 0;j < img.cols;j++)
{
int b = c*log(1+img.at<uchar>(i, j));
int d = b % 256;
src.at<uchar>(i, j) = d;
}
}
}
void Cutting(Mat img, Mat src, float r1,float r2)
{
for (int i = 0;i < img.rows;i++)
{
for (int j = 0;j < img.cols;j++)
{
if (img.at<uchar>(i, j) >= 0.0 && img.at<uchar>(i, j) <= r1)
{
src.at<uchar>(i, j) = img.at<uchar>(i, j);
}
if (img.at<uchar>(i, j) >= r1 &&img.at<uchar>(i, j) <= r2)
{
src.at<uchar>(i, j) = 200;
}
if (img.at<uchar>(i, j) >= r2 && img.at<uchar>(i, j) <= 255.0)
{
src.at<uchar>(i, j) = img.at<uchar>(i, j);
}
}
}
}
int main ()
{
Mat img=imread("D://zc//tp//eight.tif",0);
Mat src(img.rows,img.cols,CV_8UC1,Scalar(0,0,0));
cout<<src.rows<<endl;
// Reverse(img,src);
// Log(img,src,50);
Cutting(img, src, 50.0, 100.0);
imshow("img",img);
imshow("src",src);
waitKey();
return 0;
}
像素的灰度变换
最新推荐文章于 2023-11-16 22:59:37 发布