Question: These are the instructions : Use plt.subplot to generate a figure as follows:Subfigure 1: Show the original image of im_rgb Subfigure 2: Set all values

These are the instructions :

Use plt.subplot to generate a figure as follows:Subfigure 1: Show the original image of im_rgb

Subfigure 2: Set all values in green channel to 0 and show the image

Subfigure 3: Crop im_rgb using array slicing. Rows: 250 to 350; Columns 250:350

Subfigure 4: Show the resized 128 by 128 grayscale image

Subfigure 5: Histogram of the original image by setting bins = 128

Subfigure 6: Cumulative distribution.

Subfigure 7: New image from histogram equalization

Subfigure 8: Histogram of the new image by setting bins = 128

Subfigure9:An empty subfigure.ReplaceStudentNamewith your name and mark the axes using x and y labels.

Below is the source code of that needs editing :

import math """ Assignment 1 """ 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): # 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 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!