Ask Your Question
1

How to increase the text brightness opencv c++

asked 2015-06-22 06:04:52 -0600

ashok gravatar image

updated 2015-06-22 08:31:42 -0600

This is output image:C:\fakepath\Screen Shot 2015-06-22 at 6.57.01 pm.png

This actual image: C:\fakepath\Screen Shot 2015-06-22 at 6.56.20 pm.png

How to increase the text brightness of text document using opencv c++ in IOS.I am changed the text document color to white, text is display very light. Thanks in advance.

cv::Mat lab_image; cv::cvtColor(src, 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(4);
    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 imgH;
    cv::cvtColor(lab_image, imgH, CV_Lab2BGR);
edit retag flag offensive close merge delete

Comments

try some histogram equalization approach in order to fix the contrast of the image. Have a look in the following examples. 1, 2, 3

theodore gravatar imagetheodore ( 2015-06-22 07:04:41 -0600 )edit

If i use Histogram equalization document is converted to gray color. My document have somany color of text . I am tried with 3rd solution, it's changed the actual color of text. Please give me any other suggestions.

ashok gravatar imageashok ( 2015-06-22 07:38:47 -0600 )edit

i think, if you provide sample image and what you tried as code then you can get more information

sturkmen gravatar imagesturkmen ( 2015-06-22 07:56:36 -0600 )edit

@ashok, can we close your other question then ? it's bad to have duplicates

berak gravatar imageberak ( 2015-06-22 08:49:31 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2015-06-22 09:36:28 -0600

updated 2015-06-22 11:11:00 -0600

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 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

edit flag offensive delete link more

Comments

Thanks for the code.

ashok gravatar imageashok ( 2015-06-23 06:12:20 -0600 )edit
1

you are welcome! If you want to let people know it is solved, than accept an answer. It will show solved on the main page than.

sturkmen gravatar imagesturkmen ( 2015-06-24 20:09:53 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-06-22 06:04:52 -0600

Seen: 1,878 times

Last updated: Jun 22 '15