Ask Your Question

Revision history [back]

a trial code just to show some possibilities around your question

#include "opencv2/opencv.hpp"

using namespace cv;

int main(int argc, char** argv)
{
    Mat src= imread( argv[1] );

    imshow("source", src);

    src = src + Scalar(40,40,40); // to remove jpeg artifacts

    Mat mask;
    cvtColor( src, mask, COLOR_BGR2GRAY );

    mask = mask < 255;

    add(src,Scalar(0,60,20),src,mask);

    Mat blackbg = Mat::zeros(src.size(),CV_8UC3);
    src.copyTo( blackbg, mask);

    imshow("mask", mask);
    imshow("result", src);
    imshow("blackbg", blackbg);
    waitKey();

    return 0;
}

output images : ( uploaded resized )

image descriptionimage descriptionimage description

a trial code just to show some possibilities around your question ( assuming the background will be always white )

#include "opencv2/opencv.hpp"

using namespace cv;

int main(int argc, char** argv)
{
    Mat src= imread( argv[1] );

    imshow("source", src);

    src = src + Scalar(40,40,40); // to remove jpeg artifacts

    Mat mask;
    cvtColor( src, mask, COLOR_BGR2GRAY );

    mask = mask < 255;

    add(src,Scalar(0,60,20),src,mask);

    Mat blackbg = Mat::zeros(src.size(),CV_8UC3);
    src.copyTo( blackbg, mask);

    imshow("mask", mask);
    imshow("result", src);
    imshow("blackbg", blackbg);
    waitKey();

    return 0;
}

output images : ( uploaded resized )

image descriptionimage descriptionimage description