COMP Assignments Individual Homework 3! Individual Homework 3 Due 1 Dec by 23:59 Points 100 Submi!ng a file upload File types py Available un!l 4 Dec at 23:59 Start Assignment Due: 11:59pm on...

1 answer below »
Assignment description is the first attachement



COMP Assignments Individual Homework 3! Individual Homework 3 Due 1 Dec by 23:59 Points 100 Submi!ng a file upload File types py Available un!l 4 Dec at 23:59 Start Assignment Due: 11:59pm on Wednesday, December 1 Total Points: 100 Preliminaries: The goal of this homework is to do some very simple image processing tasks, u!lizing numpy to hold the image data, and to allow us to easily modify the image data. You will use matplotlib and numpy. Download the file project3.py , which already contains the necessary imports. You will use the plt.imshow(img) method in matplotlib to display images. It is important for this problem set to understand the structure of a numpy image. This is discussed at the end of the recorded video lecture from Wed Nov 17, which can be found in the Video Library. Take a look at the func!on rgb_ints_example , which should return a 150x150 image pa"ern. Calling plt.imshow(rgb_ints_example()) will display that image. You may find using the imageshow(...) func!on defined in the file gives you a be"er image display on some systems (don't worry much about how it works). The func!on can be used as follows: imshow(rgb_ints_example()) Loading and displaying an image You can load an image using the plt.imread(...) method. running: pattern = plt.imread('pattern.png') imageshow(pattern) should display: Part 1: Color Channels (30 points) Write the func!on onechannel(pattern, rgb) , which should return a new pa"ern that contains only the red, green or blue channel of the image. rgb = 0, display red rgb = 1, display green rgb = 2, display blue For example, running plt.imshow(onechannel(pattern, 0)) should display: Running plt.imshow(onechannel(pattern, 1)) should display: Part 2 - Channel Permuta"ons (35 points) define the func!on permutecolorchannels(img, perm) perm is a list of 0,1,2 in some order, which specifies how to permute the color channels. See examples below. Given the source image 'pa"ern': plt.imshow(pattern) Running plt.imshow(permutecolorchannels(pattern, [1,0,2])) will produce the following output: Here is how this works (we will discuss this in detail in class on December 4th): The first index of the perm list specifies the red channel. So the 1 in that posi!on means that the value of the red color channel should appear in posi!on of the green color channel in the image. The second index of the list specifies the green channel. The 0 in that posi!on means that the color of the green color channel should now appear in posi!on of the red color channel. So this permuta!on swaps the red and green color channel. (red->green, green->red, blue->blue) Another example: plt.imshow(permutecolorchannels(pattern, [2,0,1])) should produce this: (red->blue, green->red, blue->green) Test this func!on on a real image as follows. First load the file permcolors.jpg permcolors = plt.imread('permcolors.jpg') imageshow(permcolors) which should display: This image above has its color components permuted. Use your permutecolorchannels method to restore the correct colors for the image. plt.imshow(permutecolorchannels(permcolors, perm)) What value of 'perm' will display the image with correct colors? Include the correct func!on call, including the correct permuta!on, in your main program. Problem 3 - Image encryp"on with XOR (35 points) Running secret = plt.imread('secret.bmp') plt.imshow(secret) should display this noisy image: This image has been encrypted by XORing the data with a secret key. We can recover the original image by XORing the noise image with the key in a certain fashion. XOR(also known as exclusive OR), is a boolean 'bitwise' opera!on. You can read about it here. In Python, if A and B are integers, 'A^B' performs a bitwise XOR on the bits represen!ng the integer values of A and B. Numpy arrays also define the '^' operator. The XOR opera!on has the useful property that A^B^A = B. We ecncrypt an image by XORing the image with a key. We can recover the image by XORing with the key again. Download the key file key.npy . Then load the key (which is a numpy array) using: key = np.load('key.npy') Note that the length of the key is the same as one row of the secret image. Write the func!on decrypt(image, key) that takes an image and a key array as a parameter and returns a decrypted image. XOR each red, green, and blue row of the image with the key. In the main program, call the decrypt func!on to decrypt secret.bmp and then display the very pre"y result. What you need to submit Please upload only the project3.py file. 1 Fall 2021 Home Announcements Assignments Grades Ed Discussion Video Library People Pages Files Syllabus Quizzes Collabora!ons Course Info Library Reserves Textbooks Zoom Class Sessions Name & Pronoun Recordings Account Dashboard My Courses Courses Groups Calendar Inbox History Help https://courseworks2.columbia.edu/courses/135170/files/12624954/download?download_frd=1 https://courseworks2.columbia.edu/courses/135170/files/12624970/download?download_frd=1 https://courseworks2.columbia.edu/courses/135170 https://courseworks2.columbia.edu/courses/135170/announcements https://courseworks2.columbia.edu/courses/135170/assignments https://courseworks2.columbia.edu/courses/135170/grades https://courseworks2.columbia.edu/courses/135170/external_tools/37606?display=borderless https://courseworks2.columbia.edu/courses/135170/external_tools/12497 https://courseworks2.columbia.edu/courses/135170/users https://courseworks2.columbia.edu/courses/135170/wiki https://courseworks2.columbia.edu/courses/135170/files https://courseworks2.columbia.edu/courses/135170/assignments/syllabus https://courseworks2.columbia.edu/courses/135170/quizzes https://courseworks2.columbia.edu/courses/135170/collaborations https://courseworks2.columbia.edu/courses/135170/external_tools/7232 https://courseworks2.columbia.edu/courses/135170/external_tools/12720 https://courseworks2.columbia.edu/courses/135170/external_tools/13781 https://courseworks2.columbia.edu/courses/135170/external_tools/26601 https://courseworks2.columbia.edu/courses/135170/external_tools/39295 https://courseworks2.columbia.edu/
Answered Same DayDec 02, 2021

Answer To: COMP Assignments Individual Homework 3! Individual Homework 3 Due 1 Dec by 23:59 Points 100 Submi!ng...

Swapnil answered on Dec 03 2021
113 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here