Sp 2003 Midterm Review #1
Below are questions like those I plan to ask on Midterm #1 (Feb. 5). The exam will consist of 4 or 5 questions like these.
Please do try these questions! Post your answers, questions, comments, concerns, and criticisms on the pages for each question. Those comments, questions, etc. can also be about each others' answers! If someone posts an answer that you don't understand, ask about it! If you see a question here that you know the answer to, don't keep it to yourself – help your fellow students!
I will be reading your answers. Here are the ground rules for the interaction.
- If you don't post, neither will I. I will not be posting official solutions to these problems at all! If one of you gets it right, terrific!
- I will try to always point out if an answer is wrong. I won't always point out when the answer is right.
- I am glad to work with you toward the right answer. I will give hints, and I'm glad to respond to partial guesses.
Generalized changeRed
Write a new version of the function increaseRed and decreaseRed called changeRed that takes as input a picture AND an amount to increase or decrease red by. That amount will be a number between -.99 and .99.
- changeRed(pict,-.10) should decrease the amount of red in the picture by 10%.
- changeRed(pict,.30) should increase the amount of red in the picture by 30%
- changeRed(pict,0) should do nothing at all the amount of red in the picture.
def increaseRed(pict):
for p in getPixels(pict):
setRed(p,getRed(p)*1.2)
def decreaseRed(pict):
for p in getPixels(pict):
setRed(p,getRed(p)*.80)
Questions, comments, and answers for Midterm Exam 1 Review Spring 2003: Generalized changeRed
Generalized image filter
Now go one step further. Write a function changeRGB that takes four inputs: A picture, and an amount to change the red, green, and blue (in that order) pixels. Each amount should be between -.99 and +.99.
Thus, Homework 1 would just be:
changeRGB(picture,-.75,.25,-.25)
Questions, comments, and answers for Midterm Exam 1 Review Spring 2003: Generalized image filter
What does it mean?
- What does def mean? What does the statement def someFunction(x,y): do?
- What does for mean? What does the statement for x in range(1,5): do?
- What does print mean? What does the statement print a do?
Questions, comments, and answers for Midterm Exam 1 Review Spring 2003: What does it mean?
Which does which?
Which of the recipes below takes a picture and removes all the blue from every pixel of that picture that already has a blue value of more than 100?
1. A only
2. D only
3. B and C
4. C and D
5. None
6. All
What do the other ones do?
A.
def blueOneHundred(picture):
for x in range(1,100):
for y in range(1,100):
pixel = getPixel(picture,x,y)
setBlue(pixel,100)
B.
def removeBlue(picture):
for p in getPixels(picture):
if getBlue(p) > 0:
setBlue(p,100)
C.
def noBlue(picture):
blue = makeColor(0,0,100)
for p in getPixels(picture):
color = getColor(p)
if distance(color,blue) > 100:
setBlue(p,0)
D.
def byeByeBlue(picture):
for p in getPixels(picture):
if getBlue(p) > 100:
setBlue(p,0)
Questions, comments, and answers for Midterm Exam 1 Review Spring 2003: Which does which
Increase the volume, stepped
Write a function increaseVolumeStepped that takes a sound as input:
- In the first third of the sound, decrease the volume by 50%.
- In the middle third of the sound, increase the volume by 20%.
- In the last third of the sound, normalize the sound (normalize ONLY across the last third of the sound.)
Questions, comments, and answers for Midterm Exam 1 Review Spring 2003: Increase the volume, stepped #2
Check your luminance
Write a program checkLuminance that will input red, green, and blue values, and compute the luminance using the weighted average (as below). But then, print out a warning to the user based on the computed luminance:
| If the luminance is... | Print out the statment... |
| Less then 10 | "That's going to be awfully dark" |
| Between 50 and 200 | "Looks like a good range" |
| Over 250 | "That's going to be nearly white" |
def greyScaleNew(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
setColor(px,makeColor(luminance,luminance,luminance))
Questions, comments, and answers for Midterm Exam 1 Review Spring 2003: Check your luminance
Sound concepts
- What does a fourier transform (FFT) show you?
- What is the Nyquist theorem? Why can't you hear CD music well over a telephone?
- How does the amplitude of the sound impact our sensation of the sound?
Questions, comments, and answers for Midterm Exam 1 Review Spring 2003: Sound concepts
Picture concepts
- Why don't we see red, green, and blue spots at each position in our picture?
- What is luminance?
- Assume an RGB color model with 8 bits per each color component. How much more memory is required to display a 1024x768 monitor image compared to a 320x240 cheap digital picture image?
Questions, comments, and answers for Midterm Exam 1 Review Spring 2003: Picture concepts
CS concepts
- What is sampling?
- What's the difference between an array and a matrix? Which is a sound and which is a picture?
- What's an encoding?
Questions, comments, and answers for save #5
What gets printed?
Consider the below program:
def testme(p,q,r):
if q > 50:
print r
value = 10
for i in range(1,p):
print "Hello"
value = value - 1
print value
print r
If we execute testme(5,51,"Hello back to you!"), what will print?
Hint: DON'T TRY IT IN JES! Try to figure it out by walking through the code. On the exam, you will NOT have access to JES.
Questions, comments, and answers for Midterm Exam 1 Review Spring 2003: What gets printed
Manipulate an array
Write a function dup100 to input a sound filename and return the sound where the first 100 samples are duplicated. Let's say that the original sound's samples look like this for the first five samples "54,62,-13,-2,4..." Then the output sound's first ten samples should look like this "54,54,62,62,-13,-13,-2,-2,4,4..." Thus, the output's first 200 samples will be different from the original (the first 100 duplicated), but the rest of the samples will be the same.
Questions, comments, and answers for Midterm Exam 1 Review Spring 2003: Manipulate an array #2
Compute pay rates
Write a function called pay that takes in as input a number of hours worked and the hourly rate to be paid. Compute the gross pay as the hours * the rate. But then compute a tax.
| If the pay is... | Charge a tax of... |
| < 100 | .25 |
| >= 200 and <300 | .35 |
| >=300 and <400 | .45 |
| >=400 | .50 |
Compute the taxed amount as tax rate * gross pay.
Print the gross pay and the net pay (gross - tax).
Questions, comments, and answers for Midterm Exam 1 Review Spring 2003: Compute the pay rate
Links to this Page