# Name: *** Enter your name here *** # # Student-ID: *** Enter your student ID here *** # # Rename the file to 04.py # # Submit your solutions via moodle # import numpy as np import matplotlib.pylab as plt def make_disk(npix, radius, center=(0, 0)): """Creates an (npix, npix) binary image of a disk where `radius` is the radius of the disk (in pixels) and `center` is a tuple specifying the center of the disk (relative to the origin). """ x = np.linspace(-0.5*npix, 0.5*npix, npix) X, Y = np.meshgrid(x-center[0], x-center[1]) return np.sqrt(X**2 + Y**2) < radius # Please do not change the code above this line # Exercise 1: Color mixing # def exercise1(): # close all figures plt.close('all') # Task 1A: To demonstrate additive color mixing, create a (1024, 1024, 3) # RGB image with disks of radius 300 in each layer. The center of the disk # in the red / green / blue layer is (0, -160) / (-160, 160) / (160, 160), # respectively. # *** Insert your Python code here *** # Task 1B: To demonstrate subtractive color mixing, first create a white # RGB image. Then *subtract* disks of radius 300 in each layer. The centers # of the disks that will be subtracted from the red / green / blue layer # are (0, -160) / (-160, 160) / (160, 160), respectively. # *** Insert your Python code here *** # Task 1C: Show both types of color mixing by creating a figure. # *** Insert your Python code here *** # Exercise 2: Color maps # def exercise2(): # close all figures plt.close('all') # Task 2A: Read the image and show histograms of the image intensities in # each color layer. # *** Insert your Python code here *** # Task 2B: For the green color layer, multiples of 0.25 can be used to # segment the image. Use these thresholds to create four binary images of # green pixel values falling into the intervals [0., 0.25), [0.25, 0.5), # etc. and show the four binary images. # *** Insert your Python code here *** # Task 2C: Combine the four binary images that you defined in 2B with a # colormap to create Warhol-like images of Marilyn Monroe. First, create an # intensity image with intensities in the interval [0, 1] by adding up the # four binary images using weights [0, 1/3, 2/3, 1]. Second, show the # resulting intensity array with various colormaps provided by matplotlib. # *** Insert your Python code here *** # Exercise 3: Thermal imaging # def exercise3(): # close all figures plt.close('all') # Task 3A: Read the intensity image and show the temperature distribution # using false colors (e.g. the plasma colormap) # *** Insert your Python code here *** # Task 3B: Remove the camera logo "FLIR" in the upper left corner of the # image. To do so: # # 1. Make the image writeable by replacing it with its copy # 2. Extract a patch that contains the logo by slicing [:80, :160] # 3. Select the pixels in the patch with intensity > 100 # 4. Compute the average intensity of pixels that have *not* been selected # 5. Set the intensity of the selected pixels to the average value computed # in step 3. # *** Insert your Python code here *** # Task 3C: Find and highlight the head of the hardest thinking participant. # 1. Create a gray RGB image whose color channels are all identical to the # intensity image from 3B in which the logo has been removed. # 2. Select the pixels whose intensity is larger than 93% of the maximum # intensity. # 3. Color the selected pixels in red. # *** 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)