1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
#ifndef NATIVEINTENSITYMAPPING_H
#define NATIVEINTENSITYMAPPING_H
/**
* @brief The AbstractNativeIntensityMapping class
* This class is the parent in a hierarchy of classes describing a mapping from
* the internal datatype to the 'native' datatype. These mappings are used
* in cases where the image is represented internally as a short type, although
* the underlying data is in the reals.
*/
class AbstractNativeIntensityMapping
{
public:
virtual double operator() (double g) const = 0;
virtual double MapGradientMagnitudeToNative(double g) const = 0;
virtual double MapInternalToNative(double g) const = 0;
virtual double MapNativeToInternal(double g) const = 0;
virtual double GetScale() const = 0;
virtual double GetShift() const = 0;
};
class LinearInternalToNativeIntensityMapping : public AbstractNativeIntensityMapping
{
public:
typedef LinearInternalToNativeIntensityMapping Self;
double operator() (double g) const
{ return MapInternalToNative(g); }
double MapGradientMagnitudeToNative(double internalGM) const
{ return internalGM * scale; }
double MapInternalToNative(double internal) const
{ return internal * scale + shift; }
double MapNativeToInternal(double native) const
{ return (native - shift) / scale; }
virtual double GetScale() const { return scale; }
virtual double GetShift() const { return shift; }
LinearInternalToNativeIntensityMapping() : scale(1.0), shift(0.0) {}
LinearInternalToNativeIntensityMapping(double a, double b) : scale(a), shift(b) {}
bool operator != (const Self &other) const
{ return scale != other.scale || shift != other.shift; }
protected:
double scale;
double shift;
};
class SpeedImageInternalToNativeIntensityMapping
: public LinearInternalToNativeIntensityMapping
{
public:
typedef SpeedImageInternalToNativeIntensityMapping Self;
SpeedImageInternalToNativeIntensityMapping()
{
// Map the range of short to -1 : 1
short smin = -0x7fff, smax = 0x7fff;
this->scale = 2.0 / ((int) smax - (int) smin);
this->shift = 0.0;
}
bool operator != (const Self &other) const { return false; }
};
class IdentityInternalToNativeIntensityMapping : public AbstractNativeIntensityMapping
{
public:
typedef IdentityInternalToNativeIntensityMapping Self;
double operator() (double g) const
{ return g; }
double MapGradientMagnitudeToNative(double internalGM) const
{ return internalGM; }
double MapInternalToNative(double internal) const
{ return internal; }
double MapNativeToInternal(double native) const
{ return native; }
virtual double GetScale() const { return 1; }
virtual double GetShift() const { return 0; }
bool operator != (const Self &other) const { return false; }
};
#endif // NATIVEINTENSITYMAPPING_H
|