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++
// program.cpp
//
// Main entry point into the application.
//

#include "stdafx.h"
#include "GrayIntensity.h"
#include "GaussianBlur.h"
#include "HdrTone.h"

using std::cout;
using std::cerr;
using std::endl;
using std::exception;
using std::string;

using namespace Bisque;

// Main entry into the application
int main(int argc, char** argv)
{
#if _DEBUG
	_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif

	// Test input parameters: required path to 2 images, original and modified.
	string imagePath;
	string outputPath;

	if (argc > 2)
	{
		imagePath = string(argv[1]);
		outputPath = string(argv[2]);
	}
	else
	{
		cerr << "Please provide input and output image files as arguments to this application." << endl;
		exit(EXIT_FAILURE);
	}

	// Set device and display properties
	int numDevices;
	cudaGetDeviceCount(&numDevices);

	if (numDevices == 0)
	{
		cerr << "ERROR: Your system does not have CUDA." << endl;
		exit(EXIT_FAILURE);
	}

	const int deviceId = 0;
	cudaSetDevice(deviceId);

	cudaDeviceProp p;
	cudaError hr = cudaGetDeviceProperties(&p, deviceId);

	if (hr == cudaSuccess)
	{
		cout << "Using device: " << deviceId << endl;
		cout << "   Name:                    " << p.name << endl;
		cout << "   Compute version:         " << p.major << "." << p.minor << endl;
		cout << "   Global memory:           " << p.totalGlobalMem / static_cast<float>(1024 * 1024) << " mb" << endl;
		cout << "   Const memory:            " << p.totalConstMem / static_cast<float>(1024) << " kb" << endl;
		cout << "   L2 cache size:           " << p.l2CacheSize / static_cast<float>(1024) << " kb" << endl;
		cout << "   Clock rate:              " << p.clockRate / 1000.f << " mhz"<< endl;
		cout << "   Timeout enabled:         " << (p.kernelExecTimeoutEnabled == 1 ? "true" : "false") << endl;
		cout << "   Multiprocessors:         " << p.multiProcessorCount << endl;
		cout << "   Max grid size:           " << p.maxGridSize[0] << " : " << p.maxGridSize[1] << " : " << p.maxGridSize[2] << endl;
		cout << "   Max threads per SM:      " << p.maxThreadsPerMultiProcessor << endl;
		cout << "   Max threads per block:   " << p.maxThreadsPerBlock << endl;
		cout << "   Registers per block:     " << p.regsPerBlock << endl;
		cout << "   Shared memory per block: " << p.sharedMemPerBlock / static_cast<float>(1024) << " kb" << endl;
		cout << "   Memory bus width:        " << p.memoryBusWidth << " bits" << endl;
		cout << "   Memory clock rate:       " << p.memoryClockRate / 1000.f << " mhz" << endl;
		cout << endl;
	}

	// Do something!
	GrayIntensity	gray;
	GaussianBlur	gaussian;
	HdrTone			hdr;

	try
	{
		//gray.ApplyFilter		(imagePath, outputPath);
		//gaussian.ApplyFilter	(imagePath, outputPath);
		hdr.ApplyFilter			(imagePath, outputPath);
	}
	catch(exception& e)
	{
		cerr << endl << "ERROR: " << e.what() << endl;
		exit(EXIT_FAILURE);
	}

	cout << "Done!" << endl << endl;
	return 0;
}