首页 > 代码库 > RGB空间与HSV空间的相互转换(C++实现,修正网上大多数的代码错误)
RGB空间与HSV空间的相互转换(C++实现,修正网上大多数的代码错误)
void Rgb2Hsv(float R, float G, float B, float& H, float& S, float&V){ // r,g,b values are from 0 to 1 // h = [0,360], s = [0,1], v = [0,1] // if s == 0, then h = -1 (undefined) float min, max, delta,tmp; tmp = R>G?G:R; min = tmp>B?B:tmp; tmp = R>G?R:G; max = tmp>B?tmp:B; V = max; // v delta = max - min; if( max != 0 ) S = delta / max; // s else { // r = g = b = 0 // s = 0, v is undefined S = 0; H = 0; return; } if (delta == 0){ H = 0; return; } else if(R == max){ if (G >= B) H = (G - B) / delta; // between yellow & magenta else H = (G - B) / delta + 6.0; } else if( G == max ) H = 2.0 + ( B - R ) / delta; // between cyan & yellow else if (B == max) H = 4.0 + ( R - G ) / delta; // between magenta & cyan H *= 60.0; // degrees}
源地址:http://blog.csdn.net/shijun_zhang/article/details/6525388
RGB空间与HSV空间的相互转换(C++实现,修正网上大多数的代码错误)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。