Class 40 — Wednesday, April 27
Chrestomatics and patterning
Itβs simply smashing β For visitors on the Lawn β If they watch their steps
Look both ways
Agenda
- Problem solving
- Image manipulation
To do
- Complete Rachel's feedback form
- More fun with images
Downloads
- Module image_fx.py
- Module half_flip.py
- Module noisify.py
- Module manip.py
Photo-manipulation Python code
- Review: Create a new image by making a copy that tweaks the original image's size, color, or pixel locations
def manip( original, size=same_size, color=same_color, at=same_at ) :
""" Tweaks the original image. The tweaking is governed by
function size(): Determines new image size based on the original.
The default is the same size
function color(): Determines pixelation based on the original pixel.
The default is the same color
function at(): Determines orignal source location.
The default is the same spot
"""
# set dimensions of the new image
nw, nh =
size( original )
# get a 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 the corresponding spot of interest in the original
ospot =
at( 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 nspot in the new image
new_image.putpixel( nspot, npixel )
# return the filled in new image
return new_image
Module image_fx.py
- Function
brighten( opixel )
- Returns the twice-as-bright new color of
opixel
from the full-color original.
|
Module image_fx.py
- Function
darken( opixel )
- Returns the twice-as-dark new color of
opixel
from the full-color original.
|
Module image_fx.py
- Function
sepia( opixel )
- Returns the sepia-tone new color of
opixel
from the full-color original.
|
Module half_flip.py
- Function
half_flip( nspot, nw, nh )
- Returns the correspondent of
nspot
in thenw
xnh
un-half-flipped original.
|
Module noisify.py
- Function
noise( opixel )
- Returns the additive-noise-version of the new color of
opixel
from the full-color original.
|
π¦ © 2022 Jim Cohoon | Resources from previous semesters are available. |