Definition at line 472 of file Color64.h. References BYTE, max, and min. Referenced by ExtractCorrelogramTextureMoment(). 00473 { 00474 static BYTE RGB2HSV[16][16][16]; 00475 static bool bInit = false; 00476 if (!bInit) 00477 { 00478 for (int r = 0; r < 16; r ++) 00479 { 00480 for (int g = 0; g < 16; g ++) 00481 { 00482 for (int b = 0; b < 16; b ++) 00483 { 00484 int nMax = max(r, max(g, b)); 00485 int nMin = min(r, min(g, b)); 00486 00487 float h, s, v; 00488 if (nMax == nMin) 00489 { 00490 h = 0; 00491 } 00492 else if (r == nMin) 00493 { 00494 h = 3.0f + (float)(b - g) / (nMax - nMin); 00495 } 00496 else if (g == nMin) 00497 { 00498 h = 5.0f + (float)(r - b) / (nMax - nMin); 00499 } 00500 else //if (b == nMin) 00501 { 00502 h = 1.0f + (float)(g - r) / (nMax - nMin); 00503 } 00504 if (nMax > 0) 00505 { 00506 s = (float)(nMax - nMin) / nMax; 00507 } 00508 else 00509 { 00510 s = 0; 00511 } 00512 v = (float)nMax / 15.0f; 00513 00514 int H = (int)(h * 60); 00515 int S = (int)(s * 10); 00516 int V = (int)(v * 10); 00517 int nIndex; 00518 00519 if (V < 2) // black area 00520 { 00521 nIndex = 0; 00522 } 00523 else if (S < 2) // Gray area 00524 { 00525 if (V < 8) 00526 { 00527 nIndex = V - 1; // 1~6, gray area 00528 } 00529 else 00530 { 00531 nIndex = 7 + (V >= 9); // 7~8, white area 00532 } 00533 } 00534 else // Color area 00535 { 00536 int nColor; 00537 if (H < 22) 00538 { 00539 nColor = 0; // red 00540 } 00541 else if (H < 45) 00542 { 00543 nColor = 1; // orance 00544 } 00545 else if (H < 70) 00546 { 00547 nColor = 2; // yellow 00548 } 00549 else if (H < 155) 00550 { 00551 nColor = 3; // green 00552 } 00553 else if (H < 186) 00554 { 00555 nColor = 4; // cyan 00556 } 00557 else if (H < 278) 00558 { 00559 nColor = 5; // blue 00560 } 00561 else if (H < 330) 00562 { 00563 nColor = 6; // purple 00564 } 00565 else 00566 { 00567 nColor = 0; // red 00568 } 00569 00570 if (V >= 7) // SV plane is segmented into 5 regions 00571 { 00572 nIndex = 2 + (S >= 5) + (S >= 8); 00573 } 00574 else 00575 { 00576 nIndex = (S >= 7); 00577 } 00578 nIndex += 9 + 5 * nColor; // 9~43 00579 } 00580 RGB2HSV[r][g][b] = nIndex; 00581 } 00582 } 00583 } 00584 bInit = true; 00585 } 00586 return RGB2HSV[bRed / 16][bGreen / 16][bBlue / 16]; 00587 }
|