02_grayscale.md 1.4 KB

Tutorial 02 - Grayscale Image Operations

After reading your image from a file into memory, you may want to optimize its histogram using gray value transforms. This tutorial will tech you the basics.

Pattern for gray value transforms

You can use the following pattern for your gray value transforms.

template <class P> void MyTransform(NICE::ImageT<P>& image)
{
	for(int x = 0; x < image.width(); x++) {
		for(int y=0; y < image.height(); y++) {
			P pixel = image.getPixelQuick(x, y);
			// Insert transform here	
			image.setPixelQuick(x, y, pixel);
		}
	}
}

Note that the get/setPixelQuick Methods don't perform boundary checks!

Optimization

If you have access to Intel IPP, you can use the overloaded operators provided in ImageOperators.h.

Another easy way to improve performance is adding a "parallel for" OpenMP compilation hint.

Gamma transforms

Gamma transforms are a little more complicated, because gray values are not always in the [0,1] range. For example, the Image and GrayImage16s use the full positive range of their data types while the FloatImage class can handle arbitrary ranges.

You can use the max() and min() methods on your image to find its specific range.

Histogram

NICE provides a Histogram class for 8-bit grayscale and color images (Image and ColorImage). To calculate an image's histogram, use the constructor:

NICE::Histogram histogram(image, 0, 256);