It seems that nikons own tool and photoshop has the option to open the image as they was taken.
but using libraws dcraw processor I cant figure this out.
here is my implementation.
CV_EXPORTS_W int load_image(const char * path, cv::Mat & output)
{
LibRaw RawProcessor;
int ret;
#define imgD RawProcessor.imgdata
imgD.params.use_camera_wb = 1;
imgD.params.use_auto_wb = 0;
if ((ret = RawProcessor.open_file(path)) != LIBRAW_SUCCESS)
{
fprintf(stderr, path, libraw_strerror(ret));
return -1;
}
if ((ret = RawProcessor.unpack()) != LIBRAW_SUCCESS)
{
return -1;
}
int check = RawProcessor.dcraw_process();
libraw_processed_image_t *image_ptr = RawProcessor.dcraw_make_mem_image(&check);
output = cv::Mat(cv::Size(image_ptr->width, image_ptr->height), CV_8UC3, image_ptr->data, cv::Mat::AUTO_STEP);
cv::cvtColor(output, output, 4);
}
Updated with an image to show what I am talking about: The images are being normalized somehow. If the original image contains a large area of light matrial the overall image becomes more dark. I want to be able to just read the raw image data and normalize or handle it my own way in opencv.
update
Based on comments I got the brightness adjusted but a problem now arize with the pixel color values, best seen here:
The image on the left is the result of libraw and the right one is viewnx. There seem to be some noise colors in the libraw image.