Gamma, Tonemapping, - basics hdr
Hey
Fairly new here, going over the docs currently. But before I start climbing the wall... can any1 clear up some things for me?
- I have a HDR 32 bit per channel, 3 channels. As far as I can tell that is "CV_32FC3" ?
- How can I print-text stuff like mat.type() ? I get a number, but I don't know where to look at to figure out what it is.
- How can I control gamma, is there dedicated function or do I just get bits and run a loop function over the array? - feels a bit slow if I have to do it on cpu... does openCV offer any openGL/etc option for it?
I've created a Mat using this command >
cv::Mat img(FreeImage_GetHeight(hdrImage), FreeImage_GetWidth(hdrImage), CV_32FC4, FreeImage_GetBits(hdrImage), FreeImage_GetPitch(hdrImage));
Now when I do- I messed up conversionqDebug() << "Type type ? : " << CV_32FC4;
I get a number 29, but when I doqDebug()<<img.type()
I get something like 21. - what did I miss understand here?cvtColor(img, img, COLOR_BGRA2RGBA);
I'm now getting proper type!And then when trying to do
img.convertTo(img, CV_8SC4/CV_8UC4);
I get lots of bad stuff/crashes. I want to convert here from 32 bit per channel image rgba to 8 bit or uchar per channel. How can I accomplish it properly?
Am I even calling the things I want to do correctly?
So far thats it, I'll update the topic as I solve the issues. So far its exciting stuff :- )
TIA
Got stuck with more conversions.. I have the given CV_32FC4 image that come from freeImage that is EXR. I then want to convert it to 8 bit for QImage but all I get is zip. I tried convertTo(CV8/16/U/S/C4)
etc/etc but no luck.
raw9 = QImage((const uchar *) img.data, img.cols, img.rows, img.step, QImage::Format_RGBA8888); // no luck
raw9 = QImage((const uchar *) img.data, img.cols, img.rows, img.step, QImage::Format_RGBA64); // no luck
Any helps would be amazing, I'm getting lost with these bits/bytes/channels... :- C
I had some luck via accessing img.data directly and converting to what I need... like :
auto imgData = reinterpret_cast<float *>(img.data);
for (int a = 0; a < data.size(); a = a + img.channels()) {
data[a] = imgData[a] * 255;
data[a + 1] = imgData[a + 1] * 255;
data[a + 2] = imgData[a + 2] * 255;
data[a + 3] = imgData[a + 3] * 255;
}
But I get some bad red/yellow pixels > Bad Pixels - How to bite/solve it?
Above issues got solved magically by img.convertTo(img,CV_8U,255) < the 255 "scale factor" does something magical! Thank you barek for help!
Ok moving on... we solved the bit depth conversion... Now.. gamma! :D
As far as I can tell this "works"
cv::pow(img, 1.0f / 2.2f, img);
img.convertTo(img, CV_8U, 255);
But as I have RGBA the alpha gets also gamma corrected which is not desired...
Does ...
are you really sure it has 4 channels, not 3 ? (exr images rarely have an alpha channel, it would not make much sense)
I have multiple HDR/EXR images, with 3-4 channels. Some exr are multi-layered and I didn't even start looking into them yet. So yep I'm "for now" sure I have 4 channels available in the file.
imho, your gamma correction workflow above is correct.
I have follow up question :- ) does extractChannel produce a deepCopy or shallow one? / same goes for Split ?
deep copy, think of it, the internal Mat representation is BGRABGRABGRA... and youwant a specific channel extracted.