Skip to content

Commit

Permalink
Merge pull request #413 from fedorov/412-fix-cielab-conversion
Browse files Browse the repository at this point in the history
BUG: fix RGB-CIELab conversion

Resolves #412
  • Loading branch information
fedorov authored Dec 28, 2020
2 parents b9b6510 + 235da0e commit 322da4c
Show file tree
Hide file tree
Showing 12 changed files with 744 additions and 224 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ cache:

before_script:
# Install ajv
- npm install ajv-cli -g
- npm install ajv-cli@3.3.0 -g
# Install dicom3tools
- wget --no-check-certificate http://slicer.kitware.com/midas3/download/item/270308/dicom3tools_macexe_1.00.snapshot.20161218101718.zip -O dicom3tools.zip
- tar zxf dicom3tools.zip
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ environment:
secure: 3+wBc5SxNqx3XjsY3EZ7afvQbLAWWcw30SPGK7q+QPA=
before_build:
# Install tools required to run DCMQI "doc" tests
- npm install ajv-cli -g
- npm install ajv-cli@3.3.0 -g
# Display infos
- cmake --version
# Downloads
Expand Down
4 changes: 2 additions & 2 deletions doc/examples/seg-example_multiple_segments.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"SegmentAlgorithmType": "SEMIAUTOMATIC",
"SegmentAlgorithmName": "SlicerEditor",
"recommendedDisplayRGBValue": [
221,
130,
220,
129,
101
]
}
Expand Down
2 changes: 1 addition & 1 deletion docker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ prereq.install_npm_packages: prereq.pull_dockcross
tar xf node-v6.9.5-linux-x64.tar.xz || true
# Install tools required to run DCMQI "doc" tests
cd $(ROOT_DIR) && \
$(TMP)/dockcross bash -c "export PATH=/work/build/node-v6.9.5-linux-x64/bin:$$PATH && sudo npm install ajv-cli -g"
$(TMP)/dockcross bash -c "export PATH=/work/build/node-v6.9.5-linux-x64/bin:$$PATH && sudo npm install ajv-cli@3.3.0 -g"

# Configure, build and package
dcmqi.generate_package: prereq.pull_dockcross
Expand Down
103 changes: 103 additions & 0 deletions include/dcmqi/ColorUtilities.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#ifndef DCMQI_COLORUTILITIES_H
#define DCMQI_COLORUTILITIES_H


using namespace std;

namespace dcmqi {

class ColorUtilities {
public:

static void getIntegerScaledCIELabFromCIELab(int &sL, int &sA, int &sB, float L, float A, float B);

/**
* <p>Convert 16 bit fractional integer scaled CIELab values used in ICC profiles and DICOM to floating point.</p>
*
* <p>See ICC v4.3 Tables 12 and 13, and DICOM PS 3.3 C.10.7.1.1.</p>
*
* @param cieLabScaled array of length 3 containing 16 bit scaled L*,a*,b* values from 0 to 65535
* return array of length 3 containing L*,a*,b* values with L* from 0.0 to 100.0, and a* and b* from -128.0 to +127.0
*/
static void getCIELabPCSFromIntegerScaledCIELabPCS(float &L, float &A, float &B, int sL, int sA, int sB);

/**
* <p>Convert CIEXYZ to CIE 1976 L*, a*, b*.</p>
*
* @see <a href="http://en.wikipedia.org/wiki/Lab_color_space#CIELAB-CIEXYZ_conversions">Wikipedia CIELAB-CIEXYZ_conversions</a>
*
* @param cieXYZ array of length 3 containing X,Y,Z values
* return array of length 3 containing L*,a*,b* values
*/
static void getCIELabFromXYZ(float &L, float &A, float &B, float X, float Y, float Z);

/**
* <p>Convert CIE 1976 L*, a*, b* to CIEXYZ.</p>
*
* @see <a href="http://en.wikipedia.org/wiki/Lab_color_space#CIELAB-CIEXYZ_conversions">Wikipedia CIELAB-CIEXYZ_conversions</a>
*
* @param cieLab array of length 3 containing L*,a*,b* values
* return array of length 3 containing X,Y,Z values
*/
static void getCIEXYZFromLAB(float &X, float &Y, float &Z, float L, float A, float B);

/**
* <p>Convert RGB values in sRGB to CIEXYZ in ICC PCS.</p>
*
* <p>SRGB Observer = 2°, Illuminant = D65, XYZ PCS Illuminant = D50.</p>
*
* @see <a href="http://en.wikipedia.org/wiki/SRGB#The_reverse_transformation">Wikipedia SRGB Reverse Transformation</a>
*
* @param rgb array of length 3 containing R,G,B values each from 0 to 255
* return array of length 3 containing X,Y,Z values
*/
static void getCIEXYZPCSFromSRGB(float &X, float &Y, float &Z, int R, int G, int B);

/**
* <p>Convert CIEXYZ in ICC PCS to RGB values in sRGB.</p>
*
* <p>SRGB Observer = 2°, Illuminant = D65, XYZ PCS Illuminant = D50.</p>
*
* @see <a href="http://en.wikipedia.org/wiki/SRGB#The_forward_transformation_.28CIE_xyY_or_CIE_XYZ_to_sRGB.29">Wikipedia SRGB Forward Transformation</a>
*
* @param cieXYZ array of length 3 containing X,Y,Z values
* return array of length 3 containing R,G,B values each from 0 to 255
*/
static void getSRGBFromCIEXYZPCS(int &R, int &G, int &B, float X, float Y, float Z);

/**
* <p>Convert RGB values in sRGB to CIELab in ICC PCS.</p>
*
* @param rgb array of length 3 containing R,G,B values each from 0 to 255
* return array of length 3 containing L*,a*,b* values
*/
static void getCIELabPCSFromSRGB(float &L, float &A, float &B, int r, int g, int b);

/**
* <p>Convert RGB values in sRGB to 16 bit fractional integer scaled CIELab in ICC PCS.</p>
*
* @param rgb array of length 3 containing R,G,B values each from 0 to 255
* return array of length 3 containing L*,a*,b* values each from 0 to 65535
*/
static void getIntegerScaledCIELabPCSFromSRGB(int &sL, int &sA, int &sB, int r, int g, int b);

/**
* <p>Convert CIELab in ICC PCS to RGB values in sRGB.</p>
*
* @param cieLab array of length 3 containing L*,a*,b* values
* return array of length 3 containing R,G,B values each from 0 to 255
*/
static void getSRGBFromCIELabPCS(int &r, int &g, int &b, float L, float A, float B);

/**
* <p>Convert 16 bit fractional integer scaled CIELab in ICC PCS to RGB values in sRGB.</p>
*
* @param cieLabScaled array of length 3 containing L*,a*,b* values each from 0 to 65535
* return array of length 3 containing R,G,B values each from 0 to 255
*/
static void getSRGBFromIntegerScaledCIELabPCS(int &sr, int &sg, int &sb, int sL, int sA, int sB);

};
}

#endif // DCMQI_COLORUTILITIES_H
7 changes: 0 additions & 7 deletions include/dcmqi/Helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,6 @@ namespace dcmqi {

static string toString(const unsigned int& value);

static float *getCIEXYZFromRGB(unsigned *rgb, float *cieXYZ);
static float *getCIEXYZFromCIELab(float *cieLab, float *cieXYZ);
static float *getCIELabFromCIEXYZ(float *cieXYZ, float *cieLab);
static float *getCIELabFromIntegerScaledCIELab(unsigned *cieLabScaled, float *cieLab);
static unsigned *getIntegerScaledCIELabFromCIELab(float *cieLab, unsigned *cieLabScaled);
static unsigned *getRGBFromCIEXYZ(float *cieXYZ, unsigned *rgb);

static CodeSequenceMacro stringToCodeSequenceMacro(string str);
static DSRCodedEntryValue stringToDSRCodedEntryValue(string str);

Expand Down
2 changes: 2 additions & 0 deletions libsrc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ set(HDRS
${INCLUDE_DIR}/ImageSEGConverter.h
${INCLUDE_DIR}/ParaMapConverter
${INCLUDE_DIR}/Helper.h
${INCLUDE_DIR}/ColorUtilities.h
${INCLUDE_DIR}/JSONMetaInformationHandlerBase.h
${INCLUDE_DIR}/JSONParametricMapMetaInformationHandler.h
${INCLUDE_DIR}/JSONSegmentationMetaInformationHandler.h
Expand All @@ -26,6 +27,7 @@ set(SRCS
ImageSEGConverter.cpp
ParaMapConverter.cpp
Helper.cpp
ColorUtilities.cpp
JSONMetaInformationHandlerBase.cpp
JSONParametricMapMetaInformationHandler.cpp
JSONSegmentationMetaInformationHandler.cpp
Expand Down
Loading

0 comments on commit 322da4c

Please sign in to comment.