Class 32 — Monday April 19

Chrestomatics and patterning

I need a haiku — I can't think of one I like — Will you please help me


Look both ways


Agenda


Downloads


Some possible image transformations

mandrill

mandrill

Duplicate

mandrill

mandrill

Bluing

mandrill

mandrill

Monotone

mandrill

mandrill

Mirror

mandrill

mandrill

Flip

mandrill

mandrill

Sepia

mandrill

mandrill

Grayscale

mandrill

mandrill

Clockwise rotation

mandrill

mandrill

Palette reduction

mandrill

mandrill

Shrinking

mandrill

mandrill

Pixelate


Strategy — produce the new image from left to right and top to bottom

mandrill

mandrill


Basic photo-manipulation problem-solving pattern

# get dimensions of the original

ow, oh = ...

 

# set dimensions of the new image

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 of interest in the original

  ospot = ...

 

  # get the pixel at the ospot

  opixel = ...

 

  # determine the pixel for the new image

  npixel = ...

 

  # set the nspot in the new image

  ...

 

# return the filled in new image

return new_image



Basic photo-manipulation problem-solving Python function

def manip( original, size, color, where ) :

  ''' Provide a pattern for image manipulation

  function size(): determines size of new image based on the original

  function color(): determines color of new image pixel based on an

  original pixel

  function where(): determines where on original to determine

  correspondent pixel for new image

  '''

  # 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 = 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 nspot in the new image

  new_image.putpixel( nspot, npixel )

  # return the filled in new image

  return new_image



Actual photo-manipulation problem-solving Python function

def same_size( image ) :

  return image.size

def same_color( pixel ) :

  return pixel

def same_where( spot, w, h ) :

  return spot

def manip( original, size=same_size, color=same_color, where=same_where ) :

  ...

 


  🦆 © 2022 Jim Cohoon   Resources from previous semesters are available.