Changeset 2205


Ignore:
Timestamp:
Jan 6, 2013, 10:27:08 PM (10 years ago)
Author:
sam
Message:

color: unit test data for the CIEDE2000 color-difference formula.

Location:
trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/image/color/cie1931.cpp

    r2203 r2205  
    2727float Color::DistanceCIEDE2000(vec3 lab1, vec3 lab2)
    2828{
     29    float const pi = 3.141592653589793f;
     30
    2931    float const deg2rad = 6.28318530718f / 360.f;
    3032    float const rad2deg = 360.f / 6.28318530718f;
     
    4850    float Cp_ = 0.5f * (Cp1 + Cp2);
    4951
    50     float hp1 = fmod(atan2(lab1.z, ap1) * rad2deg, 360.f);
    51     if (hp1 < 0.f)
    52         hp1 += 360.f;
    53     float hp2 = fmod(atan2(lab2.z, ap2) * rad2deg, 360.f);
    54     if (hp2 < 0.f)
    55         hp2 += 360.f;
    56     float dhp;
    57     if (abs(hp1 - hp2) <= 180.f)
     52    float hp1 = fmod(atan2(lab1.z, ap1) + 2.f * pi, 2.f * pi);
     53    float hp2 = fmod(atan2(lab2.z, ap2) + 2.f * pi, 2.f * pi);
     54    float dhp; /* -pi .. pi */
     55    if (abs(hp1 - hp2) <= pi)
    5856        dhp = hp2 - hp1;
    5957    else if (hp2 <= hp1)
    60         dhp = hp2 - hp1 + 360.f;
     58        dhp = hp2 - hp1 + 2.f * pi;
    6159    else
    62         dhp = hp2 - hp1 - 360.f;
    63     float dHp = 2.f * sqrt(Cp1 * Cp2) * sin(dhp / 2.f * deg2rad);
    64     float Hp_;
    65     if (abs(hp1 - hp2) > 180.f)
    66         Hp_ = 0.5f * (hp1 + hp2 + 360.f);
     60        dhp = hp2 - hp1 - 2.f * pi;
     61    float dHp = 2.f * sqrt(Cp1 * Cp2) * sin(dhp / 2.f);
     62    float Hp_; /* half-angle 0 .. 360 */
     63    if (!(Cp1 * Cp2))
     64        Hp_ = hp1 + hp2;
     65    else if (abs(hp1 - hp2) > pi && hp1 + hp2 < 2.f * pi)
     66        Hp_ = 0.5f * (hp1 + hp2) + pi;
     67    else if (abs(hp1 - hp2) > 180.f)
     68        Hp_ = 0.5f * (hp1 + hp2) - pi;
    6769    else
    6870        Hp_ = 0.5f * (hp1 + hp2);
    6971
    70     float T = 1.f - 0.17f * cos((Hp_ - 30.f) * deg2rad)
    71                   + 0.24f * cos(2 * Hp_ * deg2rad)
    72                   + 0.32f * cos((3.f * Hp_ + 6.f) * deg2rad)
    73                   - 0.20f * cos((4.f * Hp_ - 63.f) * deg2rad);
     72    float T = 1.f - 0.17f * cos(Hp_ - pi / 6.f)
     73                  + 0.24f * cos(2.f * Hp_)
     74                  + 0.32f * cos(3.f * Hp_ + pi / 30.f)
     75                  - 0.20f * cos(4.f * Hp_ - 0.35f * pi);
    7476    float SL = 1.f + 0.015f * (L_ - 50) * (L_ - 50)
    7577                            / sqrt(20.f + (L_ - 50) * (L_ - 50));
     
    7779    float SH = 1.f + 0.015f * Cp_ * T;
    7880    float RT = -2.f * sqrt(pow(Cp_, 7.f) / (pow(Cp_, 7.f) + pow(25.f, 7.f)))
    79                     * sin(60.f * deg2rad * exp(-pow((Hp_ - 275.f) / 25.f, 2.f)));
     81                    * sin(60.f * deg2rad * exp(-pow((Hp_ * rad2deg - 275.f) / 25.f, 2.f)));
    8082
    8183    dLp /= SL;
  • trunk/test/Makefile.am

    r2109 r2205  
    2323    unit/vector.cpp unit/matrix.cpp unit/half.cpp unit/trig.cpp \
    2424    unit/build.cpp unit/real.cpp unit/image.cpp unit/quat.cpp unit/cmplx.cpp \
    25     unit/array.cpp unit/rotation.cpp unit/string.cpp unit/map.cpp
     25    unit/array.cpp unit/rotation.cpp unit/string.cpp unit/map.cpp \
     26    unit/color.cpp
    2627testsuite_CPPFLAGS = @LOL_CFLAGS@
    2728testsuite_LDFLAGS = $(top_builddir)/src/liblol.a @LOL_LIBS@
  • trunk/test/testsuite.vcxproj

    r2165 r2205  
    4040    <ClCompile Include="unit\build.cpp" />
    4141    <ClCompile Include="unit\cmplx.cpp" />
     42    <ClCompile Include="unit\color.cpp" />
    4243    <ClCompile Include="unit\half.cpp" />
    4344    <ClCompile Include="unit\image.cpp" />
Note: See TracChangeset for help on using the changeset viewer.