CPSC150A
Scientific Computing

Activity 16

Numpy Image Processing

Decrease Contrast

Write the function decrease_contrast(image_array), which has 1 parameter, a numpy array that represents a color RGB image. The function should return a new numpy array that is the input image with the range of values scaled to the range 255 / 4 to 255 * 3 / 4, that is half the range but still centered. The function should not use any loops. Test the function with a small test array and printing the result before testing on a larger image and writing the result to a file.

Example

Test Code Output
print(decrease_contrast(numpy.array([[[0, 255, 0]]])) [[[ 63.75 191.25 63.75]]]

Grayscale

Write the function grayscale(image_array), which has 1 parameter, a numpy array that represents a color RGB image. The function should return a new numpy array that is the input image converted to a grayscale image. In a grayscale image, for each pixel, all three color values are the identical. To compute the grayscale value of a pixel, average the values of the red, green, and blue channels. The function should not use any loops. Again, test the function with a small test array and printing the result before testing on a larger image and writing the result to a file.

Test Code Output
print(grayscale(numpy.array([[[0, 255, 0]]])) [[[85. 85. 85.]]]

Submission

Please show your source code and run your programs. Only programs that have perfect functionality will be accepted as complete.