Question: Write a program in Python that asks the user for a name of an image .png file and the name of an output file. Your
Write a program in Python that asks the user for a name of an image .png file and the name of an output file. Your program should create a new image that has only the green channel of the original image (that is, no red and blue channels).
To test your program you can download csBridge.png
A sample run of your program should look like:
Enter name of the input file: csBridge.png Enter name of the output file: greenH.png
Sample input and resulting output files:
Note: before submitting your program for grading, remove the commands that show the image (i.e. the ones that pop up the graphics window with the image). The program is graded on a server on the cloud and does not have a graphics window, so, the plt.show() and plt.imshow() commands will give an error. Instead, the files your program produces are compared pixel-by-pixel to the answer to check for correctness.
and i have a code which is like thisplease help me to fix it
import matplotlib.pyplot as plt import numpy as np
img = plt.imread('csBridge.png') #Read in image from csBridge.png plt.imshow(img) #Load image into pyplot plt.show() #Show the image (waits until closed to continue)
img2 = img.copy() #make a copy of our image img2[:,:,0] = 0 #Set the red channel to 0 img2[:,:,2] = 0 #Set the blue channel to 0
plt.imshow(img2) #Load our new image into pyplot plt.show() #Show the image (waits until closed to continue)
plt.imsave('green.png', img2) #Save the image we created to the file: reds.png
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
