Ask Your Question

Revision history [back]

Apply transformation matrix to pixels in OpenCV image

I want to change the color basis of an image from RGB to something else. I have a matrix M that I want to apply to each pixel's RGB, which we can define as xij.

I am currently iterating over each pixel of the NumPy image and calculating Mxij manually. I can't even vectorize it over the rows, because the RGB is a 1x3 instead of a 3x1 array.

Is there a better way to do this? Maybe a function in OpenCV or NumPy?

click to hide/show revision 2
retagged

updated 2014-02-28 00:37:50 -0600

berak gravatar image

Apply transformation matrix to pixels in OpenCV image

I want to change the color basis of an image from RGB to something else. I have a matrix M that I want to apply to each pixel's RGB, which we can define as xij.

I am currently iterating over each pixel of the NumPy image and calculating Mxij manually. I can't even vectorize it over the rows, because the RGB is a 1x3 instead of a 3x1 array.

Is there a better way to do this? Maybe a function in OpenCV or NumPy?