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 Fall 2004: Check your luminance

Post your answers, questions, comments, comments on answers, suggestions, suggestions on questions, etc.

Back to Fall2004 Midterm 1 Review


will this work ok?:
def checkLuminance(r,g,b):
Red=r0.229
Green=g0.587
Blue=b0.114
lum=Red+Green+Blue
if lum10:
print"that's going to be awfully dark"
if lum>=10 or =50:
print "a little dark..."
if 50>lum200:
print "looks like a great range"
if lum>=200 and 250:
print "getting kinda bright"
if lum>=250:
print"That's going to be nearly white"

I know that there's an error on the line that reads if lum 10: There's something missing. Can you find it? Kelly Lyons

ahhh...if lum10:
got it.
thanks kelly

Try typing > for a greater-than sign and $amp;lt; for a less-than sign. (See FAQ) Mark Guzdial


The if statements work if i put a number is less than luminance is less than another number, and the code does not have to set the computed luminance, just label the range it falls into, right?

I'm not sure what you're getting at here. Write out the code of what you're explaining and I could better answer your question. But in general, try it in JES, and if it works in JES, then it works. Kelly Lyons

def checkLuminance(r,g,b):
Red = r 0.299
Green = g 0.587
Blue = b 0.114
luminance = Red+Green+Blue
if luminance 10:
print "That's going to be awfully dark"
if luminance >=10 and luminance =50:
print "A little dark..."
if luminance >50 and luminance 250:
print "Looks like a good range"
if luminance >=250:
print "That's going to be nearly white"


where did the values 0.299, 0.587, and 0.114 come from?
From the book, the lecture slides, and from class. It's just a way of doing a grayscale that is more appropriate to how we actually see than a simple average becuase humans perceive some colors as brighter than others. Kelly Lyons

def checkLuminance(picture):
for px in getPixels(picture):
newRed = getRed(px).299
newGreen = getGreen(px).587
newBlue = getBlue(px).114
luminance = newRed+newGreen+newBlue
if luminance10:
print "Thant's going to be awfully dark"
if luminance>=10 and luminance=50:
print "A little dark..."
if luminance >50 and luminance 200:
print "Looks like a good range"
if luminance>=200 and luminance=250:
print "Getting kinda bright"
if luminance>=250:
print "That's going to be nearly white"

The input is incorrect. Reread the question. Kelly Lyons


I know in my answer above, it looks like there's no sign in the seventh line, but on the edit page it's there....that's wierd
Please refer to the FAQ on how to edit the swiki to fix this problem. You can also find the information under the help menu. It is in fact not weird at all. Some characters are special and mean things, like an asterisk means create new page, so if you type one, it won't show up on the page unless you tell the swiki to ignore it's specal meaning. The same idea goes for the less than sign Kelly Lyons

def checkLuminance(pic):
for px in getPixels(pic):
if luminance 10
print "That's going to be awfully dark"
if lumance >=10 and luminance 20
print "A little dark..."
if luminance > 50 and luminance 200
print "Looks like a good range."
if luminance >=200 and luminance 250
print "getting kinda bright"
if luminance >=250
print "That's going to be nearly white"
But how you you know what the luminance is? You never define it. Also, the function is not supposed to take a picture as input. Kelly Lyons


How about this?

def checkLuminance(pic):
for px in getPixels(pic):
r=getRed(px)0.299
g=getGreen(px)0.587
b=getBlue(px)0.114
color = r+g+b
if color 10:
print "That's going to be awfully dark"
if color >= 10 and color = 50:
print "A little dark..."
if color > 50 and color 200:
print "Looks like a good range"
if color >= 200 and color 250:
print "Getting kinda bringt"
if color >= 250:
print "That's going to be nearly white"

should we use the "or" command in our if/than sentence for: "if the luminance is greater than or equal to 10 or less than or equal to 50" ? +O'Nisha Lawrence+
No, becuase then it would include all values, becuase 5 is less than or equal to 50 and 55 is greater than or equal to 10 so both will work even though they are not supposed to work. And should be used in these functions Kelly Lyons

def checkLuminance(picture): luminance = greyScaleNew(picture) if luminance < 10: print "That's going to be awfully dark" if luminance in range(10,51): print "A little dark..." if luminance in range(50, 200): print "Looks like a good range" if luminance in range(200, 250): print "Getting kinda bright." if luminance >= 250: print "That's going to be nearly white"

Are we allowed to call the greyScaleNew(picture) function since it was provided? Also, if we use ranges and the first term of the range is "greater than" (not greater than or equal) can we assume the values are all integers and use the next number, or no?
The above function is wrong since your input is supposed to consist of a red, green and blue value, and not a picture. Therefore you can assume that everything is integers becuase pixels cannot be decimal numbers. Also, you could call the greyScaleNew function, but since your function does not take in a picture and the greyScaleNew function does, it would not work. Kelly Lyons


def checkLuminance(picture):
luminance = greyScaleNew(picture)
if luminance 10:
print "That's going to be awfully dark"
if luminance in range(10,51):
print "A little dark..."
if luminance in range(50, 200):
print "Looks like a good range"
if luminance in range(200, 250):
print "Getting kinda bright."
if luminance >= 250:
print "That's going to be nearly white"

Are we allowed to call the greyScaleNew(picture) function since it was provided? Also, if we use ranges and the first term of the range is "greater than" (not greater than or equal) can we assume the values are all integers and use the next number, or no?



why would you want to use the greyScaleNew function. it does not do what we want. however it has information in it that can be useful for our goal. here is the code that i came up with:
def checkLuminance(r,g,b):
  newr = r * 0.299
  newg = g * 0.587
  newb = b * 0.114
  lum = newr+newg+newb
  if lum < 10:
    print 'That is going to be awfully dark'
  if lum >= 10 and lum <=50:
    print 'A little dark...'
  if lum > 50 and lum < 200:
    print 'Looks like a good range'
  if lum >= 200 and lum < 250:
    print 'Getting kinda bright'
  if lum >= 250:
    print 'thats going to be nearly white'




Link to this Page