about summary refs log tree commit diff
path: root/lib/libppmfuzzy.c
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2006-09-04 18:14:59 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2006-09-04 18:14:59 +0000
commitab395adc780e78b5f1ba0ff7a4c69415b3de928a (patch)
tree4ab74fa71323c897e4dd197846296da4f957f344 /lib/libppmfuzzy.c
parentfc13ef5f73e9b97e7353ae980b470a59066b7ddc (diff)
downloadnetpbm-mirror-ab395adc780e78b5f1ba0ff7a4c69415b3de928a.tar.gz
netpbm-mirror-ab395adc780e78b5f1ba0ff7a4c69415b3de928a.tar.xz
netpbm-mirror-ab395adc780e78b5f1ba0ff7a4c69415b3de928a.zip
Adjustments to Berlin-Kay fuzzy color matching
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@36 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'lib/libppmfuzzy.c')
-rw-r--r--lib/libppmfuzzy.c89
1 files changed, 50 insertions, 39 deletions
diff --git a/lib/libppmfuzzy.c b/lib/libppmfuzzy.c
index 6127d5d5..e149b42a 100644
--- a/lib/libppmfuzzy.c
+++ b/lib/libppmfuzzy.c
@@ -84,7 +84,7 @@ memberTrapez(fzLog const x1,
 static fzLog
 hueIsAround000(double const hue) {
 
-    return memberZ(10, 30, hue);
+    return memberZ(10, 20, hue);
 }
 
 
@@ -92,7 +92,7 @@ hueIsAround000(double const hue) {
 static fzLog
 hueIsAround015(double const hue) {
 
-    return memberZ(30, 40, hue);
+    return memberZ(20, 40, hue);
 }
 
 
@@ -100,7 +100,7 @@ hueIsAround015(double const hue) {
 static fzLog
 hueIsAround030(double const hue) {
 
-    return memberTrapez(10, 30, 40, 60, hue);
+    return memberTrapez(10, 20, 40, 60, hue);
 }
 
 
@@ -108,7 +108,7 @@ hueIsAround030(double const hue) {
 static fzLog
 hueIsAround060(double const hue) {
 
-    return memberTrapez(40, 60, 60, 80, hue);
+    return memberTrapez(40, 50, 60, 70, hue);
 }
 
 
@@ -116,7 +116,7 @@ hueIsAround060(double const hue) {
 static fzLog
 hueIsAround120(double const hue) {
 
-    return memberTrapez(60, 80, 150, 180, hue);
+    return memberTrapez(60, 70, 150, 180, hue);
 }
 
 
@@ -160,14 +160,14 @@ hueIsAround360(double const hue) {
 static fzLog
 satIsVeryLow(double const sat) {
 
-    return memberZ(0.02, 0.1, sat);
+    return memberZ(0.03, 0.08, sat);
 }
 
 
 
 static fzLog
 satIsLow(double const sat) {
-    return memberTrapez(0.02, 0.1, 0.2, 0.3, sat);
+    return memberTrapez(0.03, 0.08, 0.17, 0.2, sat);
 }
 
 
@@ -175,7 +175,7 @@ satIsLow(double const sat) {
 static fzLog
 satIsMedium(double const sat) {
 
-    return memberTrapez(0.2, 0.3, 0.6, 0.7, sat);
+    return memberTrapez(0.17, 0.2, 0.6, 0.8, sat);
 }
 
 
@@ -183,7 +183,7 @@ satIsMedium(double const sat) {
 static fzLog
 satIsHigh(double const sat) {
 
-    return memberS(0.6, 0.7, sat);
+    return memberS(0.6, 0.8, sat);
 }
 
 
@@ -195,7 +195,7 @@ satIsHigh(double const sat) {
 static fzLog
 valIsVeryLow(double const val) {
 
-    return memberZ(0.1, 0.2, val);
+    return memberZ(0.05, 0.2, val);
 }
 
 
@@ -203,7 +203,7 @@ valIsVeryLow(double const val) {
 static fzLog
 valIsLow(double const val) {
 
-    return memberTrapez(0.1, 0.2, 0.3, 0.6, val);
+    return memberTrapez(0.05, 0.2, 0.25, 0.3, val);
 }
 
 
@@ -211,7 +211,7 @@ valIsLow(double const val) {
 static fzLog
 valIsMedium(double const val) {
 
-    return memberTrapez(0.3, 0.6, 0.7, 0.8, val);
+    return memberTrapez(0.25, 0.3, 0.6, 0.7, val);
 }
 
 
@@ -219,7 +219,15 @@ valIsMedium(double const val) {
 static fzLog
 valIsHigh(double const val) {
 
-    return memberS(0.7, 0.8, val);
+    return memberTrapez(0.6, 0.7, 0.95, 0.97, val);
+}
+
+
+
+static fzLog
+valIsVeryHigh(double const val) {
+
+    return memberS(0.95, 0.97, val);
 }
 
 
@@ -269,10 +277,11 @@ matchBk(pixel     const color,
     fzLog const satMedium  = satIsMedium(hsv.s);
     fzLog const satHigh    = satIsHigh(hsv.s);
 
-    fzLog const valVeryLow = valIsVeryLow(hsv.v);
-    fzLog const valLow     = valIsLow(hsv.v);
-    fzLog const valMedium  = valIsMedium(hsv.v);
-    fzLog const valHigh    = valIsHigh(hsv.v);
+    fzLog const valVeryLow  = valIsVeryLow(hsv.v);
+    fzLog const valLow      = valIsLow(hsv.v);
+    fzLog const valMedium   = valIsMedium(hsv.v);
+    fzLog const valHigh     = valIsHigh(hsv.v);
+    fzLog const valVeryHigh = valIsVeryHigh(hsv.v);
 
     fzLog const hueAround000 = hueIsAround000(hsv.h);
     fzLog const hueAround015 = hueIsAround015(hsv.h);
@@ -285,13 +294,13 @@ matchBk(pixel     const color,
     fzLog const hueAround360 = hueIsAround360(hsv.h);
 
     (*bkMatchP)[BKCOLOR_BLACK]  =
-        fzAnd(fzOr(satVeryLow, satLow), valVeryLow);
+        fzAnd(fzOr(satVeryLow, satLow), fzOr(valVeryLow, valLow));
 
     (*bkMatchP)[BKCOLOR_GRAY]   =
-        fzAnd(fzOr(satVeryLow, satLow), fzOr(valLow, valMedium));
+        fzAnd(satVeryLow, fzAnd(fzNot(valVeryLow), fzNot(valVeryHigh)));
 
     (*bkMatchP)[BKCOLOR_WHITE]  =
-        fzAnd(fzOr(satVeryLow, satLow), valHigh);
+        fzAnd(satVeryLow, valVeryHigh);
     
     (*bkMatchP)[BKCOLOR_RED]    =
         fzAnd(fzAnd(fzOr(hueAround000, hueAround360), fzNot(satVeryLow)),
@@ -300,38 +309,40 @@ matchBk(pixel     const color,
 
     (*bkMatchP)[BKCOLOR_ORANGE] =
         fzAnd(fzAnd(hueAround030, fzOr(satMedium, satHigh)),
-              fzOr(valMedium, valHigh)
+              fzOr(fzOr(valMedium, valHigh), valVeryHigh)
              );
 
     (*bkMatchP)[BKCOLOR_YELLOW] =
         fzAnd(fzAnd(hueAround060, fzOr(satMedium, satHigh)),
-              fzOr(valMedium, valHigh)
+              fzOr(valHigh, valVeryHigh)
              );
 
     (*bkMatchP)[BKCOLOR_GREEN]  =
-        fzAnd(fzAnd(hueAround120, fzNot(satVeryLow)),
-              fzOr(valMedium, valHigh)
+        fzAnd(fzAnd(hueAround120, fzOr(satMedium, satHigh)),
+              fzAnd(fzNot(valVeryLow), fzNot(valLow))
              );
 
     (*bkMatchP)[BKCOLOR_BLUE]   =
-        fzAnd(fzAnd(hueAround180, fzAnd(fzNot(satVeryLow), fzNot(satLow))),
-              fzOr(valMedium, valHigh)
+        fzAnd(fzAnd(hueAround180, fzNot(satVeryLow)),
+              fzNot(valVeryLow)
              );
 
     (*bkMatchP)[BKCOLOR_VIOLET] =
-        fzAnd(fzAnd(hueAround270, fzNot(satVeryLow)),
+        fzAnd(fzAnd(hueAround270, fzOr(satMedium, satHigh)),
               fzOr(valMedium, valHigh)
              );
 
     (*bkMatchP)[BKCOLOR_PURPLE] =
-        fzAnd(fzAnd(hueAround320, fzNot(satVeryLow)),
+        fzAnd(fzAnd(hueAround320, fzOr(satMedium, satHigh)),
               fzOr(valMedium, valHigh)
              );
 
     (*bkMatchP)[BKCOLOR_BROWN]  =
-        fzAnd(fzOr(hueAround015, hueAround360),
-              fzAnd(fzNot(satVeryLow), fzNot(valHigh))
-             );
+	fzOr(
+             fzAnd(fzOr(hueAround015, hueAround360),
+                   fzAnd(fzNot(satVeryLow), fzOr(valLow, valMedium))),
+             fzAnd(hueAround015, satLow)
+	    );
 }
 
 
@@ -359,17 +370,17 @@ ppm_bk_color_from_color(pixel  const color,
 
 
 static pixel const bkColorMap[BKCOLOR_COUNT] = {
-    {  0,   0,   0}, /* BKCOLOR_BLACK  */
     {174, 174, 174}, /* BKCOLOR_GRAY   */
-    {255, 255, 255}, /* BKCOLOR_WHITE  */
-    {255,   0,   0}, /* BKCOLOR_RED    */
+    {128,  42,  42}, /* BKCOLOR_BROWN  */
     {255, 128,   0}, /* BKCOLOR_ORANGE */
+    {255,   0,   0}, /* BKCOLOR_RED    */
     {255, 255,   0}, /* BKCOLOR_YELLOW */
     {  0, 255,   0}, /* BKCOLOR_GREEN  */
     {  0,   0, 255}, /* BKCOLOR_BLUE   */
     {143,  94, 153}, /* BKCOLOR_VIOLET */
     {160,  32, 240}, /* BKCOLOR_PURPLE */
-    {128,  42,  42}  /* BKCOLOR_BROWN  */
+    {255, 255, 255}, /* BKCOLOR_WHITE  */
+    {  0,   0,   0}  /* BKCOLOR_BLACK  */
 };
 
 
@@ -393,17 +404,17 @@ ppm_color_from_bk_color(bk_color const bkColor,
 
 
 static const char * const bkColorNameMap[BKCOLOR_COUNT] = {
-    "black",
     "gray",
-    "white",
-    "red",
+    "brown",
     "orange",
+    "red",
     "yellow",
     "green",
     "blue",
     "violet",
     "purple",
-    "brown"
+    "white",
+    "black"
 };