LoginSignup
2
2

More than 5 years have passed since last update.

HSIカラー空間への変換(oF)

Posted at

HSI testApp::RGBtoHSI(unsigned char r, unsigned char g, unsigned char b)
{
HSI hsi = {0.0f, 0.0f, 0.0f};

unsigned char max, min;

// get Max
if (r > g) max = r;
else max = g;
if (b > max) max = b;
// get Min
if (r < g) min = r;
else min = g;
if (b < min) min = b;

if (max == min) {
    hsi.h = -1.0f;
    hsi.s = 0.0f;
    hsi.i = (float)max / 255.0f;
    return hsi;
}

// calc Hue
if (max == r) 
    hsi.h = (float)(M_PI/3 * (((float)g - b)/(max - min)));
else if (max == g)
    hsi.h = (float)(M_PI/3 * (((float)b - r)/(max - min)) + 2 * M_PI / 3);
else if (max == b)
    hsi.h = (float)(M_PI/3 * (((float)r - g)/(max - min)) + 4 * M_PI / 3);
if (hsi.h < 0.0f) hsi.h += 2 * M_PI;

// calc Saturation
hsi.s = (max - min) / max;

// calc Intensity
hsi.i = max / 255.0f;

return hsi;

}

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2