c++ - 解释颜色函数和调整像素值

标签 c++ image opencv image-processing computer-vision

这是我从网上看到的定义

第一个是

Midtone: Situated between the darkest tone (Black), and the brightest tone (White). For a 24 bit colour image, this occurs when Red = Green = Blue = 128.

另一个是

Tones created by dots between 30% and 70% of coverage

Midtone also refers to the range of colors that aren't mixed with black (the shadows) or white (the highlights).

我从这些定义中得到的是,我们应该将值为 0 或 255 的像素调整为 128 。我的定义正确吗?我不想使用直方图均衡的方式,因为据我所知它也用于图像的亮度

我想执行如下功能,就像我想在 OpenCV C++ 中执行此功能一样,但我不知道如何处理 Midtones 和 CYMK 值,因为它同时具有RGB 和 CMYK 同时显示

enter image description here

例如 示例图片

enter image description here

应用上述值后

enter image description here

我想在 OpenCV 中做同样的事情

如果我们只用 RGB 执行此操作,我只关心结果

编辑

安德烈的回答很好,但仍在等待最佳答案,因为这个答案很难让其他图像调整其他颜色平衡值

最佳答案

我认为在这种情况下,阴影、中间调和高光定义了轨迹栏值的范围。

  • 阴影 - 精确调整(小范围);
  • 中间调 - 中等调整(中等范围);
  • 亮点 - 重大调整(范围广泛)。

它允许快速和精确的颜色校正。

代码片段:

#include <iostream>
#include <vector>
#include <stdio.h>
#include <functional>
#include <algorithm>
#include <numeric>
#include <cstddef>
#include "opencv2/opencv.hpp"
using namespace std;
using namespace cv;

int val_Cyan_Red=0;
int val_Magenta_Green=0;
int val_Yellow_Blue=0;
Mat result;
Mat Img;

void on_trackbar( int, void* )
{
float SH=0.1; // The scale of trackbar ( depends on ajusting mode Shadows/Midtones/Highlights )

float cr_val=(float)val_Cyan_Red/255.0;
float mg_val=(float)val_Magenta_Green/255.0;
float yb_val=(float)val_Yellow_Blue/255.0;
// Cyan_Red
float R1=0;
float G1=1;
float B1=1;

float R2=1;
float G2=0;
float B2=0;

float DR=(1-cr_val)*R1+(cr_val)*R2-0.5;
float DG=(1-cr_val)*G1+(cr_val)*G2-0.5;
float DB=(1-cr_val)*B1+(cr_val)*B2-0.5;

result=Img+(Scalar(DB,DG,DR)*SH);

// Magenta_Green
 R1=1;
 G1=0;
 B1=1;

 R2=0;
 G2=1;
 B2=0;

 DR=(1-mg_val)*R1+(mg_val)*R2-0.5;
 DG=(1-mg_val)*G1+(mg_val)*G2-0.5;
 DB=(1-mg_val)*B1+(mg_val)*B2-0.5;

result+=(Scalar(DB,DG,DR)*SH);

// Yellow_Blue

 R1=1;
 G1=1;
 B1=0;

 R2=0;
 G2=0;
 B2=1;

 DR=(1-yb_val)*R1+(yb_val)*R2-0.5;
 DG=(1-yb_val)*G1+(yb_val)*G2-0.5;
 DB=(1-yb_val)*B1+(yb_val)*B2-0.5;

result+=(Scalar(DB,DG,DR)*SH);

imshow("Result",result);
waitKey(10);
}

// ---------------------------------
// 
// ---------------------------------
int main( int argc, char** argv )
{
    namedWindow("Image",cv::WINDOW_NORMAL);
    namedWindow("Result");

    Img=imread("D:\\ImagesForTest\\cat2.jpg",1);
    Img.convertTo(Img,CV_32FC1,1.0/255.0);  

   createTrackbar("CyanRed", "Image", &val_Cyan_Red, 255, on_trackbar);
   createTrackbar("MagentaGreen", "Image", &val_Magenta_Green, 255, on_trackbar);
   createTrackbar("YellowBlue", "Image", &val_Yellow_Blue, 255, on_trackbar);

    imshow("Image",Img);
    waitKey(0);
}

大致为上述值的结果(零偏移为 128): enter image description here

关于c++ - 解释颜色函数和调整像素值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23213925/

相关文章:

c++ - "-Wall"中的 "g++ -Wall test.cpp -o test"有什么作用?

c++ - 解决多定义的内联函数是一个定义明确的东西吗?

c# - 动态添加图像到asp.net c# gridview

图像相似性和 k 均值聚类

python-2.7 - bitwise_and 它是如何工作的?

python - 使用cv2在python中在手绘图像上连接角的线

python - 是OpenCV函数 "pyrDown"设计的bug吗

c++ - 尝试在 C++、MinGW 上获取当前进程内存大小时出错

c++ - 是否有针对 CUDA-GPU 或 MPI-CPU+CUDA-GPU 的基准测试?

python - 处理屏幕截图中的图像 - Python