Ask Your Question

Tim Redfern's profile - activity

2013-07-18 09:04:07 -0600 answered a question fixed point arithmetic

I managed to achieve this using cv::Mat.mul(Cv::Mat,double), but it turns out to be slower than just using integer arithmetic 'manually'

for reference: the openCV algorithm I used was:

vector<cv::Mat> ichans,ochans;
vector<cv::Mat> compchans;
cv::split(rgb,ichans);
cv::split(other.rgb,ochans);
uint8_t b=0xFF;
cv::Mat iA=b-other.alpha;
for (int i=0;i<3;i++) {
    compchans.push_back(ichans[i].mul(iA,1.0/255.0)+ochans[i].mul(other.alpha,1.0/255.0));
}
merge(compchans,rgb);

but, it proved quicker to just do:

for (int i=0;i<w*h*3;i++) {
    rgb.data[i]=(uint8_t)(((((int)rgb.data[i])*(0xFF-other.alpha.data[i/3]))>>8)+((((int)other.rgb.data[i])*((int)other.alpha.data[i/3]))>>8));
}
2013-07-17 03:12:17 -0600 received badge  Nice Answer (source)
2013-07-16 18:12:22 -0600 received badge  Teacher (source)
2013-07-16 08:46:56 -0600 answered a question How can I get an effect similar to Curve Adjustment Layers of Photoshop using OpenCV?

cv::LUT is great for this kind of thing. Create one or more lookup tables for the curves (either the same for all or seperate ones for RGB), and then map all of the pixel values through it to do the remap.

2013-07-16 08:01:36 -0600 asked a question fixed point arithmetic

Hi, I wonder if anyone can help me with a basic question about the way openCV calculates pixel values.

I want to implement alpha masking, using CV_8U4 matrices.

So, if there are 2 input images in1 and in2,

out.R=(in1.R*(255-in2.A))+(in2.R*in2.A)

out.G=(in1.G*(255-in2.A))+(in2.R*in2.A)

out.B=(in1.B*(255-in2.A))+(in2.R*in2.A)

in other words- I want to use a fixed point arithmetic in the same way openGL does, where 0 represents 0.0f and 255 represents 1.0f..

or in other words:

0*0=0
128*128=64
255*255=255

however, in2.R.mul(in2.A) doesn't work like this - and in2.R.mul(in2.A,1.0/255.0) doesn't either.

Is there any way to easily do openGL style pixel operations in openCV?

Thanks

Tim Redfern