HDR Tone Mapping with CUDA 5

In this example, for the sake of learning, we are going to butcher some great images. Let's describe the problem first.We are going to take some HDR images and modify their luminosity to lighten them. We could also darken the images, or apply changes only to parts of the images,

C++ (117.3 MB)
 
 
 
 
 
(0)
2,781 times
Add to favorites
3/8/2013
E-mail Twitter del.icio.us Digg Facebook

Solution explorer

C++
//-----------------------------------------------------------------------------
// File: HdrTone.h
//
// Desc: HDR Tone Mapping.
//		 Full description of HDR tone mapping is provided in the HdrTone.cu file.
//
//-----------------------------------------------------------------------------

#pragma once

namespace Bisque
{
	using std::string;
	using std::vector;

	// class HdrTone
	class HdrTone
	{
	public:
		HdrTone(void);
		~HdrTone(void);

		void ApplyFilter(const string& imagePath, const string& outputPath);

	private:

		// struct HostData
		//		Used on the CPU host
		//		RGB channels, number of rows and columns.
		//		This is a temporary data we need to initialize kernel.
		struct HostData
		{
			vector<float>	red;
			vector<float>	green;
			vector<float>	blue;
			size_t			rows;
			size_t			cols;
			size_t			numPixels;
		};

		// struct xyY
		//		Data is used on the GPU device
		//		Y = Luminescence (cd/m2)   xy = chromaticity co-ordinates (spectral locus) 
		//		http://en.wikipedia.org/wiki/CIE_1931_color_space#CIE_xy_chromaticity_diagram_and_the_CIE_xyY_color_space
		struct DeviceData
		{
			float*			red;						// input for the conversion from rgb to xyY
			float*			green;						// input for the conversion from rgb to xyY
			float*			blue;						// input for the conversion from rgb to xyY
			float*			x;							// component of xyY
			float*			y;							// component of xyY
			float*			luminance;					// Y component of xyY
			unsigned int*	histogram;					// histogram of luminance values
			unsigned int*	cdf;						// luminance cumulative distribution, calculated from histogram
			float*			normalizedCdf;				// normalized cdf
			float*			lumMin;						// luminance min value
			float*			lumMax;						// luminance max value
			float*			lumRange;					// luminance range:max - min
		};

	private:
		void ComputeCDF				();
		void rgb2xyY				(const HostData& hdr);
		void LoadHdrImage			(const string& imagePath, HostData& hdr);
		void PostProcess			();
		void SaveImage				(const string& imagePath);

		// CPU verification
		void VerifyGpuComputation	();

	private:
		HostData		m_host;							// helper structure for items used on the CPU
		DeviceData		m_device;						// helper structure to allocate memory on GPU

		static const unsigned int NumBins = 1024;		// number of bins for luminocity cdf histogram.
														// NOTE that we hard-code 1024 in many places in kernels.
														// Do not just change this number without re-factoring kernel code.
	};
}