Question

I've looked at the documentation but I couldn't find if there was a method for transforming the colors for an entire image using some formula. Would this be somehow related to the color curve functions because I'm not too sure what effects those have- I've tried them but do not understand what effect each parameter has.

For example: If I want to take an image and tranform the colors using the following formula

(2R - 0.5G - B)/4

I read through the functions and some seem like they may apply but the meaning of the parameters are unclear to me. Is there a method for SimpleCV and/or OpenCV to do this?

EDIT:

By transform, I mean take the RGB values of the image and apply that formula to them so those are the new RGB values. OR instead of a formula, to use a matrix like:

[Y] [0.299 0.587 0.114 ][R]

[I] = [0.596 -0.274 -0.322 ][G]

[Q] [0.212 -0.523 0.311 ][B]

Was it helpful?

Solution

To do this in SimpleCV you just do:

from SimpleCV import *
img = Image('simplecv')
(r,g,b) = img.splitChannels(False) #we pass false to break into color channels, not greyscale
updated = ((r * 2) - (g * 0.5) - b)/4
updated.show()

OTHER TIPS

It dpeends on what interface you're using.

If you're using python it's fairly simple as images are represented as numpy arrays.

So to get an image that was (2R - 0.5G - B)/4 you could do:

imgF = img.astype('float') # convert from INT to FLOAT
# note that OpenCV loads it as Blue,Green,Red. not RGB.
imgTransformed = (2.*imgF[:,:,2] - .5*imgF[:,:,1] - imgF[:,:,0])/4

For matrix transforms, have a look at OpenCV's transform function. As per documentation, it performs:

dest(I) = mtx * src(I)

for each index I.

So for the matrix example in your question, you'd do

cv2.transform( img, [ [ 0.114, 0.587, 0.299],
                      [-0.322, 0.274, 0.596],
                      [ 0.311,-0.523, 0.212] ] )

Note - I swapped your columns 1 and 3 because in OpenCV the images are read in with channel order B,G,R instead of R,G,B.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top