本文主要是介绍photoshop 彩色影像 色调均化 c++,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
色调均化:彩色影像统计三个颜色通道的直方图的累积概率 --> 计算色阶映射表-->映射颜色
#include <opencv2/opencv.hpp>
#include <iostream>
#include <algorithm>
#include <vector>bool ImgEqualization(cv::Mat& img)
{std::vector<cv::Mat> splitImg(3);cv::split(img, splitImg);int histSize = 256;float range[] = { 0, 256 };const float* histRange = { range };bool uniform = true; bool accumulate = false;cv::Mat b_hist, g_hist, r_hist;cv::calcHist(&splitImg[0], 1, 0, cv::Mat(), b_hist, 1, &histSize, &histRange, uniform, accumulate);cv::calcHist(&splitImg[1], 1, 0, cv::Mat(), g_hist, 1, &histSize, &histRange, uniform, accumulate);cv::calcHist(&splitImg[2], 1, 0, cv::Mat(), r_hist, 1, &histSize, &histRange, uniform, accumulate);cv::Mat hist = b_hist.clone();hist += g_hist;hist += r_hist;{hist /= (img.rows *img.cols *3.0);float* ptr = (float*)hist.data;for (int i = 1; i < hist.rows; i++) {ptr[i] += ptr[i - 1];}}{float* ptr = (float*)hist.data;for (int i = 0; i < img.rows; i++) {cv::Vec3b* dstImgPtr = img.ptr<cv::Vec3b>(i);for (int j = 0; j < img.cols; j++) {dstImgPtr[j][0] = ptr[dstImgPtr[j][0]] * 255;dstImgPtr[j][1] = ptr[dstImgPtr[j][1]] * 255;dstImgPtr[j][2] = ptr[dstImgPtr[j][2]] * 255;}}}return true;
}
这篇关于photoshop 彩色影像 色调均化 c++的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!