Homework 29
Due Wednesday April 24
Module mash.py
- Supports the creation of a new image that is a mash up of two existing images —
bg
andfg
. The new image hasbg
as its background. The pixels infg
that are dissimilar to the back screen color are copied on top of the background.
Downloads
- Module mash.py
- Tester smashing.py
- Used by module
mash
for some simple holistic testing of its capabilities.
Primary function (already written)
combine( bg, fg, sx, sy, back_screen )
- Returns mash up of background image
bg
and foreground imagefg
, where the pixels infg
that are dissimilar toback_screen
are copied on top of the background.
- The mash up uses location
(sx, sy)
as the spot in the background to start the lay over offg
.
Convenience functions to be written
similar( p1, p2, max_allowable=THRESHOLD )
- Returns whether the distance between pixels
p1
andp2
is less than the max allowable threshold.
is_background( p, back_screen )
- Returns whether
p
is similar to theback_screen
color.
inbounds( spot, img )
- Returns whether
spot
lies onimg
; that is whether the x-value and y-value forspot
are nonnegative, the x-value is less thanimg
width, and the y-value is less thanimg
height.
colorable( spot, img, p, back_screen )
- Returns whether both
spot
is a location onimg
and colorp
is not similar to colorback_screen
.
Already written convenience functions
distance( p1, p2 )
- Returns the RGB difference between colors
p1
andp2
.
clean_up( original, back_screen )
- Returns a new copy of the
original
, where those pixels inoriginal
similar to colorback_screen
are replaced byback_screen
.