![]() |
![]() |
|
home—info—labs—exams—hws
—D2L—MediaSamples/—breeze (snow day)—tutor/PIs
Due May.02 (Fri) 10:00 (hardcopy, and D2L)
04 (Sun) 23:59 on D2L;
bring hardcopy to the exam.
(10pts)
Write a function
(2pts) You can run the following test code; add at least one test-case of your own. (A test case requires both calling the function to get an actual-result, and an expected-result to compare against.)
# testCountSpaces : -> None # def testCountSpaces(): print( "Actual: " + str(countSpaces("a")) ) print( "Expect: " + str(0) ) print( "Actual: " + str(countSpaces("a ")) ) print( "Expect: " + str(1) ) print( "Actual: " + str(countSpaces("Radford University")) ) print( "Expect: " + str(1) ) # Add one additional test of your own, here. print( "Actual: " + str(countSpaces("")) ) print( "Expect: " + str(0) ) print( "Actual: " + str(countSpaces(" ")) ) print( "Expect: " + str(3) ) return None |
(38pts total) In this problem, we'll write a program to make a “green-screen” special effect. Note that you can get full credit for a later function, if it correctly calls/uses previous functions (presuming those earlier ones really did work correctly).
Reading: If you're the type who has been reading the book for an alternate view of the material, you've been reading §5.1 (Replacing Colors) and §5.4 (Blending Pictures). This homework problem is the same task as solved in §5.5 (Background Subtraction), except that we are requiring approaching with the specific functions below.
Although our code won't produce a convincing result (it's hard to get this automated!), there is an optional idea for improving your result below.
(2pts) Make sure you have a couple of images of size 640x480 on your H: drive, to use as backgrounds. (You presumably did this in lab41—creating images; mixing images; you can also look at links—sample images for some images.)
Rename your files to be of the form bg1-description.jpg and bg2-description.jpg1 (For example, “bg1-mountain.jpg”.)
Note: Casting even the slightest shadows on the background can degrade the effect! If using a brightly-colored sheet for the background, try to drape it w/o any wrinkles.
COLOR_TO_IGNORE = makeColor( someRedValue, someBlueValue, someGreenValue ) |
(0pts)
Be aware there is already a function called
JES Functions > Colors >
Self-understanding question:
determine the distance between
the
# fxColorAt : int, int, Picture, Picture -> Color # Given a foreground image `fg`, a background image `bg`, and an (x,y) location, # return the color to use in a “greenscreen” special-effect, as follows: # # If `fg`s color at that pixel is “close” to `COLOR_TO_IGNORE`, # then we'll ignore `fg` and instead return the color of the background at that location. # Otherwise, we'll return the color of `fg` at that location. # # def fxColorAt( x, y, foregroundImg, backgroundImg ): # your code here |
# fxRow : Picture, Picture, Picture, int -> None # Given a (presumably) new/blank picture `fxPict`, # along with a foreground `fg` and background `bg` and a row-number, # fill in that row of `fxPict` # so that each pixel has its color set as per our greenscreen effect. # # def fxRow( fxPict, fg, bg, rowNum ): # your code here |
# fx : Picture, Picture -> Picture # Given foreground `fg` and background `bg`, # return an entirely-new picture which has `fg` superimposed on `bg` # as per our greenscreen special effect. # # Pre-condition: `fg` and `bg` must be the same size (presumably 640x480). # def fx( fg, bg ): # your code here |
(For debugging/feedback, it's okay to
To submit: Bring a hardcopy of your code to class, and submit six files on D2L: your code plus five pictures, named as follows:
Note: Be sure to use the filenames with the non-olive-color parts exactly as described — I will have a script which automatically processes the solution, and will look for names of that form!
1 It's okay if you have a different file format — e.g. bg1-mountain.png instead of .jpg. This holds for all image-files for this homework. ↩
2you can do this in many common photo-processing programs, or even at various on-line websites. If you find a program/site you like, please share it on the discussion boards! ↩
3 We use all-caps to indicate that this “variable” is actually a named-constant. ↩
4 Super-challenge: Make a list of colors-to-ignore, and have your code loop through that list! For example:
IGNORABLES = ( makeColor(200,150,150), makeColor(140,200,140), magenta, makeColor(20,30,40) ) # the round-parens make this a list of four colors. for i in range( len(IGNORABLES) ): print( "Processing the color " + str(IGNORABLES[i]) ) |
home—info—labs—exams—hws
—D2L—MediaSamples/—breeze (snow day)—tutor/PIs
©2014, Ian Barland, Radford University Last modified 2014.May.05 (Mon) |
Please mail any suggestions (incl. typos, broken links) to ibarland ![]() |
![]() |