Firstly you should do a profile to see where the time is mostly going. Maybe it is all in imdecode()
, as "seems clear", but you might be wrong.
If not, .at<>()
is a bit slow (and you are calling it nearly 4 million times). You can get some speedup by more efficent scanning of the image. Also you do not need floor()
- that will avoid converting an int to double and back again (2 million times). Something like this will be faster:
int x , y;
for(y = 0; y < 1232; y++){
uint8_t* row = Reconstructed.ptr<uint8_t>(y);
if(y % 2 == 0){
uint8_t* i0 = imgMat[0].ptr<uint8_t>(y / 2);
uint8_t* i1 = imgMat[1].ptr<uint8_t>(y / 2);
for(x = 0; x < 1616; ){
//R
row[x] = i0[x / 2];
x++;
//G1
row[x] = i1[x / 2];
x++;
}
}
else {
uint8_t* i2 = imgMat[2].ptr<uint8_t>(y / 2);
uint8_t* i3 = imgMat[3].ptr<uint8_t>(y / 2);
for(x = 0; x < 1616; ){
//G2
row[x] = i2[x / 2];
x++;
//B
row[x] = i3[x / 2];
x++;
}
}
}