RGB to HSV 색상변환

Author : 퓨림노 / Date : 2014.12.29 16:08 / Category : before/Develop


RGB to HSV 색상변환


<코드>

#define MATH_MIN3(x,y,z)		( (y) <= (z) ? ((x) <= (y) ? (x) : (y)) : ((x) <= (z) ? (x) : (z)) )
#define MATH_MAX3(x,y,z)		( (y) >= (z) ? ((x) >= (y) ? (x) : (y)) : ((x) >= (z) ? (x) : (z)) )

struct hsv_color {
    unsigned char h;        // Hue: 0 ~ 255 (red:0, gree: 85, blue: 171)
    unsigned char s;        // Saturation: 0 ~ 255
    unsigned char v;        // Value: 0 ~ 255
};

hsv_color RGB2HSV(unsigned char r, unsigned char g, unsigned char b)
{
	unsigned char rgb_min, rgb_max;
	rgb_min = MATH_MIN3(b, g, r);
	rgb_max = MATH_MAX3(b, g, r);

	hsv_color hsv;
	hsv.v = rgb_max;
	if (hsv.v == 0) {
		hsv.h = hsv.s = 0;
		return hsv;
	}

	hsv.s = 255*(rgb_max - rgb_min)/hsv.v;
	if (hsv.s == 0) {
		hsv.h = 0;
		return hsv;
	}

	if (rgb_max == r) {
		hsv.h = 0 + 43*(g - b)/(rgb_max - rgb_min);
	} else if (rgb_max == g) {
		hsv.h = 85 + 43*(b - r)/(rgb_max - rgb_min);
	} else /* rgb_max == rgb.b */ {
		hsv.h = 171 + 43*(r - g)/(rgb_max - rgb_min);
	}

	return hsv;
}



Reference

블로그1 http://zeal74.tistory.com/1180

WIKI : http://ko.wikipedia.org/wiki/HSV_%EC%83%89_%EA%B3%B5%EA%B0%84

블로그2 : http://babytiger.tistory.com/entry/opencv%EC%97%90%EC%84%9C-HSV%EC%9D%98-%EA%B0%81-%EC%B1%84%EB%84%90-%EB%B2%94%EC%9C%84

블로그3 : http://darkpgmr.tistory.com/66




저작자 표시 비영리 동일 조건 변경 허락
신고

'before > Develop' 카테고리의 다른 글

RGB to HSV 색상변환  (0) 2014.12.29
[Unity3D] Animation 제어  (0) 2014.11.01
[unity] unity can not sign application  (0) 2014.07.03
[티스토리(Tistory)] SyntaxHighlighter Setting!!  (0) 2014.06.10
[OpenCV] Blending  (2) 2014.04.22
openCV ROI 영역에 관해  (0) 2013.11.13

Tags : , , ,

Blog Information

퓨림노

앞으로 블로그에 markdown+dropbox를 이용하여 포스팅 예정중!!

Search

Statistics

  • Total : 447,702
  • Today : 21
  • Yesterday : 51

Archives

Copyright © http://vbflash.net All Rights Reserved
Designed by CMSFactory.NET