Class 38 — Friday November

Image mash ups

It’s simply smashing — For visitors on the Lawn — If they watch their steps


Look both ways


Gallery


Downloads


Rounding



Basic photo-manipulation problem-solving Python function one more time

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, original )

  # 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 mash.py


Primary function (already written)

def combine( bg, fg, sx, sy, back_screen ) :

  bw, bh = bg.size # size of background image

  fw, fh = fg.size # size of foreground image

  copy = bg.copy() # get a copy of background image

  new_image = copy.convert( 'RGB' ) # to be the basis of new image

  for fx in range( 0, fw ) : # consider every (fx, fy)

  for fy in range( 0, fh ): # possibility of the new image

  fspot = ( fx, fy ) # name spot (fx, fy )

  fpixel = fg.getpixel( fspot ) # get fspot pixel on fg image

  nx = sx + fx # determine the shifted nspot on new image

  ny = sy + fy # to paint fpixel

  nspot = ( nx, ny )

  # check whether fpixel should be painted on new image at nspot

  if ( colorable( nspot, new_image, fpixel, back_screen ) ) :

  new_image.putpixel( nspot, fpixel )

  return new_image # return the mash up


Helpful constant (already defined)


Functions to be written







 























 


  © 2020 Jim Cohoon   Resources from previous semesters are available.