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.
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!
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 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.
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);