Class 33 — Wednesday April 21
Chrestomatics and patterning
I draw from the past – Wonder about the present – Think of the future
Look both ways
Agenda
- Problem solving
- Image manipulation
Downloads
- Module mirror.py
- Homework flip.py
- Homework grey.py
- Future homework palette.py
Photo-manipulation Python code
- Create a new image by making a copy that tweaks the original image
# get dimensions of the original
ow, oh = original.size
# set dimensions of the new image
nw, nh = size( original )
# create new appropriately sized image
new_image = Image.new( 'RGB', ( nw, nh ) )
# fill in every pixel of the new image
for nx in range( 0, nw ) : # consider every x value for the new image
for ny in range( 0, nh ) : # in tandem with every y value for the image
# set the spot to be filled in the new image
nspot = ( nx, ny )
# determine corresponding spot of interest in the original
ospot = where( nspot, nw, nh )
# get the pixel at the ospot
opixel = original.getpixel( ospot )
# determine the pixel for the new image
npixel = color( opixel )
# set the pixel at nspot in the new image
new_image.putpixel( nspot, npixel )
# return the filled in new image
return new_image
Module mirror.py
- Function
mirror( nspot, nw, nh )
- Returns the correspondent of
nspot
in thenw
xnh
the unmirrored original.
|
Module grey.py
- Function
grey( opixel )
- Returns the correspondent of
nspot
in thenw
xnh
the unflipped original.
|
Module flip.py
- Function
flip( nspot, nw,nh )
- Returns the correspondent of
nspot
in thenw
xnh
the unflipped original.
|
Module palette.py
- Function
distance( p1, p2 )
- Returns the distance between pixels
p1
andp2
.
- Function
closest( opixel )
- Returns the pixel in the pixel-list
PALETTE
that is closest toopixel
Function set_palette( p )
- Sets global
PALETTE
to pixel-listp
.
Global variable
PALETTE
- List of possible pixels for use in palette reduction
|
🦆 © 2022 Jim Cohoon | Resources from previous semesters are available. |