Class ImageProcessor

class image_processor.ImageProcessor(image_array)

Instance is a collection of image transforms

Constructor: Create an ImageProcessor for the given image.

param image:The image to process.

Precondition: an ImageArray object

Attribute original is a direct reference to image_array. However, attribute current is a copy of that ImageArray.

Attributes

current

The original state of the image in this processor.

Invariant: Must be an ImageArray

Immutable Attributes

These attributes may be read (e.g. used in an expression), but not altered.

original

The original state of the image in this processor.

This attribute is set by the constructor and may not be altered

Methods

restore()

Restore the original image

invert()

Invert the current image, replacing each element with its color complement

transpose()

Transpose the current image

Follow this plan:

Create a new ImageArray ia, which has no data (it is an empty image), but which has the number of rows and columns swapped from their current values in self.current

Store the transpose of self.current in ia, using self.current’s getPixel function and ia’s setPixel function.

Assign ia to self.current.

The transposed image will be drawn on the screen immediately afterwards.

horizReflect()

Reflect the current image around a vertical line through the middle of the image.

vertReflect()

Reflect the current image around a horizontal line through the middle of the image.

rotateLeft()

Rotate the image left via a transpose, followed by a vertical reflection.

rotateRight()

Rotate the image right via a transpose, followed by a horizontal reflection.

jail()

Put jail bars on the current image:

Put 3-pixel-wide horizontal bars across top and bottom,

Put 4-pixel vertical bars down left and right, and

Put n 4-pixel vertical bars inside, where n is (number of columns - 8) / 50.

The n+2 vertical bars should be as evenly spaced as possible.

monochromify(color)

Convert the current image to monochrome according to parameter color.

param color:Monochrome color choice

Precondition: an int equal to either the global constant GRAY or the global constant SEPIA

If color is GRAY, then remove all color from the image by setting the three color components of each pixel to (an int corresponding to) that pixel’s overall brightness, defined as 0.3 * red + 0.6 * green + 0.1 * blue.

If color is SEPIA, make the same computation but set green to int(0.6 * brightness) and blue to int(0.4 * brightness).

vignette()

Simulate vignetting (corner darkening) characteristic of antique lenses.

Darken each pixel in the image by the factor

(d / hfD)^2

where d is the distance from the pixel to the center of the image and hfD (for half diagonal) is the distance from the center of the image to any of the corners.

hide(text)

Hide message text in this image, using the ASCII representation of text’s characters.

Return: True if message hiding possible, and False if not.

param text:a message to hide

Precondition: a string

If m has more than 999999 characters or the picture does not have enough pixels, return False without storing the message.

reveal()

Return: The secret message from the image array. Return None if no message detected.

getPixels(n)

Return: String that contains the first n pixels of the current image

param n:number of pixels to get

Precondition: a positive int < self.current.len

The pixels are shown 5 to a line, with annotation (i.e. something at the beginning to say what the string contains).

To begin a new line, put an ‘\n‘ in the string. For example, type this at the Python interpreter and see what happens: ‘ABCDE\nEFGH’.

Use the function _pixel2str() to get the string representation of a pixel tuple.

fuzzify()

Change the current image so that every pixel that is not on one of the four edges of the image is replaced with the average of its current value and the current values of its eight neighboring pixels.

When implementing this function:

FIRST, make a copy of the image. Use the function ImageArray.Copy()

THEN transform the copy using the values in the current image.

THEN copy the entire transformed copy into the current image.

Thus, the average will be the average of values in the “original” current image, NOT of values that have already been fuzzified.

Table Of Contents

Previous topic

Class Main

Next topic

Class ImagePanel

This Page