How to generate random 'greenish' colors - python

Anyone have any suggestions on how to make randomized colors that are all greenish? Right now I'm generating the colors by this:
color = (randint(100, 200), randint(120, 255), randint(100, 200))
That mostly works, but I get brownish colors a lot.

Simple solution: Use the HSL or HSV color space instead of rgb (convert it to RGB afterwards if you need this). The difference is the meaning of the tuple: Where RGB means values for Red, Green and Blue, in HSL the H is the color (120 degree or 0.33 meaning green for example) and the S is for saturation and the V for the brightness. So keep the H at a fixed value (or for even more random colors you could randomize it by add/sub a small random number) and randomize the S and the V. See the wikipedia article.

As others have suggested, generating random colours is much easier in the HSV colour space (or HSL, the difference is pretty irrelevant for this)
So, code to generate random "green'ish" colours, and (for demonstration purposes) display them as a series of simple coloured HTML span tags:
#!/usr/bin/env python2.5
"""Random green colour generator, written by dbr, for
http://stackoverflow.com/questions/1586147/how-to-generate-random-greenish-colors
"""
def hsv_to_rgb(h, s, v):
"""Converts HSV value to RGB values
Hue is in range 0-359 (degrees), value/saturation are in range 0-1 (float)
Direct implementation of:
http://en.wikipedia.org/wiki/HSL_and_HSV#Conversion_from_HSV_to_RGB
"""
h, s, v = [float(x) for x in (h, s, v)]
hi = (h / 60) % 6
hi = int(round(hi))
f = (h / 60) - (h / 60)
p = v * (1 - s)
q = v * (1 - f * s)
t = v * (1 - (1 - f) * s)
if hi == 0:
return v, t, p
elif hi == 1:
return q, v, p
elif hi == 2:
return p, v, t
elif hi == 3:
return p, q, v
elif hi == 4:
return t, p, v
elif hi == 5:
return v, p, q
def test():
"""Check examples on..
http://en.wikipedia.org/wiki/HSL_and_HSV#Examples
..work correctly
"""
def verify(got, expected):
if got != expected:
raise AssertionError("Got %s, expected %s" % (got, expected))
verify(hsv_to_rgb(0, 1, 1), (1, 0, 0))
verify(hsv_to_rgb(120, 0.5, 1.0), (0.5, 1, 0.5))
verify(hsv_to_rgb(240, 1, 0.5), (0, 0, 0.5))
def main():
"""Generate 50 random RGB colours, and create some simple coloured HTML
span tags to verify them.
"""
test() # Run simple test suite
from random import randint, uniform
for i in range(50):
# Tweak these values to change colours/variance
h = randint(90, 140) # Select random green'ish hue from hue wheel
s = uniform(0.2, 1)
v = uniform(0.3, 1)
r, g, b = hsv_to_rgb(h, s, v)
# Convert to 0-1 range for HTML output
r, g, b = [x*255 for x in (r, g, b)]
print "<span style='background:rgb(%i, %i, %i)'> </span>" % (r, g, b)
if __name__ == '__main__':
main()
The output (when viewed in a web-browser) should look something along the lines of:
Edit: I didn't know about the colorsys module. Instead of the above hsv_to_rgb function, you could use colorsys.hsv_to_rgb, which makes the code much shorter (it's not quite a drop-in replacement, as my hsv_to_rgb function expects the hue to be in degrees instead of 0-1):
#!/usr/bin/env python2.5
from colorsys import hsv_to_rgb
from random import randint, uniform
for x in range(50):
h = uniform(0.25, 0.38) # Select random green'ish hue from hue wheel
s = uniform(0.2, 1)
v = uniform(0.3, 1)
r, g, b = hsv_to_rgb(h, s, v)
# Convert to 0-1 range for HTML output
r, g, b = [x*255 for x in (r, g, b)]
print "<span style='background:rgb(%i, %i, %i)'> </span>" % (r, g, b)

Check out the colorsys module:
http://docs.python.org/library/colorsys.html
Use the HSL or HSV color space. Randomize the hue to be close to green, then choose completely random stuff for the saturation and V (brightness).

If you stick with RGB, you basically just need to make sure the G value is greater than the R and B, and try to keep the blue and red values similar so that the hue doesn't go too crazy. Extending from Slaks, maybe something like (I know next to nothing about Python):
greenval = randint(100, 255)
redval = randint(20,(greenval - 60))
blueval = randint((redval - 20), (redval + 20))
color = (redval, greenval, blueval)

So in this case you are lucky enough to want variations on a primary color, but for artistic uses like this it is better to specify color wheel coordinates rather than primary color magnitudes.
You probably want something from the colorsys module like:
colorsys.hsv_to_rgb(h, s, v)
Convert the color from HSV coordinates to RGB coordinates.

The solution with HSx color space is a very good one. However, if you need something extremely simplistic and have no specific requirements about the distribution of the colors (like uniformity), a simplistic RGB-based solution would be just to make sure that G value is greater than both R and B
rr = randint(100, 200)
rb = randint(100, 200)
rg = randint(max(rr, rb) + 1, 255)
This will give you "greenish" colors. Some of them will be ever so slightly greenish. You can increase the guaranteed degree of greenishness by increasing (absolutely or relatively) the lower bound in the last randint call.

What you want is to work in terms of HSL instead of RGB. You could find a range of hue that satisfies "greenish" and pick a random hue from it. You could also pick random saturation and lightness but you'll probably want to keep your saturation near 1 and your lightness around 0.5 but you can play with them.
Below is some actionscript code to convert HSL to RGB. I haven't touched python in a while or it'd post the python version.
I find that greenish is something like 0.47*PI to 0.8*PI.
/**
#param h hue [0, 2PI]
#param s saturation [0,1]
#param l lightness [0,1]
#return object {r,g,b} {[0,1],[0,1][0,1]}
*/
public function hslToRGB(h:Number, s:Number, l:Number):Color
{
var q:Number = (l<0.5)?l*(1+s):l+s-l*s;
var p:Number = 2*l-q;
var h_k:Number = h/(Math.PI*2);
var t_r:Number = h_k+1/3;
var t_g:Number = h_k;
var t_b:Number = h_k-1/3;
if (t_r < 0) ++t_r; else if (t_r > 1) --t_r;
if (t_g < 0) ++t_g; else if (t_g > 1) --t_g;
if (t_b < 0) ++t_b; else if (t_b > 1) --t_b;
var c:Color = new Color();
if (t_r < 1/6) c.r = p+((q-p)*6*t_r);
else if (t_r < 1/2) c.r = q;
else if (t_r < 2/3) c.r = p+((q-p)*6*(2/3-t_r));
else c.r = p;
if (t_g < 1/6) c.g = p+((q-p)*6*t_g);
else if (t_g < 1/2) c.g = q;
else if (t_g < 2/3) c.g = p+((q-p)*6*(2/3-t_g));
else c.g = p;
if (t_b < 1/6) c.b = p+((q-p)*6*t_b);
else if (t_b < 1/2) c.b = q;
else if (t_b < 2/3) c.b = p+((q-p)*6*(2/3-t_b));
else c.b = p;
return c;
}

The simplest way to do this is to make sure that the red and blue components are the same, like this: (Forgive my Python)
rb = randint(100, 200)
color = (rb, randint(120, 255), rb)

I'd go with with the HSV approach everyone else mentioned. Another approach would be to get a nice high resolution photo which some greenery in it, crop out the non-green parts, and pick random pixels from it using PIL.

Related

Convert single 8 bit value (0-255) to 3, 8 bit values

Alright so the best way I can really explain this is on this site https://www.colorspire.com/rgb-color-wheel/ there is a color wheel when you first load the site don't move the little pointer in the square to select stuff. Just go to the bar that you can drag and drag it you'll see the r g b values change but you will also notice that one of the values is always 0, how can I recreate that but instead of the bar you drag you input a single 8 bit value (out of 255) so I can run the program with the value lets say 170 and it would somehow map that to a certain color.
You are actually changing the hue when you move the bar so try this
import colorsys
color = input("Enter a value from 0-359:")
test_color = colorsys.hsv_to_rgb(color/360.0, 1, 1)
References
HSV to RGB Color Conversion
test_color = colorsys.hsv_to_rgb(int(value)/255.0, 1, 1)
r, g, b = test_color
r = (r * 255)
r = math.trunc(r)
g = (g * 255)
g = math.trunc(g)
b = (b * 255)
b = math.trunc(b)
fg.orange = Style(RgbFg(r, g, b))
msg = fg.orange + str(f" r = {r}, g = {g}, b = {b}")
print(msg)

How can I detect a 'dark' image border and crop to it using Python (or Perl)?

I have a number of small images that are screen captures from a video. A couple of example images follow (with various typesof edges present):
In short, I'm trying to crop the image to the closest part of the 'main' image, which is inside an (almost) uniformly 'black' border... or sometimes, there's a bit of a 'jittery' edge. You could think of it as going to the centre of the image and then radiate out until you hit a 'rectangular ('black' or 'nearly black') border'.
The biggest issue as near as I can see is to determine the location and dimensions of the 'cropping rectangle' around the image.. but so far, I haven't been able to get anywhere with doing that.
I've tried using 'cropdetect' filters in ffmpeg; there's not anything really helpful with Perl; ...and as I'm new to Python, I still haven't worked-out if there's any simple module that can do what I need. I have looked at 'scikit-image'... but was totally bamboozled by it, as I don't have a good enough knowledge of Python, let alone a sufficientlly 'technical' knowledge of image formats, colour depth, manipulation techniques, etc that would let me use 'scikit-image'.
I'd appreciate any suggestions on how to tackle this problem, even better if there was a simple way to do it. From my little bit of understanding of 'scikit-image', it seems like the 'Canny edge detect' or the 'prewitt_v'/'prewitt_h' filters might be relevant...?
I'm using Python 3.7.0 (and Active State Perl v5.20.2, if there's any way to use that), both running under Windows 8.1.
Thanks a lot for any forthcoming suggestions.
I've made an attempt at solving this... but it's not very 'robust'. It uses the luminance values of the pixels when the image has been greyscaled:-
# ----
# this will find the 'black'-ish portions and crop the image to these points
# ozboomer, 25-Apr-2020 3-May-2020
#
# ---------
import pprint
import colorsys
from PIL import Image, ImageFilter
# ---- Define local functions (I *still* don't understand why I have to put these here)
def calculate_luminances(r, g, b):
"""Return luminance values of supplied RGB and greyscale of RGB"""
lum = (0.2126 * r) + (0.7152 * g) + (0.0722 * b) # luminance
H, S, V = colorsys.rgb_to_hsv(r, g, b) # HSV for the pixel RGB
R, G, B = colorsys.hsv_to_rgb(H, 0, V) # ...and greyscale RGB
glum = (0.2126 * R) + (0.7152 * G) + (0.0722 * B) # greyscale luminance
return(lum, glum)
# end calculate_luminances
def radial_edge(radial_vector, ok_range):
"""Return the point in the radial where the luminance marks an 'edge' """
print("radial_edge: test range=", ok_range)
edge_idx = -1
i = 0
for glum_value in radial_vector:
print(" radial_vector: i=", i, "glum_value=", "%.2f" % round(glum_value, 2))
if int(glum_value) in ok_range:
print(" IN RANGE! Return i=", i)
edge_idx = i
break
i = i + 1
# endfor
return(edge_idx)
# ---- End local function definitions
# ---- Define some constants, variables, etc
#image_file = "cap.bmp"
#image_file = "cap2.png"
#image_file = "cap3.png"
image_file = "Sample.jpg"
#image_file = "cap4.jpg"
output_file = "Cropped.png";
edge_threshold = range(0, 70) # luminance in this range = 'an edge'
#
# The image layout:-
#
# [0,0]----------+----------[W,0]
# | ^ |
# | | |
# | R3 |
# | | |
# +<--- R1 ---[C]--- R2 --->+
# | | |
# | R4 |
# | | |
# | v |
# [0,H]----------+----------[W,H]
#
# -------------------------------------
# Main Routine
#
# ---- Get the image file ready for processing
try:
im = Image.open(image_file) # RGB.. mode
except:
print("Unable to load image,", image_file)
exit(1)
# Dammit, Perl, etc code is SO much less verbose:-
# open($fh, "<", $filename) || die("\nERROR: Can't open file, '$filename'\n$!\n");
print("Image - Format, size, mode: ", im.format, im.size, im.mode)
W, H = im.size # The (width x height) of the image
XC = int(W / 2.0) # Approx. centre of image
YC = int(H / 2.0)
print("Image Centre: (XC,YC)=", XC, ",", YC)
# --- Define the ordinate ranges for each radial
R1_range = range(XC, -1, -1) # Actual range: XC->0 by -1 ... along YC ordinate
R2_range = range(XC, W, 1) # : XC->W by +1 ... along YC ordinate
R3_range = range(YC, -1, -1) # : YC->0 by -1 ... along XC ordinate
R4_range = range(YC, H, 1) # : YC->H by +1 ... along XC ordinate
# ---- Check each radial for its 'edge' point
radial_luminance = []
for radial_num in range (1,5): # We'll do the 4 midlines
radial_luminance.clear()
if radial_num == 1:
print("Radial: R1")
for x in R1_range:
R, G, B = im.getpixel((x, YC))
[lum, glum] = calculate_luminances(R, G, B)
print(" CoOrd=(", x, ",", YC, ") RGB=",
(R, G, B), "lum=", "%.2f" % round(lum, 2),
"glum=", "%.2f" % round(glum, 2))
radial_luminance.append(glum)
# end: get another radial pixel
left_margin = XC - radial_edge(radial_luminance, edge_threshold)
elif radial_num == 2:
print("Radial: R2")
for x in R2_range:
R, G, B = im.getpixel((x, YC))
[lum, glum] = calculate_luminances(R, G, B)
print(" CoOrd=(", x, ",", YC, ") RGB=",
(R, G, B), "lum=", "%.2f" % round(lum, 2),
"glum=", "%.2f" % round(glum, 2))
radial_luminance.append(glum)
# end: get another radial pixel
right_margin = XC + radial_edge(radial_luminance, edge_threshold)
elif radial_num == 3:
print("Radial: R3")
for y in R3_range:
R, G, B = im.getpixel((XC, y))
[lum, glum] = calculate_luminances(R, G, B)
print(" CoOrd=(", XC, ",", y, ") RGB=",
(R, G, B), "lum=", "%.2f" % round(lum, 2),
"glum=", "%.2f" % round(glum, 2))
radial_luminance.append(glum)
# end: get another radial pixel
top_margin = YC - radial_edge(radial_luminance, edge_threshold)
elif radial_num == 4:
print("Radial: R4")
for y in R4_range:
R, G, B = im.getpixel((XC, y))
[lum, glum] = calculate_luminances(R, G, B)
print(" CoOrd=(", XC, ",", y, ") RGB=",
(R, G, B), "lum=", "%.2f" % round(lum, 2),
"glum=", "%.2f" % round(glum, 2))
radial_luminance.append(glum)
# end: get another radial pixel
bottom_margin = YC + radial_edge(radial_luminance, edge_threshold)
# end: which radial we're processing
im.close()
crop_items = (left_margin, top_margin, right_margin, bottom_margin)
print("crop_items:", crop_items)
# ---- Crop the original image and save it
im = Image.open(image_file)
im2 = im.crop(crop_items)
im2.save(output_file, 'png')
exit(0)
# [eof]
I would expect the radial_edge() function would need to be modified to do something about checking the surrounding pixels to determine if we have a real edge... 'coz the current ok_range probably needs to be determined for each image, so there's no point to trying to automate the cropping using a script such as this.
Still looking for a robust and reliable way to attack this problem...

Efficient color lookup with linear interpolation in Python

I am interested in finding a fast method for looking up linearly interpolated colors from a defined lookup table. The purpose if to assign colors to a large number of items at run time based on a given color map. The colormap lookup table is a list of tuples that contains Values(Ascending), Red, Green, Blue, Opacity
Below is a simple recipe with standard python.
I could also use pandas as I am using that for something else as well.
# Interpolate colors from a lookup table
import bisect
def find_color(x, vlist, lut):
"""Finds linearly interpolated color from specified lut and x
Returns RGBA tuple
Parameters
x: value to lookup
vlist: list of values in lut
lut: List of tuples Value, R, G, B, A
"""
last = len(lut) - 1 # last index for lut
if x <= vlist[0] : #clamp low end
return lut[0][1], lut[0][2], lut[0][3], lut[0][4]
elif x >= vlist[last]: #clamp high end
return lut[last][1], lut[last][2], lut[last][3], lut[last][4]
else:
# since vlist is sorted we can use bisect
hi = bisect.bisect_left(vlist, x) #hi index
lo = hi - 1 # lo index
# interpolation weight from left
w = ( x - vlist[lo] ) / (vlist[hi] -vlist[lo] )
#print x, lo, hi, w
# use w to interpolate r,g,b,a from lo and hi bins
# interpolated_value = low_value + w * bin_size
r = lut[lo][1] + w * (lut[hi][1] - lut[lo][1])
g = lut[lo][2] + w * (lut[hi][2] - lut[lo][2])
b = lut[lo][3] + w * (lut[hi][3] - lut[lo][3])
a = lut[lo][4] + w * (lut[hi][4] - lut[lo][4])
return int(r), int(g), int(b), int(a)
# Color lookup table
lut = [ (0.0, 255, 0, 0, 64),
(0.5, 0, 255, 255,128),
(1.0, 0, 0, 255, 255) ]
# Value list - extract first column from lut
vlist = [ x[0] for x in lut]
# Test find_color() for arbitrary value
for i in xrange(-5, 12):
x = i/10.0
print find_color(x, vlist, lut)
If you can pre-process your lookup table ahead of time, you can replace the binary search + interpolation with a simple lookup. That is as long as you're willing to accept the possibility of not fully accurate output, which should be the case for colors - off by one errors are very hard to detect.
Take the value and multiply it by some constant, then convert to integer, and use that integer as an index into a list.
resolution = 1024
multiplier = float(resolution) / (lut[-1][0] - lut[0][0])
lookup = [(0, 0, 0, 0)] * resolution
for index in range(resolution):
r, g, b, a = find_color(lut[0][0] + i / multiplier, vlist, lut)
lookup[index] = (r, g, b, a)
def find_color2(x):
return lookup[int((x - lut[0][0]) * multiplier)]

Finding the position of an object in an image

My goal is to find the location of specific images on other images, using python. Take this example:
I want to find the location of the walnut in the image. The image of the walnut is known, so I think there is no need for any kind of advanced pattern matching or machine learning to tell if something is a walnut or not.
How would I go about finding the walnut in the image? Would a strategy along these lines work:
read images with with PIL
transform them into Numpy arrays
use Scipy's image filters (what filters?)
Thanks!
I would go with pure PIL.
Read in image and walnut.
Take any pixel of the walnut.
Find all pixels of the image with the same color.
Check to see if the surrounding pixels coincide with the surrounding pixels of the walnut (and break as soon as you find one mismatch to minimize time).
Now, if the picture uses lossy compression (like JFIF), the walnut of the image won't be exactly the same as the walnut pattern. In this case, you could define some threshold for comparison.
EDIT: I used the following code (by converting white to alpha, the colors of the original walnut slightly changed):
#! /usr/bin/python2.7
from PIL import Image, ImageDraw
im = Image.open ('zGjE6.png')
isize = im.size
walnut = Image.open ('walnut.png')
wsize = walnut.size
x0, y0 = wsize [0] // 2, wsize [1] // 2
pixel = walnut.getpixel ( (x0, y0) ) [:-1]
def diff (a, b):
return sum ( (a - b) ** 2 for a, b in zip (a, b) )
best = (100000, 0, 0)
for x in range (isize [0] ):
for y in range (isize [1] ):
ipixel = im.getpixel ( (x, y) )
d = diff (ipixel, pixel)
if d < best [0]: best = (d, x, y)
draw = ImageDraw.Draw (im)
x, y = best [1:]
draw.rectangle ( (x - x0, y - y0, x + x0, y + y0), outline = 'red')
im.save ('out.png')
Basically, one random pixel of the walnut and looking for the best match. This is a first step with not too bad an output:
What you still want to do is:
Increase the sample space (not only using one pixel, but maybe 10 or
20).
Not only check the best match, but the best 10 matches for
instance.
EDIT 2: Some improvements
#! /usr/bin/python2.7
import random
import sys
from PIL import Image, ImageDraw
im, pattern, samples = sys.argv [1:]
samples = int (samples)
im = Image.open (im)
walnut = Image.open (pattern)
pixels = []
while len (pixels) < samples:
x = random.randint (0, walnut.size [0] - 1)
y = random.randint (0, walnut.size [1] - 1)
pixel = walnut.getpixel ( (x, y) )
if pixel [-1] > 200:
pixels.append ( ( (x, y), pixel [:-1] ) )
def diff (a, b):
return sum ( (a - b) ** 2 for a, b in zip (a, b) )
best = []
for x in range (im.size [0] ):
for y in range (im.size [1] ):
d = 0
for coor, pixel in pixels:
try:
ipixel = im.getpixel ( (x + coor [0], y + coor [1] ) )
d += diff (ipixel, pixel)
except IndexError:
d += 256 ** 2 * 3
best.append ( (d, x, y) )
best.sort (key = lambda x: x [0] )
best = best [:3]
draw = ImageDraw.Draw (im)
for best in best:
x, y = best [1:]
draw.rectangle ( (x, y, x + walnut.size [0], y + walnut.size [1] ), outline = 'red')
im.save ('out.png')
Running this with scriptname.py image.png walnut.png 5 yields for instance:

RGB to HSV conversion using PIL

I'm trying to automate the enhancement of some images that are to be transfered to a digital frame. I have code in place that resizes, adds a date/time to the least-significant (least details) corner of the image and pastes together pairs of portrait images to avoid displaying a single portrait in the frame's 41:20 low resolution screen.
I've implemented a brightness-stretching filter for those pictures where the lighting wasn't so good, using the colorsys.rgb_to_hsv function to calculate H, S, V bands, operating on the V one and then converting back to RGB before saving a JPEG in the digital frame. Obviously, the conversion takes a lot of time, even using itertools tricks; I managed to improve things using psyco.
However, I noticed an example for the PIL Image.convert where RGB can be converted to XYZ color space using a 4×4 matrix as a second argument to the convert method, and I got to wonder:
How can I convert RGB to HSV (and then HSV back to RGB) using a custom matrix in the convert method call? (Minor rounding errors are not important in this case, so I don't mind that each band will be expressed as a series of 0…255 integers)
Thank you in advance.
Although I've seen references[1] that claim HSV color-space is linear transformation from RGB, which would seem to imply that it could be done with a matrix, I have been unable to find or determine for myself just what such a matrix would look like. In a way this doesn't really surprise me based on all the [similar] non-matrix procedural implementations I've also seen -- the way they go about it doesn't look linear.
Anyway, while looking into this, I ran across a [somewhat dated] article in former SGI researcher Paul Haeberli's online computer graphics notebook titled Matrix Operations for Image Processing which describes how to do a number of different color transformations using 4x4 matrices which might help you. All of the examples given operate directly on RGB color images and, like geometric matrix transformations, any sequence of them can be combined into a single matrix using concatenation.
Hope this helps.
[1]: Colour Space Conversions <http://www.poynton.com/PDFs/coloureq.pdf>:
2.7.3 HSL (Hue Saturation and Lightness)
This represents a wealth of similar
colour spaces, alternative names
include HSI (intensity), HSV (value),
HCI (chroma / colourfulness), HVC,
TSD (hue saturation and darkness) etc.
Most of these colour spaces are
linear transforms from RGB and are
therefore device dependent and
non–linear. Their advantage lies in
the extremely intuitive manner of
specifying colour. It is very easy to
select a desired hue and to then
modify it slightly by adjustment of
its saturation and intensity.
The formula to transform an RGB value to an HSV value can be found here: http://www.rapidtables.com/convert/color/rgb-to-hsv.htm. I once needed it the other way around, and made the following function for it.
def hsb2rgb(hsb):
'''
Transforms a hsb array to the corresponding rgb tuple
In: hsb = array of three ints (h between 0 and 360, s and v between 0 and 100)
Out: rgb = array of three ints (between 0 and 255)
'''
H = float(hsb[0] / 360.0)
S = float(hsb[1] / 100.0)
B = float(hsb[2] / 100.0)
if (S == 0):
R = int(round(B * 255))
G = int(round(B * 255))
B = int(round(B * 255))
else:
var_h = H * 6
if (var_h == 6):
var_h = 0 # H must be < 1
var_i = int(var_h)
var_1 = B * (1 - S)
var_2 = B * (1 - S * (var_h - var_i))
var_3 = B * (1 - S * (1 - (var_h - var_i)))
if (var_i == 0):
var_r = B ; var_g = var_3 ; var_b = var_1
elif (var_i == 1):
var_r = var_2 ; var_g = B ; var_b = var_1
elif (var_i == 2):
var_r = var_1 ; var_g = B ; var_b = var_3
elif (var_i == 3):
var_r = var_1 ; var_g = var_2 ; var_b = B
elif (var_i == 4):
var_r = var_3 ; var_g = var_1 ; var_b = B
else:
var_r = B ; var_g = var_1 ; var_b = var_2
R = int(round(var_r * 255))
G = int(round(var_g * 255))
B = int(round(var_b * 255))
return [R, G, B]

Categories