Class 33 — November 8
Image visualization
What do you picture – For your future life to be – We wish you success
Look both ways
Video
- Quick attempt: image manipulation
Agenda
- Image transformations
Example
- Module manip.py
- Supports several common image transformations – duplicating, mirroring, flipping, rotating, scaling, and pixelation. Except for the pixelation transformation, all of the transformations copy values from the original image into the transformation.
- See documentation for transform specifications.
- Note:
manip.py
supports limited self-testing
- Questions to ask yourself before attempting the transformations:
- How do the dimensions of the transformation compare with the original?
- What is the correspondence between the pixels from the transformation with pixels from the original?
- Problem solving pattern
# get dimensions of the original
ow, oh = original.size
# set dimensions of the copy
nw, nh = ..., ...
# 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 in the original to be copied
ox = ...
oy = ...
ospot = ( ox, oy )
# get the pixel at the ospot
opixel = original.getpixel( ospot )
# determine the pixel for the new image
npixel = ...
# set the nspot in the new image
new_image.putpixel( nspot, npixel )
# return the filled in new image
return new_image
To do
- Review gray.py artifact
- Review imaging epistle
Transformations
Duplicated image | |
Mirrored image | |
Flipped image | |
Clockwise rotation | |
scale with xfactor = 2.0 and yfactor = 2.0 | |
scale with xfactor = 0.5 and yfactor = 0.5 | |
scale with xfactor = 0.5 and yfactor = 2.0 | |
scale with xfactor = 2.0 and yfactor = 0.5 | |
pixelation |