对图形进行对数变换

本文深入探讨了对数变换在图形处理中的应用,解释了如何通过对数变换改变图形的尺度,使得数据中的小变化在图形上得到放大,从而更好地观察和理解数据的细节。内容涵盖了对数函数的基本性质、对数尺度的创建以及在各种图表(如直方图、折线图等)中的实际应用案例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include <iostream>  
#include <string.h>
#include <opencv2/core/core.hpp>  
#include <opencv2/highgui/highgui.hpp>  
#include <opencv2\core\mat.hpp>
#include<opencv2/opencv.hpp>
#define e 2.71828182845
using namespace cv;
using namespace std;

void main()
{
	Mat img = imread("pic2.jpg");//读取图像img。0表示转换为灰度图像读入
	imshow("原图", img);
	waitKey(0);
	int height = img.rows;
	int width = img.cols; 
	//浮点变换
	Mat fimg(height, width, CV_32FC3);
	img.convertTo(fimg, CV_32FC3,1/255.0);
	
	//将修改后的像素值放入另一个图片中
	Mat fimg2(height,width, CV_32FC3);
	for (int row = 0; row < height; row++)
		for (int col = 0; col < width; col++)
		{
			
			fimg2.at<Vec3f>(row, col)[0] = float(log(fimg.at<Vec3f>(row, col)[0])+1.0);
			fimg2.at<Vec3f>(row, col)[1] = float(log(fimg.at<Vec3f>(row, col)[1])+1.0);
			fimg2.at<Vec3f>(row, col)[2] = float(log(fimg.at<Vec3f>(row, col)[2])+1.0);
		}
	namedWindow("rgb", 0);
	imshow("rgb",fimg2);
	waitKey(0);
	//三通道进行输出
	for (int i = 0; i < 3; i++)

	{

		Mat bgr(height, width, CV_32FC3, Scalar(0, 0, 0));

		Mat out[] = { bgr };

		int from_to[] = { i, i };

		mixChannels(&fimg2, 1, out, 1, from_to, 1);

		//获得其中一个通道的数据进行分析
		imshow("1 channel", bgr);
		waitKey();

	}
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值