Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

[solved] - Help coming up with color definitions?


  • Please log in to reply
2 replies to this topic
  • Guests
  • Last active:
  • Joined: --
I have something that gets a pixel colors and coverts it to 255 BGR values. I have tried to come up with some statements that define each of the colors without picking up on other colors, but I can't seem to get them all to fit so no errors happen... So I turn to you guys. Here is my color and values list. NOTE THEY ARE IN BGR not RGB.

BGR form (BLUE GREEN RED ORDER) out of 255.

PINK:
128 224 17
128 224 17
128 224 17
128 224 17
128 224 17
128 224 17
128 224 17
128 224 17
128 224 17
128 224 17
35 46 30
35 46 30
63 62 59
63 62 59
91 79 88
119 95 117
119 95 117
119 95 117
146 111 146
80 97 242
80 97 242
80 97 242
80 97 242
80 97 242
80 97 242

PURPLE:
174 23 46
173 22 44
173 22 44
173 22 44
173 22 44
174 22 45
173 21 44
175 26 49
174 23 46
174 23 46
175 26 49
174 23 46
174 23 46
175 26 49
180 34 56
180 34 56
180 34 56
180 34 57
181 35 57
181 35 57
183 38 61
183 38 61
183 38 61
189 47 70
189 48 70
232 148 86

ORANGE:
41 18 98
41 18 98
41 18 98
59 64 137

RED:
75 54 245
86 55 246
93 62 246
86 55 246
118 73 248
118 73 248
118 73 248
118 73 248
132 83 248
150 92 249
150 92 249
150 92 249
160 98 250
160 98 250
160 98 250
192 117 251
192 117 251
192 117 251
192 117 251
181 111 251
192 117 251
219 129 252
213 129 252
213 129 252
213 129 252

BLUE:
207 168 41
209 171 49
211 172 53
211 172 53
213 174 57
213 174 57
213 174 57
213 174 57
213 174 57
213 174 57
213 175 61
213 175 61
215 177 65
215 177 65
215 177 65
215 177 65
216 178 69
216 178 69
216 178 69
216 178 69
216 178 69
216 178 69
219 180 73
219 180 73
219 181 77
221 183 81
222 184 85
224 186 89
224 186 89
224 186 89
224 186 89


GREEN:
71 170 31
72 171 31
71 170 31
71 170 31
72 171 31
71 170 31
71 170 31
72 172 31
71 170 31
71 170 31
72 172 31
71 171 31

YELLOW:
40 146 230
40 146 230
40 146 230
40 146 230
40 145 230
40 144 230
40 145 230
40 145 230
40 144 230
40 144 230


Note that some of the colors change just slightly in value, so you can't use == incase some come out slightly different.

This was the code I had that doesn't work all that great:

; Determine color
	If ( G > 200 ) && ( B < 140 ) && ( 120 < B ) && ( 30 > R ) || (B==63 && G==62 && R==59)|| (B==80 && G==97 && R==242) 
        COLORCHOICE = W ; pink since P is taken
      Else If ( G < R ) && ( G < B ) && ( R < B )
        COLORCHOICE = P ; purple
      Else If (( B == 41 ) && ( G == 18 ) && ( R == 98 )) || (( B == 59 ) && ( G == 64 ) && ( R == 137 )) 
        COLORCHOICE = O ; orange
      Else If (  (B>70) && (B<R) && (G>50) && (G<130) && (R>240) ) 
        COLORCHOICE = R ; red
      Else If ( (B>190) && (R<110) && (G>160) ) 
        COLORCHOICE = B ; blue
      Else If ( G > B+R ) || ( (G>B) && (B=R) )
        COLORCHOICE = G ; green
		Else If ( (R>B*2) && (R>G) )
        COLORCHOICE = Y ; yellow
	  Else
        COLORCHOICE = ? ; unknown..

I would appreciate you guys mentioning some tips because I really need the colors to be as accurate as possible. Thank you.

engunneer
  • Moderators
  • 9162 posts
  • Last active: Sep 12 2014 10:36 PM
  • Joined: 30 Aug 2005
This script converts the numbers to HSV, and then filters. the relationship from H to your color definitions is much easier to figure out.

tested
Colors =
(
PINK: 
128 224 17 
128 224 17 
128 224 17 
128 224 17 
128 224 17 
128 224 17 
128 224 17 
128 224 17 
128 224 17 
128 224 17 
35 46 30 
35 46 30 
63 62 59 
63 62 59 
91 79 88 
119 95 117 
119 95 117 
119 95 117 
146 111 146 
80 97 242 
80 97 242 
80 97 242 
80 97 242 
80 97 242 
80 97 242 
PURPLE: 
174 23 46 
173 22 44 
173 22 44 
173 22 44 
173 22 44 
174 22 45 
173 21 44 
175 26 49 
174 23 46 
174 23 46 
175 26 49 
174 23 46 
174 23 46 
175 26 49 
180 34 56 
180 34 56 
180 34 56 
180 34 57 
181 35 57 
181 35 57 
183 38 61 
183 38 61 
183 38 61 
189 47 70 
189 48 70 
232 148 86 
ORANGE: 
41 18 98 
41 18 98 
41 18 98 
59 64 137 
RED: 
75 54 245 
86 55 246 
93 62 246 
86 55 246 
118 73 248 
118 73 248 
118 73 248 
118 73 248 
132 83 248 
150 92 249 
150 92 249 
150 92 249 
160 98 250 
160 98 250 
160 98 250 
192 117 251 
192 117 251 
192 117 251 
192 117 251 
181 111 251 
192 117 251 
219 129 252 
213 129 252 
213 129 252 
213 129 252 
BLUE: 
207 168 41 
209 171 49 
211 172 53 
211 172 53 
213 174 57 
213 174 57 
213 174 57 
213 174 57 
213 174 57 
213 174 57 
213 175 61 
213 175 61 
215 177 65 
215 177 65 
215 177 65 
215 177 65 
216 178 69 
216 178 69 
216 178 69 
216 178 69 
216 178 69 
216 178 69 
219 180 73 
219 180 73 
219 181 77 
221 183 81 
222 184 85 
224 186 89 
224 186 89 
224 186 89 
224 186 89 
GREEN: 
71 170 31 
72 171 31 
71 170 31 
71 170 31 
72 171 31 
71 170 31 
71 170 31 
72 172 31 
71 170 31 
71 170 31 
72 172 31 
71 171 31 
YELLOW: 
40 146 230 
40 146 230 
40 146 230 
40 146 230 
40 145 230 
40 144 230 
40 145 230 
40 145 230 
40 144 230 
40 144 230
)

Loop, parse, Colors, `n, `r
{
  ThisColorBGR := A_LoopField
  StringSplit, colorpart, ThisColorBGR, %A_Space%
	if colorpart1 is not number
	{
	  output .= ThisColorBGR "`n"
	  continue
	}
  b := colorpart1 / 255
  g := colorpart2 / 255
  r := colorpart3 / 255
	
	Color_RGBtoHSV(r, g, b, h, s, v)
	
	If (h > 265) && (h < 269) 
	  COLORCHOICE = Y ; yellow
	Else If ((h > 210) && (h < 220)) || ((h > 245) && (h < 255))
	  COLORCHOICE = P ; purple
	Else If (h > 295) && (h < 305) && (v < 0.70) && (s > 0.50)
	  COLORCHOICE = O ; orange
	Else If (h > 295) && (h < 305) && (v >= 0.70) 
	  COLORCHOICE = R ; red
	Else If (h > 190) && (h < 200) && (s > 0.15)
	  COLORCHOICE = B ; blue
	Else If (h > 175) && (h < 185) && (s > 0.75) && (s < 0.85)
	  COLORCHOICE = G ; green
	Else If ((h > 175) && (h < 185) && ((v <= 0.75) || (v >= 0.85)) ) || ((h > 280) && (h < 301)) || ((h > 190) && (h < 200))
	  COLORCHOICE = N ; pink since P is taken
	Else
	  COLORCHOICE = ? ; unknown..
					
	;Msgbox, %ThisColorBGR%`n%b% %g% %r%`n%h% %s% %v%  
  output .= ThisColorBGR "`t`t" Round(h,0) " " Round(s,2) " " Round(v,2) "`t`t" COLORCHOICE "`n"
}

FileAppend %output%, 77061.txt

msgbox
exitapp
Return

^q::Exitapp






;from http://www.cs.rit.edu/~ncs/color/t_convert.html
;// 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)
Color_RGBtoHSV( r, g, b, Byref h, Byref s, Byref v )
{
	min := MIN( r, g, b )
	max := MAX( r, g, 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 := -1 
		return 
	}
	if( r = max )
		h := ( g - b ) / delta ;		// between yellow & magenta
	else if( g == max )
		h := 2 + ( b - r ) / delta ;	// between cyan & yellow
	else
		h := 4 + ( r - g ) / delta ;	// between magenta & cyan
	h *= 60 ;				// degrees
	if( h < 0 )
		h += 360 ;
	return
}

Color_HSVtoRGB( h, s, v, ByRef r, ByRef g, ByRef b )
{
	if( s = 0 ) {
		;// achromatic (grey)
		r := v, g := v, b := v ;
		return
	}
	h /= 60 ;			// sector 0 to 5
	i := floor( h ) ;
	f := h - i ;			// factorial part of h
	p := v * ( 1 - s ) ;
	q := v * ( 1 - s * f ) ;
	t = v * ( 1 - s * ( 1 - f ) ) ;
	if (i = 0) {
		r := v
		g := t
		b := p
		Return
	}
	if (i = 1) {
		r := q
		g := v
		b := p
		Return
	}
	if (i = 2) {
		r := p
		g := v
		b := t
		Return
	}
	if (i = 3) {
		r := p
		g := q
		b := v
		Return
	}
	if (i = 4) {
		r := t
		g := p
		b := v
		Return
	}
	;default
	r := v
	g := p
	b := q
	Return
	
}

MIN(in1="", in2="", in3="", in4="", in5="", in6="", in7="", in8="", in9="", in10="")
{
	Loop, 10
		If in%A_Index% is number
		  list .= in%A_Index% . "`n"
		  
	Sort, list, N
	StringSplit, item, list, `n, `r
  Return item1
}

MAX(in1="", in2="", in3="", in4="", in5="", in6="", in7="", in8="", in9="", in10="")
{
	Loop, 10
		If in%A_Index% is number
		  list .= in%A_Index% . "`n"
		  
	Sort, list, N R
	StringSplit, item, list, `n, `r
  Return item1
}

If you remove the ? option, and have pink as default, the selection is even easier
	If (h > 265) && (h < 269) 
	  COLORCHOICE = Y ; yellow
	Else If (h > 210) && (h < 220) || (h > 245) && (h < 255)
	  COLORCHOICE = P ; purple
	Else If (h > 295) && (h < 305) && (v < 0.70) && (s > 0.5)
	  COLORCHOICE = O ; orange
	Else If (h > 295) && (h < 305) && (v >= 0.70) 
	  COLORCHOICE = R ; red
	Else If (h > 190) && (h < 200) && (s > 0.1)
	  COLORCHOICE = B ; blue
	Else If (h > 175) && (h < 185) && (s > 0.75) && (s < 0.85)
	  COLORCHOICE = G ; green
	Else
	  COLORCHOICE = N ; pink since P is taken

Note I used N for piNk instead of W.