## Imaging

Having a problem solving pattern to apply to similar problems is generally a good thing. For establishing an image processing how about the following.

• When referring to the original and its transform, rather than variable names like `im1` and `im2`, use names that clearly indicate what image is being referenced. Variable `original` is a good name for the original image. For the new image, a variable `new` seems like a good choice of name.
• When producing a grayscale, the value for a pixel in the new image is determined using the pixel at the corresponding coordinate in the original. However, when producing a reflection (mirroring), the value for a pixel in the new image is not determined from the corresponding coordinate in the original. Using variable names that make it clear which coordinate is being considered is sensible. If we are going with `original` and `new` for naming the images, how about `(ox, oy)` and `(nx, ny)` when talking about pixel locations in the respective images?
• Also when producing a grayscale, the new image has the same dimensions as the original image. However, when producing a clockwise rotation, the new image does not. Again names that make it clear which image dimensions are being referenced is sensible. How about `(ow, oh)` and `(nw, nh)`?
• When producing an image transformation it is clear you have to assign values to all of the pixels in the new image. So nested `for` loops that consider each pixel in the image seems appropriate

for nx in range( 0, nw ) :

for ny in range( 0, nh ) :

• Using the discussion points our basic image processing pattern is

# get the dimensions of the original

ow = original.width

oh = original.height

# determine the dimensions of the new image

nw = ...

nh = ...

# create a new blank image to hold the transformation

new_image = Image.new( 'RGB', (nw, nh) )

# consider every (x, y) location in the new image

for nx in range( 0, nw ) :

for ny in range( 0, nh ) :

# get the new image coordinate to be colored

ncoordinate = (nx, ny)

# determine the pixel value for ncoordinate

...

npixel = ...

# set the pixel at ncoordinate

new_image.putpixel( ncoordinate, npixel )

# return the transformation

return new