辅导案例-CSC108-Assignment 2

欢迎使用51辅导,51作业君孵化低价透明的学长辅导平台,服务保持优质,平均费用压低50%以上! 51fudao.top
CSC108 Assignment 2: Image Editor
For this assignment, you will implement an image editor using Pillow, an image
manipulation module.
Before you get started, you must install Pillow. There are several ways to do this,
involving Terminal and the command line (this is beyond 108 knowledge, but
you're welcome to look up guides on how to manually install Pillow). But we're
going to stick to an easy way to do it for this course: through a program called
Pycharm. Instructions on getting set up are in the section below.
Part 0: The Set-up
So far, we have been coding using IDLE, which is a very simple coding
environment. For this assignment, you will be using a slightly more advanged
environment called Pycharm, and we will install Pillow, the image manipulation
module, into it.
Step 1: Download and install Pycharm from your computer
Here: https://www.jetbrains.com/pycharm/download
Download the Community Edition; you can keep the default settings
during installation.
Step 2: Open Pycharm and install Pillow by following the instructions in this
Youtube video with strange background sounds
Here: https://www.youtube.com/watch?v=jl1VAKd2BF8
(In that screen, make sure the interpreter is set to Python 3.7)
Step 3: You're all set to get started!
Download the starter code from the course website.
Extract the contents onto your computer
– you will now have an "a2" folder on your computer
Open Pycharm and when prompted to choose a project,
select "Open" and then select the "a2" folder you just extracted
Your a2 folder should include three files:
- app_window_class.py [DO NOT MODIFY this file]
- image_editing_program.py [DO NOT MODIFY this file]
- image_editing_functions.py [this is your starter code for the assignment]
Important Background Information and Restrctions
The Pillow module that we are using has tons of features, which you are
welcome to explore outside the coure. For this particular assignment however,
we are placing strict restrictions on which of these features you can use.
Violating these restrictions will result in a grade of 0 on the relevant
function(s).
What you can use from the Image module:
- Image.new(mode, size, color): creates a new image (use 'RGB' for mode)
- Image.open(filename): opens an existing image file
- Image.size: returns the image size in pixels as a 2-tuple, (width, height)
- Image.load(): returns a PixelAccess object of all of the image's pixels
- Image.show(): display the image represented by the Image object
- Image.save(filename): saves an image
- Image.close(): closes an open Image file
You cannot use any other Image method, and you cannot import any other
Python module, except for what we already imported for you.
(But if you're interested in exploring what else is there on your own, here is the
documentation page: https://pillow.readthedocs.io/en/3.1.x/reference/
Image.html#PIL.Image.Image)
From the PixelAccess module:
- You can use pixels[i, j] where pixels is a PixelAccess object and i and j are the 

coordinates of the pixel you are dealing with
- See documentation here: https://pillow.readthedocs.io/en/3.1.x/reference/
PixelAccess.html
Part 1: Adding Image Filters
OK, Let's get started!
Open the file image_editing_functions.py
This is the only file you will be modifying. Do NOT touch the other two files
provided for you.
Read through the docstring descriptions of each function and complete the
code as applicable.
The other two files are there for you to test out your code. To do so, you need to
run image_editing_program.py But do NOT modify any of the code in this file!
This file is not going to be submitted nor graded. Just use it to bring up the GUI
that looks something like this:
From here, you can open up the "Filter" menu at the top and play around with
your filters as you complete them in image_editing_functions.py. We have
already completed the "Remove Red" and "Downscale" filters for you, and
added in a "Reset Image" option in this menu for you.
See the demo video on the course website to see how the results of each filter should look.
Note that multiple image manipulation operations can be applied to the
same image, and they should build on one another. See the demo video that
for examples of this: https://www.youtube.com/watch?v=5-
RmguEKlPw&feature=youtu.be
We also included options to "open" new files, "save" your modified files (these
options can be found under the "File" menu).
NOTE: A lot of these features might be slow, so you should only be testing this out
with small images. We've included several small images for you to work with.
Part 2: Adding Custom Filter(s)
Optional for bonus marks up to 5% extra on the assignment
For bonus marks, you can add one custom filter to your application. To do this,
working in image_editing_functions.py (same file as Part 1; do NOT modify any
of the other files that we gave you):
1. create a new function at the bottom of the file (before the COMMANDS
dictionary, but after all the function skeletons we provided for you) that is
related to your filter's functionality, with a type contract and a good
docstring description
2. write code in this new function's body to apply your filter to a given
image and return the updated image
3. in the COMMANDS dictionary which should be at the very bottom of your
image_editing_functions.py file, add a new key that is the label for the
filter (as a string) and the associated value should be the name of the
newly added function that applies this filter to an image and returns the
updated image
For this part, you will be graded on creativity and effort. A very simple addition
could be to remove green or remove blue ... these will not be worth many marks
because we already gave you remove_red, which is too similar! So, these would
be pretty boring and easy to implement custom filters. Try to think of something
a little more interesting and unique. :) Adding just one filter is good enough to
earn you the full marks for this part, as long as your code is creative, shows
effort, and actually works! But if you have more ideas, you are welcome to add
in more. Have fun with it!
Remember to add all your custom filter functions after all the base functions
from Part 1, to make it easy for us to spot them when we are evaluating your
code.
You may also hand in a text file enhancements.txt to describe your ideas for the
custom filters, or if there is anything you want us to know about them. This time,
this file is optional because it should be fairly easy to find out what changes you
made to the program, without needing this file.
Guidelines/Cleanup:
Before handing in your code, make sure to do the following:
1. Check that you have followed our style guide
2. You will not only be marked for correctness, but also for design. This means
your code should be as clean and simple as possible. Go over your
functions to check for cleanliness and simplicity in your code. Use helper
functions whenever they would be appropriate.
3. Remove any code you added just for testing, such as print function calls.
4. Remove any pass statement where you have added the necessary code.
5. Double check that all your function code matches the given docstrings,
including the type contracts; for example, if the docstring type contract says
to return an int, your function must return an int, or else it will be graded 0 for
correctness. Note: You should never change the name of any function
given in the starter code, as doing so will make our auto-grader fail.
6. For part 2: Check your docstrings to make sure they are precise and
complete, including a type contract and good, straightforward description.
7. Make sure your code runs (try it out on someone else's computer if you
can, not just your own)! If you have some attempts that you want to get
partial marks for, great. Please submit your attempts; however, if your
incomplete/incorrect attempts cause your code to crash then please
comment out invalid code before handing it in. We must be able to run
your program in order for the autograder to give you marks for other
functions that might work.
What you will be handing in:
Submit only the following file on MarkUs by the deadline on the course website:
1. image_editing_functions.py
If you have any extra files you need for your part2 bonus filter to work, you may
hand those in as well.
Again, please make sure your code is cleaned up and that your main
program runs! If your program crashes as soon as we run it, our autograder will
give you a 0 on all your functions, even ones that might work!
If you want to leave in some code that did not work, but shows the effort you put
into trying to complete it, you can do so for possible, partial marks BUT
COMMENT IT OUT, so it doesn't crash your entire program!
Assessment:
Your mark will be based on both correctness as well as cleanliness of code
(following the Python style guidelines, following design recipe, avoiding
repetitive code – using helper functions, etc.).
51作业君

Email:51zuoyejun

@gmail.com

添加客服微信: abby12468