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);
124 assert(RGB.size() > 2);
127 std::vector<float> tmp(3);
130 const float inverseRangeMax = 1.0f / (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.01f));
140 if(tmp[1] >= -128 && tmp[1] <= 0)
142 CIELab[1] = (
unsigned short)(((
float)(0x8080)/128.0f)*tmp[1] + ((float)0x8080));
144 else if(tmp[1] <= 127 && tmp[1] > 0)
146 CIELab[1] = (
unsigned short)(((
float)(0xFFFF - 0x8080)/127.0f)*tmp[1] + (float)(0x8080));
148 if(tmp[2] >= -128 && tmp[2] <= 0)
150 CIELab[2] = (
unsigned short)(((
float)0x8080/128.0f)*tmp[2] + ((
float)0x8080));
152 else if(tmp[2] <= 127 && tmp[2] > 0)
154 CIELab[2] = (
unsigned short)(((
float)(0xFFFF - 0x8080)/127.0f)*tmp[2] + (float)(0x8080));
164 assert(CIELab.size() > 2);
166 std::vector<T> RGB(3);
167 std::vector<float> tmp(3);
171 tmp[0] = 100.0f*CIELab[0] /(float)(0xFFFF);
172 if(CIELab[1] <= 0x8080)
174 tmp[1] = (float)(((CIELab[1] - 0x8080) * 128.0f)/(
float)0x8080);
178 tmp[1] = (float)((CIELab[1]-0x8080)*127.0f / (float)(0xFFFF - 0x8080));
180 if(CIELab[2] <= 0x8080)
182 tmp[2] = (float)(((CIELab[2] - 0x8080) * 128.0f)/(
float)0x8080);
186 tmp[2] = (float)((CIELab[2]-0x8080)*127.0f / (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);
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 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
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