Decode CR2 with Magick++
Posted: 2017-08-06T14:29:38-07:00
I'm trying to decode a raw CR2 image with Magick++ but am getting some strange results. I want to get the RGB color values for each pixel so I can loop through them and do some analysis.
To decode the CR2 I'm using:
This is just an example to get the first pixel in the image, and I will modify the code to loop through the rest once I can get this working.
For image.cr2 the program outputs:
If I modify the code to read the camera's encoded jpg, I get:
The RGB values appear correct for the first pixel in the image, so I'm not sure what Magick++ is doing to decode the CR2 differently. Could this be related to the Bayer filter demosaicing?
Edit: I'm using version 7.0.6.
To decode the CR2 I'm using:
Code: Select all
Image img;
img.read("cr2:image.CR2");
Pixels view(img);
Quantum *pixels = view.get(0,0,1,1);
cout << "R: " << 255 * QuantumScale * *pixels++ << endl;
cout << "G: " << 255 * QuantumScale * *pixels++ << endl;
cout << "B: " << 255 * QuantumScale * *pixels++ << endl;
For image.cr2 the program outputs:
Code: Select all
R: 5.43191
G: 0
B: 51.2179
Code: Select all
R: 0
G: 0
B: 2
Edit: I'm using version 7.0.6.