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.
The original state of the image in this processor.
Invariant: Must be an ImageArray
These attributes may be read (e.g. used in an expression), but not altered.
The original state of the image in this processor.
This attribute is set by the constructor and may not be altered
Restore the original image
Invert the current image, replacing each element with its color complement
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.
Reflect the current image around a vertical line through the middle of the image.
Reflect the current image around a horizontal line through the middle of the image.
Rotate the image left via a transpose, followed by a vertical reflection.
Rotate the image right via a transpose, followed by a horizontal reflection.
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.
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).
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 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.
Return: The secret message from the image array. Return None if no message detected.
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.
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.