14 #ifndef GDCMSURFACEHELPER_H
15 #define GDCMSURFACEHELPER_H
46 template <
typename T,
typename U>
47 static unsigned short RGBToRecommendedDisplayGrayscale(
const std::vector<T> & RGB,
48 const U rangeMax = 255);
60 template <
typename T,
typename U>
61 static ColorArray RGBToRecommendedDisplayCIELab(
const std::vector<T> & RGB,
62 const U rangeMax = 255);
74 template <
typename T,
typename U>
75 static std::vector<T> RecommendedDisplayCIELabToRGB(
const ColorArray & CIELab,
76 const U rangeMax = 255);
88 static std::vector<float> RecommendedDisplayCIELabToRGB(
const ColorArray & CIELab,
89 const U rangeMax = 255);
93 static std::vector< float > RGBToXYZ(
const std::vector<float> & RGB);
95 static std::vector< float > XYZToRGB(
const std::vector<float> & XYZ);
97 static std::vector< float > XYZToCIELab(
const std::vector<float> & XYZ);
99 static std::vector< float > CIELabToXYZ(
const std::vector<float> & CIELab);
102 template <
typename T,
typename U>
106 assert(RGB.size() > 2);
108 unsigned short Grayscale = 0;
110 const float inverseRangeMax = 1. / (float) rangeMax;
113 Grayscale = (
unsigned short) ((0.2989 * RGB[0] + 0.5870 * RGB[1] + 0.1140 * RGB[2])
120 template <
typename T,
typename U>
124 assert(RGB.size() > 2);
127 std::vector<float> tmp(3);
130 const float inverseRangeMax = 1. / (float) rangeMax;
131 tmp[0] = (float) (RGB[0] * inverseRangeMax);
132 tmp[1] = (float) (RGB[1] * inverseRangeMax);
133 tmp[2] = (float) (RGB[2] * inverseRangeMax);
135 tmp = SurfaceHelper::XYZToCIELab( SurfaceHelper::RGBToXYZ( tmp ) );
139 CIELab[0] = (
unsigned short) ( 0xFFFF * (tmp[0]*0.01));
140 if(tmp[1] >= -128 && tmp[1] <= 0)
142 CIELab[1] = (
unsigned short)(((
float)(0x8080)/128.0)*tmp[1] + ((float)0x8080));
144 else if(tmp[1] <= 127 && tmp[1] > 0)
146 CIELab[1] = (
unsigned short)(((
float)(0xFFFF - 0x8080)/127.0)*tmp[1] + (float)(0x8080));
148 if(tmp[2] >= -128 && tmp[2] <= 0)
150 CIELab[2] = (
unsigned short)(((
float)0x8080/128.0)*tmp[2] + ((float)0x8080));
152 else if(tmp[2] <= 127 && tmp[2] > 0)
154 CIELab[2] = (
unsigned short)(((
float)(0xFFFF - 0x8080)/127.0)*tmp[2] + (float)(0x8080));
160 template <
typename T,
typename U>
164 assert(CIELab.size() > 2);
166 std::vector<T> RGB(3);
167 std::vector<float> tmp(3);
171 tmp[0] = 100.0*CIELab[0] /(float)(0xFFFF);
172 if(CIELab[1] >= 0x0000 && CIELab[1] <= 0x8080)
174 tmp[1] = (float)(((CIELab[1] - 0x8080) * 128.0)/(float)0x8080);
176 else if(CIELab[1] <= 0xFFFF && CIELab[1] > 0x8080)
178 tmp[1] = (float)((CIELab[1]-0x8080)*127.0 / (float)(0xFFFF - 0x8080));
180 if(CIELab[2] >= 0x0000 && CIELab[2] <= 0x8080)
182 tmp[2] = (float)(((CIELab[2] - 0x8080) * 128.0)/(float)0x8080);
184 else if(CIELab[2] <= 0xFFFF && CIELab[2] > 0x8080)
186 tmp[2] = (float)((CIELab[2]-0x8080)*127.0 / (float)(0XFFFF - 0x8080));
189 tmp = SurfaceHelper::XYZToRGB( SurfaceHelper::CIELabToXYZ( tmp ) );
192 RGB[0] = (T) (tmp[0] * rangeMax);
193 RGB[1] = (T) (tmp[1] * rangeMax);
194 RGB[2] = (T) (tmp[2] * rangeMax);
199 template <
typename U>
203 return RecommendedDisplayCIELabToRGB<float>(CIELab, rangeMax);
208 #endif // GDCMSURFACEHELPER_H
SurfaceHelper Helper class for Surface object.
Definition: gdcmSurfaceHelper.h:29
#define GDCM_EXPORT
Definition: gdcmWin32.h:34
static unsigned short RGBToRecommendedDisplayGrayscale(const std::vector< T > &RGB, const U rangeMax=255)
Convert a RGB color into DICOM grayscale (ready to write).
Definition: gdcmSurfaceHelper.h:103
static ColorArray RGBToRecommendedDisplayCIELab(const std::vector< T > &RGB, const U rangeMax=255)
Convert a RGB color into DICOM CIE-Lab (ready to write).
Definition: gdcmSurfaceHelper.h:121
std::vector< unsigned short > ColorArray
Definition: gdcmSurfaceHelper.h:33
static std::vector< T > RecommendedDisplayCIELabToRGB(const ColorArray &CIELab, const U rangeMax=255)
Convert a DICOM CIE-Lab (after reading) color into RGB.
Definition: gdcmSurfaceHelper.h:161