I tried to do some simple gamma correction on an image. At first, I tried using Matlab then I apply it on opencv. But I get different result. Below is some of the code. Where does the code goes wrong?
In matlab:
for i=1:r;
for j=1:c;
imout(i,j)=constant_value*power(img_double(i,j),0.04);
end
end
In OpenCV:
for(int y=0; y<height; y++){
for(int x=0; x<width; x++)
{
dataNew[y*stepNew+x] = constant_value*pow(dataNew[y*stepNew+x], 0.04);
}
}
Where the image is an unsigned 8 bit, 1 channel image. Which part that I miss?
My guess is that you forgot to scale your image data in OpenCV to the interval [0,1]. In Matlab
im2doubledoes this for you automatically.So for an 8 bit image something like this should work: