This is an example of how to implement an ImageOperation that converts image to grayscale using the transformImage() function.
#include "BWconversion.hpp"
#include <TransformImage.hpp>
template <typename PixelFormat>
public:
BWFunctor(
unsigned int bands) : m_bands(bands) {};
void operator()(PixelFormat* in, PixelFormat* out) {
for (unsigned int i = 0; i < m_bands; i++) {
out[i] = in[0];
}
}
private:
unsigned int m_bands;
};
template <typename PixelFormat>
public:
void operator()(PixelFormat* in, PixelFormat* out) {
PixelFormat color = 0.3 * in[0] + 0.59 * in[1] + 0.11 * in[2];
for (unsigned int i = 0; i < 3; i++) {
out[i] = color;
}
}
};
template <>
public:
typedef ValueTypeInfo<ValueTypeEnum::uint32>::Type uint32;
typedef ValueTypeInfo<ValueTypeEnum::uint8>::Type uint8;
void operator()(uint8* in, uint8* out) {
uint32 R = 77 * (in[0] << 8);
uint32 G = 151 * (in[1] << 8);
uint32 B = 25 * (in[2] << 8);
uint8 color = (R + G + B) >> 16;
for (unsigned int i = 0; i < 3; i++) {
out[i] = color;
}
}
};
if (sources[0]->getPixelData().colorSpace() == ColorSpaceEnum::RGB) {
switch(sources[0]->getPixelData().format()) {
#define FORMAT_DO_STH(T,U) transformImage<T>(sources[0], dest[0], BWFunctor_RGB<U>(), ROI, stamp);
case_ANY;
#undef FORMAT_DO_STH
}
} else {
switch(sources[0]->getPixelData().format()) {
#define FORMAT_DO_STH(T,U) transformImage<T>(sources[0], dest[0], \
BWFunctor<U>(sources[0]->getPixelData().numOfBands()), ROI, stamp);
case_ANY;
#undef FORMAT_DO_STH
}
}
}