Question: can you please help with the first two questions in this code rom PIL import Image import numpy as np import matplotlib.pyplot as plt import

can you please help with the first two questions in this code

rom PIL import Image import numpy as np import matplotlib.pyplot as plt import math def get_histogram(image, bins): # define an array with size of bins, set to zeros histogram = np.zeros(bins) # loop through pixels and sum up counts of pixels for i in range(image.shape[0]): for j in range(image.shape[1]): histogram[math.floor(image[i, j]/(256/bins))] = histogram[math.floor(image[i, j]/(256/bins))] + 1 # return the final result return histogram def get_cumulative_distribution(norm_histogram): # section 1 # YOUR CODES #1 5 points return 0 # You can change this line based on what you need to return. def map_intensity_values(image, cumsum, intensity_value = 256): # map old intensity values to new intensity values new_image = np.zeros(image.shape) # YOUR CODES #2 8 points # section 2 return new_image path = '../../data/empire.jpg' # im_rgb for RGB, and im for grayscale im_rgb = Image.open(path) # resize the original to a 128 by 128 grayscale image, im # YOUR CODES #3 2 points im # convert the image into a numpy array im_rgb = np.array(im_rgb) im = np.array(im) # make a copy of the original image im_g = im_rgb.copy() # set all values in green channel to 0 and store the new image to im_g # YOUR CODES #4 2 points im_g # crop im_rgb using array slicing. Rows: 250 to 350; Columns 250 to 350 # YOUR CODES #5 2 points crop # set bins value and call function get_histogram bins = 128 histogram = get_histogram(im, bins) # compute normalized_histogram norm_histogram = histogram / histogram.sum() # compute cumulative distribution cumsum = get_cumulative_distribution(norm_histogram) # calculate the transformation T to map the old intensity values to new intensity values. new_im = map_intensity_values(im, cumsum, intensity_value=256) # call function get_histogram to get new histogram by setting bins new_histogram = get_histogram(new_im, bins) # construct figure plt.figure() plt.gray() # Use subplot to display the images using a 3 by 3 setting # Display bars for histogram: plt.bar(range(histogram.size), histogram) # YOUR CODES #6 # 11 points plt.show()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!