# Name: *** Enter your name here *** # # Student-ID: *** Enter your student ID here *** # # Rename the file to 03.py # # Submit your solutions via moodle # import numpy as np import matplotlib.pylab as plt # Please do not change the code above this line # Exercise 1: Conversion of RGB to grayscale images # def exercise1(): # close all figures plt.close('all') # Task 1A: Read the image `FluorescentCells01.jpg` and print some # information about it such as the *shape* and *data type* of the image, as # well as the *minimum* and *maximum* pixel value. # *** Insert your Python code here *** # Task 1B: Convert the image to a grayscale image by averaging the pixel # values of the individual color layers. The data type of the grayscale # image should be identical to the data type of the input image. # *** Insert your Python code here *** # Task 1C: To account for differences in the sensitivity of the # photoreceptors in our retina, a weighted sum of the R, G, and B # components should be formed where the weights for the color channels are # 0.2989, 0.5870, and 0.1140, respectively. # *** Insert your Python code here *** # Task 1D: Show the original RGB image and both grayscale images # *** Insert your Python code here *** # Exercise 2: Showing under- and overflow in a color image # def exercise2(): # close all figures plt.close('all') # Task 2A: Read the image and show the individual layers as grayscale # images. # *** Insert your Python code here *** # Task 2B: For each channel, show underflowing pixels in blue, overflowing # pixels in red, and all other pixels in gray # *** Insert your Python code here *** # Exercise 3: Image histograms # def exercise3(): # close all figures plt.close('all') # Task 3A: Read the image and show image histograms for the individual # layers using a logarithmic scale for the counts. # *** Insert your Python code here *** # Task 3B: Show image histograms for the individual layers excluding the # intensities of pixels suffering from under- or overflow # *** Insert your Python code here *** # Test code - you shouldn't change this part of the template if __name__ == '__main__': exercises = {'1': (exercise1, ), '2': (exercise2, ), '3': (exercise3, ), } choice = input('Please enter the number of the exercise: ').upper() if choice not in exercises: print('Please choose among {0}'.format( list(exercises.keys()))) else: func, *args = exercises[choice] print('Task {0}, running "{1}"'.format( choice, func.__name__)) result = func(*args) if result is not None: print('Result:', result)