## Class 35 — April 12

#### Visualization

What do you picture – For a happy future life – We wish you success

### Agenda

• Prepare for the third part of the course

### Two personal questions

• What is your daily routine?
• Why do you have routine(s)?

### Another question

• What is a pattern?

### Even more questions

• What is an algorithm
• What is a program
• What is a programming paradigm?
• What is a software design pattern?
• What are some software design patterns we have considered?

### Next time — Monday!!

• We are going to fill in the class from the front.
• The teaching assistants will direct you to which section.
• If you are assigned a left or right section, take the innermost available seat in your assigned row.
• If you are in the center section, fill in from the middle of your assigned row.

### To do

• Review the Pillow modules's capabilities.
• Further review the Pillow Image capabilities — we are going to be using them on Monday!!

### Some possible basic transformations

 Duplicated image Mirrored image Flipped image Clockwise rotation

### 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 = 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

### Module manip.py

def manip( original, dim_f, color_f, loc_f ) :

# get dimensions of original

ow, oh = original.size

# set dimensions of the new image

nw, nh = dim_f( 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 original

ospot = loc_f( nspot, ow, oh )

# get the pixel at the ospot

opixel = original.getpixel( ospot )

# determine the pixel for the new image

npixel = color_f( opixel )

# set the nspot in the new image

new_image.putpixel( nspot, npixel )

# return the filled in new image

return new_image

• 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?