Exercise #3 o Write a program averageLuminance(picture) which takes as input a picture uses functional programming to calculate the average luminance of the picture’s pixels. Use the helper function   def luminance(pixel): r = getRed(pixel) g = getGreen(pixel) b = getBlue(pixxel) y = 0.2126 * r + 0.7152 * g + 0.0722 * b return y Within your main program, use map and luminance to create a list of luminances from the list of pixels. This is an example answer to help you formulate an answer for the question above: # Exercise 3 def isDocument(fileName): listOfEndings = [ ".docx", ".txt", ".rtf" ] for ending in listOfEndings: if fileName.endswith(ending): return True return False def recursiveListDocuments(directory=os.getcwd()): files = os.listdir(os.path.normpath(directory)) for file in files: fileName = os.path.normpath(directory + "/" + file) if isDirectory(fileName): recursiveListDocuments(fileName) else: if isDocument(fileName): print fileName

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter6: User-defined Functions
Section: Chapter Questions
Problem 17PE
icon
Related questions
Question

Exercise #3

o Write a program averageLuminance(picture) which takes as input a picture uses functional programming to calculate the average luminance of the picture’s pixels.

Use the helper function  

def luminance(pixel):

r = getRed(pixel)

g = getGreen(pixel)

b = getBlue(pixxel)

y = 0.2126 * r + 0.7152 * g + 0.0722 * b

return y

Within your main program, use map and luminance to create a list of luminances from the list of pixels.

This is an example answer to help you formulate an answer for the question above:

# Exercise 3 def isDocument(fileName): listOfEndings = [ ".docx", ".txt", ".rtf" ] for ending in listOfEndings: if fileName.endswith(ending): return True return False def recursiveListDocuments(directory=os.getcwd()): files = os.listdir(os.path.normpath(directory)) for file in files: fileName = os.path.normpath(directory + "/" + file) if isDirectory(fileName): recursiveListDocuments(fileName) else: if isDocument(fileName): print fileName

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Hiring Problem
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning