Add new comment

Maximum/saturation pixel value

I am having some trouble determining the maximum or saturation level for my pixels, I thought it was LibRaw::imgdata.color.maximum, however I find in some cases that after processing I have values bigger than this value. My code is below:

	// Create an image processor
	LibRaw iProcessor;
 
	// Open the file and read the metadata
	iProcessor.open_file(filename.c_str());
 
	size_t width = iProcessor.imgdata.sizes.width;
	size_t height = iProcessor.imgdata.sizes.height;
 
	// Unpack the image
	iProcessor.unpack();
 
 
	iProcessor.imgdata.params.user_qual=4; // DCB interpolation
	iProcessor.imgdata.params.output_color = 0; // Raw output
	//do no white balance
	iProcessor.imgdata.params.use_camera_wb = 0;
	iProcessor.imgdata.params.user_mul[0] = 1.0f;
	iProcessor.imgdata.params.user_mul[1] = 1.0f;
	iProcessor.imgdata.params.user_mul[2] = 1.0f;
	iProcessor.imgdata.params.user_mul[3] = 1.0f;
 
	//Process
	iProcessor.dcraw_process();
 
	//Copy the luminosity into a vector
	std::vector<unsigned short> data(width * height);
	unsigned int maxLuminosity = 0;
	for (size_t i = 0; i < data.size(); ++i)
	{
		unsigned int luminosity = ((unsigned int)iProcessor.imgdata.image[i][0] * 2 + (unsigned int)iProcessor.imgdata.image[i][1] * 3 + (unsigned int)iProcessor.imgdata.image[i][2])/6;
		data[i] = luminosity;
		maxLuminosity = luminosity > maxLuminosity ? luminosity : maxLuminosity;
		if (luminosity > iProcessor.imgdata.color.maximum)
			std::cout << "Pixel " << i << " has luminosity too high\n";
	}

If I break in my debugger where I do the std::cout, then I can see that individual pixel values are higher than iProcessor.imgdata.color.maximum.

Is there something I am doing wrong? The region where I am getting the higher values is probably overexposed in one or both of red and green ( it is a sunset picture). I have just spotted the highlight option, but this is set to 0, which I think should clip. Is this correct?

Forums: