Assignment 30 — image manipulation
Due Friday, April 17
Downloads
- Module gray.py
- Module palette.py
- Module cw.py
Clockwise rotation — module gray.py
- Your task is to implement two functions
color()
to support producing a grayscaling of an image.
| |
- Function
color( opixel )
- Returns a new pixel whose RGB values are
(m, m, m)
wherem
is is the integer cast of.299r + .587g + .114b
, wherer
,g
, andb
are the RGB values ofopixel
.
- The module has built-in testing using a mandrill image.
Clockwise rotation — module cw.py
- Your task is to implement two functions
size()
andwhere()
to support producing a clockwise rotation of an image.
| |
- Function
size( original )
- Returns the dimensions of an image that would be a clockwise rotation of
original
.
- Function
where( nspot, original )
- Return the correspondent of spot
nspot
in theoriginal
image when doing a clockwise transformation
- The module has built-in testing using a mandrill image.
Palette reduction — module palette.py
- Your task is to implement functions
distance()
andcolor()
. Before defining their purposes, first some context.
| |
- Sometimes to save computer memory, software developers perform a palette reduction of colors used in image representation.
- Our reduction scheme will use an eight-color palette
- Black, White, Red, Green, Blue, Yellow, Magenta, and Cyan; that is,
(0,0,0), (255,255,255), (255,0,0), (0,255,0), (0,0,255), (255,255,0), (255,0,255),
and(0,255,255)
- In a palette reduction, a pixel
(r,g,b)
is replaced by the pixel in in the palette it is closest to. The distance between pixels(r1,g1,b1)
and(r2,g2,b2)
equals
abs(r1 - r2) + abs(g1 - g2) + abs(b1 - b2)
- Note there is built-in function
abs()
for calculating absolute values.
- Function
distance( p1, p2 )
- Returns the distance between pixels
p1
andp2
; that is the sum of the red differences, green differences, and blue differences, where difference is an absolute value.
- Function
color( opixel )
- Make use of the color palette
PALETTE8
PALETTE8 = [ ( 0, 0, 0), (255,255,255), ( 0,255, 0), ( 0, 0,255),
(255, 0, 0), (255,255, 0), (255, 0,255), ( 0,255,255) ]
- Returns the pixel in
PALETTE8
thatopixel
is closest to
- The module has built-in testing using a mandrill image.
© 2020 Jim Cohoon | Resources from previous semesters are available. |