Change Contents of the Bubble
Welcome to CS1315. Click on the python to add comments.

Looking for the book? They have it at the Engineer's Bookstore at 748 Marietta St NW. Here is there website: http://www.engrbookstore.com/ - Monica

Hotspots: Slides and CodeTA CornerComments?AnnouncementsFAQStatic Webspace
View this PageEdit this Page (locked)Uploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Midterm Exam 1 Review Spring 2004: Check your luminance

(Return to Sp2004 Midterm 1 Review)

Questions, answers, comments on answers, comments on questions?



This is Paula Verden.
My question is are we suppose to use part of the greyscale reciepe in our new recipe for luminance.

Yes – use the same calculation for luminance as what's provided in this function. But your function will input red, green, and blue, like this: def checkLuminance(red, green, blue):. Mark Guzdial


Amelia Cipolla
How is this done without the input of a picture?  what do you do if you cant say
for p in getPixels(picture)??
what is your "for" statement?

this is what i have

def checkLuminance(picture, red, green, blue):
  for p in getPixels(picture):
    newRed=getRed(p)*0.299
    newGreen=getGreen(p)*0.587
    newBlue=getBlue(p)0.114
    luminance=newRed+newGreen+newBlue
    setColor=(p, makeColor(luminance,luminance,luminance)
    if luminance < 10:
      print "That's going to be awfully dark"
    if luminance >49 adn < 201:
      print "Looks like a good range"
    if luminance >250:
      print "That's going to be nearly white"

So you are saying there is no picture input, no reference to pixels.  so is this what you want?--

def checkLuminance(red, green, blue):
  redvalue=red*0.299
  greenvalue=green*0.587
  bluevalue=blue*0.114
  luminance=redvalue+greenvalue+bluevalue
  if luminance < 10:
    print "That's going to be awfully dark"
  if luminance >49 adn < 201:
    print "Looks like a good range"
  if luminance >250:
    print "That's going to be nearly white"



 


You don't need to have the input of a picture because all you're doing is looking at a red value, a green value, and a blue value. Write it as a function that could be used outside of the context of a picture. Say, for instance, that somebody else was working on a program to change a picture to greyscale. They don't want to worry about the luminace, though. They want you to write a function that will do that for them. They'll call it every time they look at a pixel in their picture. All they'll give you is the RGB value and they want the luminance back (Plus a little warning about the visibility). Adam Wilson

Catherine Covington Is this code clear or am I missing something?

def checkLuminance(red, green, blue):
for px in getPixels(picture):
newRed = getRed(px) 0.299
newGreen = getGreen(px) 0.587
newBlue = getBlue(px) 0.114
luminance = newRed+newGreen+newBlue
setColor(px,makeColor(luminance,luminance,luminance))

if(luminance <10):
print "That's going to be awfully dark"
if(luminance >50 and luminance <201):
print "Looks like a good range"
if(luminance >250):
print "That's going to be nearly white"

It's clear, Catherine, but you're trying to do too much. Where does the value of 'picture' come from? Look at Amelia's second code example above. Colin Potts
How do you think the program would be different if the Amelia's second code example read luminance=int(redvalue+greenvalue+bluevalue)? Mark Guzdial

def checkLuminance(picture):
  for px in getPixels(picture):
    newRed = getRed(px)*0.299
    newGreen = getGreen(px)*0.587
    newBlue = getBlue(px)* 0.114
    luminance = newRed+newGreen+newBlue
    print luminance
    if luminance<10:
      print "That's going to be awfully dark"
    if 50250:
      print "That's going to be nearly white"

Margaret McIntosh is this right?
You're on the right track, but your program needs to take color values as inputs, not a picture...

Amy Howard
def checkLuminance(red, green, blue):
	newRed = red*.299
	newGreen = green * .587
	newBlue = blue*.114
	luminance = newRed + newGreen + newBlue
	if luminance < 10:
		print "That's going to be awfully dark"
	if 50 < luminance < 200:
		print "Looks like a good range"
	if luminance > 250:
		print "That's going to be nearly white"


Amelia Cipolla
Is it wrong that in my second example I do not refer to any pixels??? (like getRed(p))???
You might need to check the luminance of a color for other reasons than probing pixels in a picture. Suppose checkLuminance was part of an interior design application that let a user choose wall or carpet colors. This function might be a useful sanity check for color values that a user might regret. (Okay, this example may not be good design aesthetics, but you get the idea...) Colin Potts

Lindsey Richardson

Am I on the right track?
def checkLuminance(red, green, blue):
    redValue = red * 0.299
    greenValue = green * 0.587
    blueValue = blue  0.114
    luminance = redValue + greenValue + blueValue
    if(luminance < 10):
      print "That's going to be awfully dark."
    if(luminance >= 50 and luminance <=200):
      print "Looks like a good range."
    if(luminance >250):
      print "That's going to be nearly white." 


That looks good, also check FAQ for how to format code on Coweb.
When you have to say that between 50 and 200 "looks like a good range," are you supposed to say 50 = luminance = 200, or 50 luminance 200? In general, what makes the difference in when you include the numbers at each end or not?

daniel goers
def checkLuminance(R,G,B):
newRed = R 0.299
newGreen = G 0.587
newBlue = B 0.114
luminance = newRed+newGreen+newBlue
if luminance 10:
print "That's going to be awfully dark"
if luminance < 200 and luminance > 50:
print "Looks like a good range"
if luminance > 250:
print "That's going to be nearly white"

Check the indentation and content of your first 'if' statement. Colin Potts
I think I"ve got it right...I have:
def checkLuminance(red, green,blue):
   redvalue=green*0.299
   greenvalue=gree*0.587
   bluevalue=blue*0.114
   luminance=redvalue+greenvalue+bluevalue
   if(luminance<10):
      print "That's going to be awfully dark."
   if(luminance>=50 and luminance<=200):
      print "Looks like a good range"
   if(luminance>250):
      print "That's going to be nearly white"

I have a feeling my spacing is going to be incorrect, but it's correct in JES
Kyla LeCroy
Spacing would be right here, too, if one would read and follow the directions on the FAQ...:-) Mark Guzdial
I am little confused with the statement "between 50 and 200." Does this mean that 50 and 200 are included? Or, are they excluded? Also, would you write "50 < luminance < 200" or would you write "if luminance > 50 and luminance 200" ???
poof #2

Lauren, this isn't really anything to worry about. If there is a is a problem like this on the midterm, it will be clear whether the numbers are inclusive or the numbers should not include the endpoints. Greg Leo



Link to this Page