当前位置: 首页 > news >正文

【c++|opencv】二、灰度变换和空间滤波---1.灰度变换、对数变换、伽马变换

every blog every motto: You can do more than you think.
https://blog.csdn.net/weixin_39190382?type=blog

0. 前言

灰度变换、对数变换、伽马变换

1. 灰度变换

#include <iostream>
#include <opencv2/opencv.hpp>using namespace std;
using namespace cv;int main() 
{Mat img,out_img,img_gray;img = imread("/home/v/home.png");if (img.empty()){cout << "Could not open or find the image" << endl;return -1;}cvtColor(img, img_gray, COLOR_BGR2GRAY);imshow("img gray",img_gray); out_img = img_gray.clone();for (int i=0;i<img_gray.rows;i++){for (int j=0;j<img_gray.cols;j++){// 灰度翻转out_img.at<uchar>(i,j) = 255 - img_gray.at<uchar>(i,j); }}imshow("灰度翻转",out_img);waitKey(0);return 0;}

在这里插入图片描述

2. 对数变换

#include <iostream>
#include <opencv2/opencv.hpp>using namespace std;
using namespace cv;int main() 
{Mat img,out_img,img_gray;img = imread("/home/v/home.png");if (img.empty()){cout << "Could not open or find the image" << endl;return -1;}cvtColor(img, img_gray, COLOR_BGR2GRAY);imshow("img gray",img_gray); out_img = img_gray.clone();for (int i=0;i<img_gray.rows;i++){for (int j=0;j<img_gray.cols;j++){// 对数变换6*log(r+1) 伽马变换out_img.at<uchar>(i,j) = 6*log((double)(img_gray.at<uchar>(i,j)) + 1);}}normalize(out_img,out_img,0,255,NORM_MINMAX); // 图像归一化convertScaleAbs(out_img,out_img); // 数据类型转换到CV_8Uimshow("对数变换",out_img);waitKey(0);return 0;}

在这里插入图片描述

3. 伽马变换

#include <iostream>
#include <opencv2/opencv.hpp>using namespace std;
using namespace cv;int main() 
{Mat img,out_img,img_gray;img = imread("/home/v/home.png");if (img.empty()){cout << "Could not open or find the image" << endl;return -1;}cvtColor(img, img_gray, COLOR_BGR2GRAY);imshow("img gray",img_gray); out_img = img_gray.clone();for (int i=0;i<img_gray.rows;i++){for (int j=0;j<img_gray.cols;j++){// 伽马变换6*r^0.5out_img.at<uchar>(i,j) = 6*pow((double)(img_gray.at<uchar>(i,j)),0.5);}}normalize(out_img,out_img,0,255,NORM_MINMAX); // 图像归一化convertScaleAbs(out_img,out_img); // 数据类型转换到CV_8Uimshow("伽马变换",out_img);waitKey(0);return 0;}

在这里插入图片描述

http://www.lryc.cn/news/212738.html

相关文章:

  • 【vue3】子传父-事件总线-mitt(子组件派发事件,父组件接收事件和传递的参数)
  • 【杂记】java 大集合进行拆分
  • select...for update 锁表了?
  • 使用ControlNet生成视频(Pose2Pose)
  • 基于Docker使用Minikube
  • Stable Diffusion系列(一):古早显卡上最新版 WebUI 安装及简单操作
  • ruoyi框架前端vue部署生产环境教程
  • leetcode第369周赛
  • 如何在维格云中自动新增一行或多行数据?
  • Three.js 开发引擎的特点
  • k8s声明式资源管理方式
  • unity性能优化__Statistic状态分析
  • Linux Spug自动化运维平台公网远程访问
  • 3DES算法
  • 手机电池寿命检测
  • Vue项目搭建及使用vue-cli创建项目、创建登录页面、与后台进行交互,以及安装和使用axios、qs和vue-axios
  • AVL树、红黑树的介绍和实现[C++]
  • meta分析的异质性检验指标如何计算?
  • 如何在mac 安装 cocos 的 android环境
  • 作为网工有必要了解一下什么是SRv6?
  • Jmeter(十八):硬件性能监控指标详解
  • 【ARM Trace32(劳特巴赫) 使用介绍 2 -- Trace32 cmm 脚本基本语法及常用命令】
  • 2023年第七期丨全国高校大数据与人工智能师资研修班
  • 一文获取鼎捷医疗器械行业数智化合规敏态方案
  • 2023最新版本 FreeRTOS教程 -1-标准库移植FreeRTOS
  • python笔记(函数参数、面向对象、装饰器、高级函数、捕获异常)
  • JAVA命令总结
  • 删除的PPT怎么找回来?4个必备恢复方法!
  • Binder机制总结笔记
  • SQL SERVER 表分区