14#ifndef GDCMIMAGECHANGEPHOTOMETRICINTERPRETATION_H
15#define GDCMIMAGECHANGEPHOTOMETRICINTERPRETATION_H
45 static void RGB2YBR(T ybr[3],
const T rgb[3],
unsigned short storedbits = 8);
47 static void YBR2RGB(T rgb[3],
const T ybr[3],
unsigned short storedbits = 8);
67 assert( std::numeric_limits<T>::min() == 0 );
68 return v < 0 ? 0 : (v > std::numeric_limits<T>::max() ? std::numeric_limits<T>::max() : v);
79 const double R = rgb[0];
80 const double G = rgb[1];
81 const double B = rgb[2];
82 assert( storedbits <=
sizeof(T) * 8 );
83 const int halffullscale = 1 << (storedbits - 1);
84 const int Y =
Round( 0.299 * R + 0.587 * G + 0.114 * B );
85 const int CB =
Round((-0.299 * R - 0.587 * G + 0.886 * B)/1.772 + halffullscale);
86 const int CR =
Round(( 0.701 * R - 0.587 * G - 0.114 * B)/1.402 + halffullscale);
87 ybr[0] = Clamp<T>(Y );
88 ybr[1] = Clamp<T>(CB);
89 ybr[2] = Clamp<T>(CR);
95 const double Y = ybr[0];
96 const double Cb = ybr[1];
97 const double Cr = ybr[2];
98 assert( storedbits <=
sizeof(T) * 8 );
99 const int halffullscale = 1 << (storedbits - 1);
100 const int R =
Round(Y + 1.402 * (Cr-halffullscale) );
101 const int G =
Round(Y -( 0.114 * 1.772 * (Cb-halffullscale) + 0.299 * 1.402 * (Cr-halffullscale))/0.587);
102 const int B =
Round(Y + 1.772 * (Cb-halffullscale) );
103 rgb[0] = Clamp<T>(R);
104 rgb[1] = Clamp<T>(G);
105 rgb[2] = Clamp<T>(B);
ImageChangePhotometricInterpretation class.
Definition gdcmImageChangePhotometricInterpretation.h:30
static void RGB2YBR(T ybr[3], const T rgb[3], unsigned short storedbits=8)
Definition gdcmImageChangePhotometricInterpretation.h:73
static void YBR2RGB(T rgb[3], const T ybr[3], unsigned short storedbits=8)
Definition gdcmImageChangePhotometricInterpretation.h:93
const PhotometricInterpretation & GetPhotometricInterpretation() const
Definition gdcmImageChangePhotometricInterpretation.h:37
~ImageChangePhotometricInterpretation()=default
ImageChangePhotometricInterpretation()
Definition gdcmImageChangePhotometricInterpretation.h:32
void SetPhotometricInterpretation(PhotometricInterpretation const &pi)
Set/Get requested PhotometricInterpretation.
Definition gdcmImageChangePhotometricInterpretation.h:36
ImageToImageFilter class.
Definition gdcmImageToImageFilter.h:28
Class to represent an PhotometricInterpretation.
Definition gdcmPhotometricInterpretation.h:29
#define GDCM_EXPORT
Definition gdcmWin32.h:34
static T Clamp(int v)
Definition gdcmImageChangePhotometricInterpretation.h:65
static int Round(T x)
Definition gdcmImageChangePhotometricInterpretation.h:59