Question

In: Computer Science

Python: Write the function pixelLuminance that takes 3 integers r, g, and b, each between 0...

Python: Write the function pixelLuminance that takes 3 integers r, g, and b, each between 0 and 255 (inclusive), representing the red, green, and blue intensity of a pixel and returns the luminance of this pixel as an integer. The function expects each parameter r, g, and b to be an integer in the interval [0,255]. You should use assertions to enforce this constraint.

Solutions

Expert Solution

Thanks for the question.

Below is the code you will be needing  Let me know if you have any doubts or if you need anything to change.

Thank You !!

===========================================================================

# formula => luminance = (r * 0.3) + (g * 0.59) + (b * 0.11)

def pixelLuminance (r,g,b):
    assert 0<=r and r<=255
    assert 0<=g and g<=255
    assert 0<=b and b<=255
    return (r * 0.3) + (g * 0.59) + (b * 0.11)


print(pixelLuminance(0,0,0))
print(pixelLuminance(255,255,255))
print(pixelLuminance(128,128,128))
try:
    print(pixelLuminance(255,80,1000))
except AssertionError:
    print('Invalid input')


Related Solutions

Write a Python function that takes a list of integers as a parameter and returns the...
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
Write a Python function that takes a list of integers as a parameter and returns the...
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
USING PYTHON, write a function that takes a list of integers as input and returns a...
USING PYTHON, write a function that takes a list of integers as input and returns a list with only the even numbers in descending order (Largest to smallest) Example: Input list: [1,6,3,8,2,5] List returned: [8, 6, 2]. DO NOT use any special or built in functions like append, reverse etc.
Write a function that takes three integers, n, a and b and a filename and writes...
Write a function that takes three integers, n, a and b and a filename and writes to the file a list with n random integers between a and b. And then write a function that can read the files as generated above and return the values. language: python
Python: Accumulator pattern and conditionals. Write a function play that takes integers rounds and sides and...
Python: Accumulator pattern and conditionals. Write a function play that takes integers rounds and sides and does the following  Plays round number of rounds, rolling two s-sided dice per round (use roll).  Uses the previous functions to calculate the score of each round  Prints out the dice rolls and the score for each round  Accumulates the score over all rounds  Returns the final score over all rounds. *Write a function result that takes an arguments...
Python : Write the function inAWhile that takes two integers t and d, where t is...
Python : Write the function inAWhile that takes two integers t and d, where t is the present time on a 12-hour clock, rounded to an integer (so t is an integer in the interval [1,12]) and d is an integer increment in hours, and returns the time on a 12-hour clock in d hours. For example, in 2 hours from 3 o’clock, it will be 5 o’clock, so inAWhile (3, 2) = 5. Notice that 12 is followed by...
In Python, write a function one_bit_NOT that takes one argument, a character that is either '0'...
In Python, write a function one_bit_NOT that takes one argument, a character that is either '0' or '1'. It should perform the NOT operation and return a string with a single character as the result. I.e., if the character argument is "0", it returns a "1"'. If the character argument is "1", it returns a "0".
Python Problem 3 Write a function named enterNewPassword. This function takes no parameters. It prompts the...
Python Problem 3 Write a function named enterNewPassword. This function takes no parameters. It prompts the user to enter a password until the entered password has 8-15 characters, including at least one digit. Tell the user whenever a password fails one or both of these tests.
Write a Scheme function that takes a list of integers and returns all odd integers on...
Write a Scheme function that takes a list of integers and returns all odd integers on the list in the original order: (odd-numbers `(2 4 9 16 25 7)) (9 25 7) Hint: 2 (remainder 13 5) 3 Please explain every step
Python: Write a function that receives a one dimensional array of integers and returns a Python...
Python: Write a function that receives a one dimensional array of integers and returns a Python tuple with two values - minimum and maximum values in the input array. You may assume that the input array will contain only integers and will have at least one element. You do not need to check for those conditions. Restrictions: No built-in Python data structures are allowed (lists, dictionaries etc). OK to use a Python tuple to store and return the result. Below...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT