颜色空间的转换程序说明
编写环境:VC 6.0
实现方法:
RGB 颜色空间向 HIS 颜色空间的转化,转化规则是通过固定的公式,把 RGB 空间中的
值计算成 HIS 空间中的值,对应于 HIS 空间输出,对应的就可以转化成功了。
程序功能:
程序支持了手动输入更加灵活,用户先自行输入初值,然后程序实现转换!
具体实现程序如下:
#include<iostream>
#include<math.h>
using namespace std;
int index1,index2,index3;
//对图像格式转换,由 RGB 空间格式转化到 HSI 空间格式
void RGB_To_HSI(int R,int G,int B,int &H ,int &S,int &I);
void main()
{
int H,S,I;
RGB_To_HSI(index1,index2,index3,H ,S,I);
//手动输入三个初始的 RGB 初值
std::cout << "plese input three RGB value"<< endl ;
std::cin >> index1 >> index2 >> index3;
cout << H << " " << S << " " << I << " " << endl;
}
void RGB_To_HSI(int R,int G,int B,int &H ,int &S,int &I)
{
float Hf,Sf,If;
if (R==0 && G==0 && B==0)
{
Hf=160;
Sf=0;
If=0;
}
else if (R==255 && G==255 && B==255)
{
Hf=160;
Sf=0;
If=240;
}
else
- 1
- 2
- 3
前往页