-1

I want to perform the independent color transformation using opencv c++ , i understand my scenario but I don't know the sequence to perform its implementation in using opencv. Letme me try to explain my scenario for further help.

I want to perform an independent RGB colour transformation on the original image pixel by pixel to increase contrast or make colour cast using opencv. Here above independent transformation means two things:

First, value of one color channel doesn't impact value of the other channels.

Second, pixels at different positions don't affect each other.

So the color transformation can be explained in such expressions:

Rxy' = transformRedChannel(Rxy, x, y)

Gxy' = transformGreenChannel(Gxy, x, y)

Bxy' = transformBlueChannel(Bxy, x, y)

In the above expression, Rxy stands for the the red channel value of a pixel at position(x, y) in the original image which is in range 0~255 and Rxy' stands for that in the goal image. The same holds for blue and green channels.

Since the function can be described by a [0, 255] -> [0, 255] mapping array, it is easy for function using 255 different gray image to generate the mapping array.

AHF
  • 1,070
  • 2
  • 15
  • 47
  • This should be very simple as openCv allows easy pixel access. See http://stackoverflow.com/questions/8932893/accessing-certain-pixel-rgb-value-in-opencv for example. You should create a new image with the same size as your input and then iterate over all pixel and call your transformation functions for every channel of every Pixel. Please post where in the process you are stuck. – Mailerdaimon May 05 '14 at 10:05
  • yes but i want that i should carry on from the original value of pixels , not from (0,0,0) – AHF May 05 '14 at 10:10
  • I don´t quite understand your comment. If you compute your 'destinationImage' from your 'sourceImage' there are no (0,0,0) left except where your 'transformation(sourcePixel)' is (0,0,0) – Mailerdaimon May 05 '14 at 10:15
  • yes this what i am saying that how can i calculate my source image color values ? as i know the `split` function but when we draw a scroll bar of colors we get 9 values of 3 colors but in split function we do it with 3 values – AHF May 05 '14 at 10:25
  • 1
    Your source image is an image. You load the image using OpenCv as Color Image (not Grayscale). Then you can access the RGB Values using 'image.at(y,x)[0]; image.at(y,x)[1]; image.at(y,x)[2];' and compute your new values and write them to another image using: 'image.at(y,x)[0] = newval[0]; image.at(y,x)[1] = newval[1]; image.at(y,x)[2] = newval[2];' – Mailerdaimon May 05 '14 at 10:28
  • but what's the difference between your code and `split(img , colors);` `colors[0] ;` `colors[1];` , `colors[2];` and then for adding values `colors[0]+20;` etc – AHF May 05 '14 at 16:07
  • colors[0] is an Image (e.g. Red channel of an RGB Image). If you wish to access a pixel in this Image you have to use colors[0].at(j,i). To change the Value you can use colors[0].at = newValue. I will copy paste my comments for better readability (and because they are actually answers). – Mailerdaimon May 06 '14 at 09:14

1 Answers1

0

Accessing RGB Values of an Image can be done either by the Method showed in Accessing certain pixel RGB value in openCV

valRed   = image.at<cv::Vec3b>(row,col)[0]; //R
valGreen = image.at<cv::Vec3b>(row,col)[1]; //G
valBlue  = image.at<cv::Vec3b>(row,col)[2]; //B

Compute your new values and write them to another image using:

image.at<cv::Vec3b>(row,col)[0] = newval[0];  //R
image.at<cv::Vec3b>(row,col)[1] = newval[1];  //G
image.at<cv::Vec3b>(row,col)[2] = newval[2];  //B

or, if you really want to use split (and create 3 new images, one per channel), you can use this:

split(img , colors);

Read:

valRed   = colors[0].at<uchar>(row,col)
valGreen = colors[1].at<uchar>(row,col)
valBlue  = colors[2].at<uchar>(row,col)

Write:

colors[0].at<uchar>(row,col) = newValRed;    //R
colors[1].at<uchar>(row,col) = newValGreen;  //G
colors[2].at<uchar>(row,col) = newValBlue;   //B
Community
  • 1
  • 1
Mailerdaimon
  • 6,003
  • 3
  • 35
  • 46
  • like `image.at(13,20)[0] += 50;` if i want to add for example 50 value on `13,20` pixels place – AHF May 06 '14 at 09:25
  • Yes, I change x,y to row,column to make the order clear. You can read even more here: http://docs.opencv.org/doc/user_guide/ug_mat.html#accessing-pixel-intensity-values – Mailerdaimon May 06 '14 at 09:31
  • If you still need help, please post the actual code you are working on – Mailerdaimon May 06 '14 at 09:32