Hi,
I'm trying to code a very simple raw developing tool. First I want to read and understand the data libraw provides.
But the data I get does not represent the colors in PhotoShop by any means. They are not off by a some digits, they seem to be completely different. The data I get is in the xls and the coresponding first 10x10 pixels from Photoshop. Unfortuantely the cr2 is too big to upload.
What am I missing here or where is the "useable" image data stored?
Thanks and regards from Germany
Rob.
Here's a my code so far:
#include <iostream> #include <fstream> #include "libraw.h" int main() { LibRaw Proc; std::fstream myfile; // Define the parameters for libraw Proc.imgdata.params.shot_select = 0; // Select first RAW, in case there are more Proc.imgdata.params.use_auto_wb = 0; // Auto white-Balance Proc.imgdata.params.use_camera_wb = 1; // Use camera WB instead Proc.imgdata.params.output_color = 1; // [0-6] Output colorspace (0=raw, 1=sRGB, 2=Adobe, 3=Wide, 4=ProPhoto, 5=XYZ, 6=ACES) Proc.imgdata.params.user_qual = 3; // [0-10] Interpolation quality (linear, VNG, PPG, AHD, DCB, DHT, mod. AHD) Proc.imgdata.params.no_auto_bright = 1; // No automatic brightnes Proc.imgdata.params.output_bps = 16; // Output bits Proc.imgdata.params.adjust_maximum_thr = 0.75; // Proc.imgdata.params.aber[0] = 1.0; // Chromatic Abberation Red Proc.imgdata.params.aber[2] = 1.0; // Chromatic Abberation Blue Proc.imgdata.params.bright = 1.0; // Default Proc.imgdata.params.four_color_rgb = 1; // Switches on separate interpolations for two green components. Proc.imgdata.params.highlight = 1; // [0-9] Highlight mode (0=clip, 1=unclip, 2=blend, 3+=rebuild) // Set Gamma switch (Proc.imgdata.params.output_color) { case 1: //sRGB { Proc.imgdata.params.gamm[0] = 1 / 2.4; Proc.imgdata.params.gamm[1] = 12.92; } break; case 4: // ProPhoto { Proc.imgdata.params.gamm[0] = 1 / 1.8; Proc.imgdata.params.gamm[1] = 0.0; } break; default: { Proc.imgdata.params.gamm[0] = 1 / 1.0; Proc.imgdata.params.gamm[1] = 1.0; } } Proc.open_file("C:\\Bild.cr2"); Proc.unpack(); Proc.raw2image(); Proc.dcraw_process(); libraw_processed_image_t* image = Proc.dcraw_make_mem_image(); int rgb_pos = 0; myfile.open("C:\\test.csv"); myfile << ",,,Proc.imgdata.image[pos][],,,,image->data[rgb_pos++],,\n"; myfile << "ID,Row,Col,[R],[G],[B],[G2],[COLOR(r;c)],IMAGE[R],IMAGE[G],IMAGE[B],Raw_image[ID]\n"; for (int r = 0; r < 10 /*Proc.imgdata.sizes.height*/; r++) { for (int c = 0; c < 10 /*Proc.imgdata.sizes.width*/; c++) { unsigned pos = r * Proc.imgdata.sizes.width + c; myfile << pos << "," << r << "," << c << "," << Proc.imgdata.image[pos][0] << "," << Proc.imgdata.image[pos][1] << "," << Proc.imgdata.image[pos][2] << "," << Proc.imgdata.image[pos][3] << "," << Proc.COLOR(r, c) << "," << (int) image->data[rgb_pos++] << "," << (int) image->data[rgb_pos++] << "," << (int) image->data[rgb_pos++] << "," << (int) Proc.imgdata.rawdata.raw_image[pos] << "\n"; } } myfile.close(); std::cout << "Done." << std::endl; getchar(); return EXIT_SUCCESS; }
Attachment | Size |
---|---|
Data from my code | 43 KB |
Could you please ask more
Could you please ask more specific question?
imgdata.image is 16 bit/linear
image->data is 16 bit (output_bps set to 16) and gamma corrected (as far as I could understand from your code)
Both imgdata.image and image.data are cropped (by imgdata.sizes top/left_margin and width/height), while imgdata.rawimage.* is not cropped.
Also, imgrata.rawimage contains unaltered raw values, black level not subtracted
-- Alex Tutubalin @LibRaw LLC
Thanks for your fast response
Thanks for your fast response.
Well, I loaded the image as shown in my code. I know, PS/LR have some hidden adjustments.
The first 100x100 pixel in the image, listed in the xls, are supposed to be some kind of green. Leaves and treetops.
But all data listed is not near the RGB values for green. And furthermore these values are supposed be in a neare range of greens. But all listed data seem to jump all over the place.
I tried both, 8 and 16 bits for the output, and other different modes in the params. But nothing worked for me.
Yes, I know that the rawdata has a larger field then the final RGB values. This is just some kind of "test" to see a reason for that jumping values.
Regards.
Let's start from the
Let's start from the beginning.
Have you tried dcraw_emu sample? If so, are results 'expected' or not?
Same question with mem_image sample.....
-- Alex Tutubalin @LibRaw LLC
I tested both samples now.
I tested both samples now.
They work both, but have the same heavy yellow shift when opend in PS. (It's an old Canon 7D cr2 by the way.) The exported thumbnail had not.
And, even with the heavy yellow shift, the values do not match... In 8 and 16 bit mode....
The first pixel of the ppm file in PS has RGB(54, 64, 14).
The first pixel of my xls has
RGBG2(542,1052,418,874) from .imgdata.image[pos][], or
RGB(22,34,18) from image->data[]
Regards.
Could you please share the
Could you please share the sample file?
-- Alex Tutubalin @LibRaw LLC
And also:
And also:
data field in libraw_processed_image_t is 'unsigned char', while you're using 16-bit output.
So you dump 8-bit wise pieces, not real 16-bit values.
-- Alex Tutubalin @LibRaw LLC
Yes, I know, but even in 8
Yes, I know, but even in 8 bit mode it did not match. The values seem random to me.
You mean from the samples page? no, not yet. I'll try this and copy this code.
Regards.
Yes, please start from
Yes, please start from samples. If LibRaw's samples provides expected (visually correct) results that mean that the problem is not within LibRaw.....
-- Alex Tutubalin @LibRaw LLC
Samples are in samples/*.cpp
Samples are in samples/*.cpp in LibRaw distribution.
-- Alex Tutubalin @LibRaw LLC
BTW, in this piece of code
BTW, in this piece of code
Execution order is not specified (before C++17, AFAIK), that may explain garbage output.
-- Alex Tutubalin @LibRaw LLC
Which file do you mean? The
Which file do you mean? The Source or resulting images?
And I'm using C++17 in VS2019 Community.
RAW file, of course. It looks
RAW file, of course. It looks like I need to repeat your experiment with your input data.
-- Alex Tutubalin @LibRaw LLC
Sure, here you are:
Sure, here you are:
https://filebin.net/jw2qi5a46ybu5cny/Bild.cr2?t=expg9qj0
Regards.
Thanks.
Thanks.
I've added this to the mem_image sample:
just after these lines:
Output: PIX0: image: 1603/2064/330 mem_image: 54/64/14
The last triple is similar with your Photoshop numbers. So, it looks like your printing code is wrong.
Yellow cast is because Daylight WB is used (unless use_camera_wb is not set)
-- Alex Tutubalin @LibRaw LLC
Thank you very much!!!!
Thank you very much!!!!
So the .image->data[] is the final RGB array, with the selected WB.
But, then I still don't get what imgdata.image[][] is for?
To wich of these fields do I have to apply my exposure compensation "pixel *= 2^EV"?
Or, in other words, wich of these two fileds do I have to apply my processing?
Regards.
imgdata.image[] is processing
imgdata.image[] is processing array. After dcraw_process() it contains 16-bit linear data in [0..2] components and some garbabe in [3]
To implement exposure correction one may use params settings as described in library manual
-- Alex Tutubalin @LibRaw LLC
Also I've modified your
Also I've modified your sample with commenting out params settings section, from
to (including) custom gamma section.
After that, 1st line of output is:
Same 54,64,14, as expected (if compiled with -std=c++17)
-- Alex Tutubalin @LibRaw LLC
Ahh, thanks.
Ahh, thanks.
So, I assume I use the wrong settings.... When I just use the camera WB, I should get the same as PS with camera WB, right?
Can you help me with the first RGBG values? What are they for then?
Regards.
>>> Can you help me with the
>>> Can you help me with the first RGBG values? What are they for then?
Sorry, could not understand this question.
-- Alex Tutubalin @LibRaw LLC
Sorry, you allready did. But
Sorry, you allready did. But it did not show up on the page. :)
imgdata.image[] is processing
imgdata.image[] is processing array. After dcraw_process() it contains 16-bit linear data in [0..2] components and some garbabe in [3]
To implement exposure correction one may use params settings as described in library manual
-- Alex Tutubalin
Yes, I know there are some processing tools alredy...
Exposure was just an example. And I allready found other programs using LibRaw for opening raws for postprocessing. But I couldn't figure out wich data they use to process yet. Because using the final RGB data gives just limited processing possibilities. That was the reason for extracting all these values to an xls.
Or in other words to make it maybe more clear for me:
When I use the PS/LR sliders for exposre, shadows, highlights, sharpness, etc, which is the "corresponding LibRaw data" they "would" use for processing? Does that question make sense to you? Do these sliders use the final RGB values you helped me with, or do they use other data, like the .imgdata.image?
Regards.
Adobe uses own raw processing
Adobe uses own raw processing engine, different from LibRaw. There is no known rule(s) to convert Adobe sliders into LibRaw's imgdata.params
Also, I do not think that altering imgdata.image values without some knowledge of LibRaw::dcraw_process internals is a good idea. You may either study it (it is opensource, so it is possible), or create own raw processing.
LibRaw's dcraw_process() is very similar to dcraw.c processing, so you may find this link useful: https://ninedegreesbelow.com/files/dcraw-c-code-annotated-code.html
-- Alex Tutubalin @LibRaw LLC
Thank you!!!
Thank you!!!
Sure, they have their own engine. ;)
But childish me thought just use the expousre-algorithm 2^exp on the imgdata.image values and done...
Phew.... thats a lot of text. I'll have to read it in a quite moment.
But never the less you helped me a lot.
Thank you very much, Alex!!!