Ask Your Question

Revision history [back]

as a startup i suggest this simple code

#include <opencv2/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>

int main(int argc, char** argv)
{

    cv::Mat bgr_image = cv::imread("14349796948124829.png");
    cv::Mat brightened_image = bgr_image*1.25;

    cv::imshow("image", bgr_image);
    cv::imshow("brightened image", brightened_image);
    cv::imwrite("brightened.png",brightened_image);
    cv::waitKey();
}

the result image is like this but we can improve the code if it is not what you want image description

as a startup i suggest this simple code

#include <opencv2/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>

int main(int argc, char** argv)
{

    cv::Mat bgr_image = cv::imread("14349796948124829.png");
    cv::Mat brightened_image = bgr_image*1.25;
bgr_image*1.25; // multiple image means brigthness

    cv::imshow("image", bgr_image);
    cv::imshow("brightened image", brightened_image);
    cv::imwrite("brightened.png",brightened_image);
    cv::waitKey();
}

the result image is like this but we can improve the code if it is not what you want image description


and the second try improving your code

#include <opencv2/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <vector>       // std::vector
int main(int argc, char** argv)
{
    // READ RGB color image and convert it to Lab
    cv::Mat bgr_image = cv::imread("14349796948124829.png");
    bgr_image*=1.3;

    cv::Mat lab_image;
    cv::cvtColor(bgr_image, lab_image, CV_BGR2Lab);

    // Extract the L channel
    std::vector<cv::Mat> lab_planes(3);
    cv::split(lab_image, lab_planes);  // now we have the L image in lab_planes[0]

    // apply the CLAHE algorithm to the L channel
    cv::Ptr<cv::CLAHE> clahe = cv::createCLAHE();
    clahe->setClipLimit(2); // changed parameter 4 to 2
    cv::Mat dst;
    clahe->apply(lab_planes[0], dst);

    // Merge the the color planes back into an Lab image
    dst.copyTo(lab_planes[0]);
    cv::merge(lab_planes, lab_image);

    // convert back to RGB
    cv::Mat image_clahe;
    cv::cvtColor(lab_image, image_clahe, CV_Lab2BGR);

    // display the results  (you might also want to see lab_planes[0] before and after).
    cv::imshow("image original", bgr_image);
    cv::imshow("image CLAHE", image_clahe);
    cv::imwrite("image_clahe.png",image_clahe);
    cv::waitKey();
}

the result image image description

as a startup i suggest this simple code

#include <opencv2/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>

int main(int argc, char** argv)
{

    cv::Mat bgr_image = cv::imread("14349796948124829.png");
    cv::Mat brightened_image = bgr_image*1.25; // multiple image means brigthness

    cv::imshow("image", bgr_image);
    cv::imshow("brightened image", brightened_image);
    cv::imwrite("brightened.png",brightened_image);
    cv::waitKey();
}

the result image is like this but we can improve the code if it is not what you want image description


and the second try improving your code

#include <opencv2/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <vector>       // std::vector
int main(int argc, char** argv)
{
    // READ RGB color image and convert it to Lab
    cv::Mat bgr_image = cv::imread("14349796948124829.png");
    bgr_image*=1.3;

    cv::Mat lab_image;
    cv::cvtColor(bgr_image, lab_image, CV_BGR2Lab);

    // Extract the L channel
    std::vector<cv::Mat> lab_planes(3);
    cv::split(lab_image, lab_planes);  // now we have the L image in lab_planes[0]

    // apply the CLAHE algorithm to the L channel
    cv::Ptr<cv::CLAHE> clahe = cv::createCLAHE();
    clahe->setClipLimit(2); // changed parameter 4 to 2
    cv::Mat dst;
    clahe->apply(lab_planes[0], dst);

    // Merge the the color planes back into an Lab image
    dst.copyTo(lab_planes[0]);
    cv::merge(lab_planes, lab_image);

    // convert back to RGB
    cv::Mat image_clahe;
    cv::cvtColor(lab_image, image_clahe, CV_Lab2BGR);

    // display the results  (you might also want to see lab_planes[0] before and after).
    cv::imshow("image original", bgr_image);
    cv::imshow("image CLAHE", image_clahe);
    cv::imwrite("image_clahe.png",image_clahe);
    cv::waitKey();
}

the result image image

image description


and the last

#include <opencv2/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>

int main(int argc, char** argv)
{

    cv::Mat bgr_image = cv::imread("14349796948124829.png");
    cv::Mat brightened_image = bgr_image*1.3;
    cv::addWeighted(brightened_image,0.8,bgr_image,0.2,0,brightened_image);
    cv::imshow("image", bgr_image);
    cv::imshow("brightened image", brightened_image);
    cv::imwrite("brightened2.png",brightened_image);
    cv::waitKey();
}

the result image

image description


for comparison source and result images

image description


image description


image description


image description