Help us understand the problem. What is going on with this article?

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

More than 5 years have passed since last update.

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;
```

}

Why not register and get more from Qiita?
1. We will deliver articles that match you
By following users and tags, you can catch up information on technical fields that you are interested in as a whole
2. you can read useful information later efficiently
By "stocking" the articles you like, you can search right away