We sometimes take pictures where there is no light, so the pictures come out dark. This means it did not have a wide range of colors. For example, an image with a minimum value of 20 and a maximum value of 100 will be dark. So we need to wide the color range of the image 0 to 255.
The full code is as follows.
#include <iostream> #include <opencv2/opencv.hpp> using namespace cv; using namespace std; void meanVal(Mat* inputArray){ double minVal, maxVal; minMaxIdx(*inputArray, &minVal, &maxVal); //get min, max value of matrix
double ratio = (maxVal - minVal)/255; *inputArray = (*inputArray - minVal)/ratio; // wide image range
cout << minVal << "," << maxVal << endl; } int main() { Mat img = imread("./res/woman.png"); imshow("origin", img); vector<Mat> bgr_img; split(img, bgr_img); // split matrix to 3 channels (Blue, Green, Red)
meanVal(&bgr_img[0]); meanVal(&bgr_img[1]); meanVal(&bgr_img[2]); merge(bgr_img, img); // merge three channels to on matrix img = img + Scalar(10, 20, 20); // add warm color to img
imshow("result", img); waitKey(0); return 0; }
- Split matrix by channel
void split(InputArray mat, OutputArrayOfArrays mv)
- Merge channels to one matrix
void merge(InoutArraysOfArrays mv, OutputArray mat)
- Get min, max value of matrix
void minMaxIdx(InputArray src, double* minVal, double* maxVal = 0, int* minIdx = 0, int* maxIdx = 0, InputArray mask = noArray());
Comments
Post a Comment