Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

5, (20%) In Python, RGB colors are expressed in three-element arrays. For exampl

ID: 3732515 • Letter: 5

Question

5, (20%) In Python, RGB colors are expressed in three-element arrays. For example, [1.0, 0.0, 0.0] is red, [0.0, 1.0, 0.0] is green, [o.0, 0.5, 0.5] is sort of bluish-green, and [1.0, 1.0, 1.0] is white. Let's estimate an RGB color for a spectrum by integrating the flux of wavelengths corresponding to red, green, and blue. Those integrals will represent the brightness in each of the three RGB colors; when mixed together they would reproduce the visual appearance of the color an object would have. The fluxes integrated over the three RGB ranges would be: 660mm I2 eSum (da Jasam (w)dw 400m wd 565m 570nm 490mm Write a Python function called estimateRGB, that accepts wavelength and flux arrays of a spectrum and returns an RGB color. The start of this function is outlined here:

Explanation / Answer

import numpy as np
import scipy.integrate as integrate
import scipy.special as special


# Normalize data
def normalize(v):
    norm = np.linalg.norm(v)
    if norm == 0:
       return v
    return v / norm

############################################################
# Change this function. Update with the function for the flux
def fluxes(x, a, b):
    f = a*x**2 + b # function to be integrated...dummy function f(x)=a*x^2+b is taken as example
                   # change this line and put the exact function for flux/radiant etc that determines the intensity
    return f


#############################################################
# The required function
def estimateRGB(wavelengths, fluxes):
a=1 # dummy parameter...change the value of the parameter
b=1 # dummy parameter...change the value of the parameter
r = integrate.quad(fluxes, wavelengths[0], wavelengths[1], args=(a,b))
#print r[0]

g = integrate.quad(fluxes, wavelengths[2], wavelengths[3], args=(a,b))
#print g[0]

b = integrate.quad(fluxes, wavelengths[4], wavelengths[5], args=(a,b))
#print b[0]

RGB = [r[0],g[0],b[0]]

RGB = normalize(RGB)

return RGB

# Main Program

wavelengths=np.array([565, 660, 485, 570, 400, 490])
RGB=estimateRGB(wavelengths, fluxes)
print RGB

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote