How to add light color to original image

asked 2015-08-26 02:49:16 -0600

zms gravatar image

Hello, Does anyone know how to color a light red color into the original image source in opencv C++ coding ? The image as below

image description

TQ

edit retag flag offensive close merge delete

Comments

1

Do you want color all the image, or know beforehand which roi to color? Then addWeighted may be the direct solution

LorenaGdL gravatar imageLorenaGdL ( 2015-08-26 03:39:51 -0600 )edit

may be you can use HSV space :

int main (int argc,char **argv)
{
Mat img = imread("14405753399632309.png", IMREAD_ANYCOLOR);
Mat imgHSV,imgRGB;
cout << img.channels() << "\n";
cvtColor(img,imgHSV,COLOR_BGR2HSV);
for (int i = 0; i < imgHSV.rows; i++)
{
    Vec3b *ptr=(Vec3b*)imgHSV.ptr(i);
    for (int j=0;j<imgHSV.cols;j++,ptr++)
        if ((*ptr)[1]<127 )
            (*ptr)[1] *= 2;
        else
            (*ptr)[1] = 255;

}
cvtColor(imgHSV,imgRGB,COLOR_HSV2BGR);
imshow("Original ",img);
imshow("Saturate ",imgRGB);
waitKey();
return 0;
}
LBerger gravatar imageLBerger ( 2015-08-26 05:08:42 -0600 )edit

@LorenaGdL I had read the addweighted but why I need to source of array? Is it going to have more processing power?

@LBerger why if if ((ptr)[1]<127 ) (ptr)[1] = 2; else (ptr)[1] = 255; is needed? we need to compare what actually in the image?

TQ

zms gravatar imagezms ( 2015-08-28 01:56:40 -0600 )edit

@zms

      if ((ptr)[1]<127 ) // if value is less than 127
          (ptr)[1] *= 2;  // we can multiply by 2 (value would be less than 255
       else 
           (ptr)[1] = 255;// we saturate (saturate_cast is possible too  i think)
LBerger gravatar imageLBerger ( 2015-08-28 02:14:10 -0600 )edit

@zms: sorry, I haven't understood your last question. What is your problem with addWeighted?

LorenaGdL gravatar imageLorenaGdL ( 2015-08-28 02:25:36 -0600 )edit