首页 > 其他分享 >17、OpenCV灰度翻转\增强\压缩\伽马变化

17、OpenCV灰度翻转\增强\压缩\伽马变化

时间:2022-09-28 11:05:50浏览次数:59  
标签:xmin 17 int ++ OpenCV 灰度 result gray2 ptr


基本思想:基本原理参考OpenCV手册,此处只记录一下如何使用;

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

using namespace std;
using namespace cv;


int main() {

Mat img = imread("/home/ubuntu/Downloads/a.jpeg");
cout << img.cols << " " << img.rows << endl;
Mat result;
cvtColor(img, result, CV_BGR2GRAY);
cout << result.channels() << endl;
imwrite("gray.jpg",result);
Mat gray0=result.clone();
for (int i = 0; i < gray0.rows; i++) {
for (int j = 0; j < gray0.cols; j++) {
gray0.ptr<uchar>(i, j)[0] = 255 - gray0.ptr<uchar>(i, j)[0];
}
}
imwrite("subtract.jpg", gray0);
//减法操作 似乎 相差帧的背景变化很少的时候 有用

double xmin;
double xmax;
Mat gray1=result.clone();
minMaxLoc(gray1,&xmin,&xmax,0,0);
//将原来的空间的像素点拉伸到0-255空间中, 使用的比例计算(z-0)/(灰度像素-xmin)=(255-0)/(xmax-xmin)
for (int i = 0; i < gray1.rows; i++) {
for (int j = 0; j < gray1.cols; j++) {

gray1.ptr<uchar>(i, j)[0]=(255-0)/(xmax-xmin)*(gray1.ptr<uchar>(i, j)[0]-xmin);

}
}
imwrite("explosion.jpg",gray1);


// 像素压缩在 [50:150]区间范围内
Mat gray2=result.clone();
minMaxLoc(gray2,&xmin,&xmax,0,0);
//将原来的空间的像素点压缩在50-150空间中, 
for (int i = 0; i < gray2.rows; i++) {
for (int j = 0; j < gray2.cols; j++) {

gray2.ptr<uchar>(i, j)[0]=(150-50)/(xmax-xmin)*(gray2.ptr<uchar>(i, j)[0]-xmin);

}
}
imwrite("rar.jpg",gray2);

// 像素压缩在 [50:150]区间范围内
Mat gray3=result.clone();

for (int i = 0; i < gray2.rows; i++) {
for (int j = 0; j < gray2.cols; j++) {

gray3.ptr<uchar>(i, j)[0]=pow((gray3.ptr<uchar>(i, j)[0])/255.0,5.0)*255;

}
}
imshow("gray.jpg",result);
imshow("gama.jpg",gray3);

waitKey(0);
return 0;
}

17、OpenCV灰度翻转\增强\压缩\伽马变化_i++

17、OpenCV灰度翻转\增强\压缩\伽马变化_像素点_02

17、OpenCV灰度翻转\增强\压缩\伽马变化_#include_03

17、OpenCV灰度翻转\增强\压缩\伽马变化_#include_04

 

 

标签:xmin,17,int,++,OpenCV,灰度,result,gray2,ptr
From: https://blog.51cto.com/u_12504263/5718737

相关文章

  • 4、openCV 图像像素
    #-*-coding:utf-8-*-importcv2,matplotlibimportnumpyasnpimportmatplotlib.pyplotaspltcols=640rows=480image=cv2.imread('2.jpg')printimage.shapewi......
  • 3、openCV 平均图像的颜色
    #-*-coding:utf-8-*-importcv2,matplotlibimportnumpyasnpimportmatplotlib.pyplotaspltpixel=cv2.imread('2.jpg')print'pixel=',pixelaverage_img=np.aver......
  • 13、OpenCV4.4 仿射变换
    Parameters:src–Coordinatesoftriangleverticesinthesourceimage.dst–Coordinatesofthecorrespondingtriangleverticesinthedestinationimage.Thefunc......
  • 9、OpenCV4.4 色彩抽出
    色彩的空间变换#-*-coding:utf-8-*-importcv2importnumpyasnporiginal=cv2.imread('1.jpg',1)img=original.copy()#副本dst=np.zeros(img.shape,np.uint8)#......
  • ceph17-quincy离线部署
    ceph-ansible集群搭建操作系统现在centos7版本主机名IPnode110.0.0.18node210.0.0.19node310.0.0.20操作系统虚拟化软件Ubuntu22.04......
  • 引用 | pip install keybert | ERROR: Could not build wheels for tokenizers which
    window10安装keybert出错以下错误:runningbuild_extrunningbuild_rusterror:can'tfindRustcompilerIfyouareusinganoutdatedpipversion,it......
  • Day17
    Day171.字符串面试题:==和equals的区别==是用来比较地址是否一样equals是比较两个对象是否相等(比较的是内容:属性值)****注意:字符串内容,如果直接使用""来赋值,......
  • [cmake wrong]wsl opencv
    [root@DESKTOP-31LJ6LM~/g101/h1/build]$cmake..--OpenCVARCH:--OpenCVRUNTIME:--OpenCVSTATIC:OFFCMakeWarningat/mnt/e/DevelopeTools/opencv/opencv/......
  • CF 1714 D
    感觉这次D比F还难……题面传送门走起!思路原先我的贪心写挂了。我只考虑了开头,没考虑结尾。事实证明结尾才是最重要的!本题数据非常小。从开头起,贪心的选择染哪......
  • Python cv2(Opencv) Canny边缘检测 和 傅里叶变换
    OpenCV是一个基于Apache2.0许可(开源)发行的跨平台计算机视觉和机器学习软件库,可以运行在Linux、Windows、Android和MacOS操作系统上。它轻量级而且高效,由一系列C函数和少......