![]() ![]() One way to do this is to first generate a 1D array of values for x, and map this array through the density function. HINTS: For efficiency and compactness, it is best to avoid ‘ for’ loops in Python. Therefore, you should normalize the values in the filter so that they sum to 1. This formula for the Gaussian ignores the constant factor. Each value of the filter can be computed from the Gaussian function, exp(- x^2 / (2*sigma^2)), where x is the distance of an array value from the center. The filter should be a 1D array with length 6 times sigma rounded up to the next odd integer. Write a Python function, ‘ gauss1d(sigma)’, that returns a 1D Gaussian filter for a given value of sigma. Show the results of your boxfilter(n) function for the cases n=3, n=4, and n=5. Of course, checking that n is odd requires a bit more work. HINT: The generation of the filter can be done as a simple one-line expression. For example, your function should work as follows: You should check that n is odd, checking and signaling an error with an ‘ assert’ statement. In CPSC 425, we follow the convention that 2D filters always have an odd number of rows and columns (so that the center row/column of the filter is well-defined).Īs a simple warm-up exercise, write a Python function, ‘ boxfilter(n)’, that returns a box filter of size n by n. Make sure that you put this right after your report cover page. During submission, you will merge this PDF with your report. You may find the questions here (if you are familiar with LaTex, feel free to use the following template to generate the answers). In this part of the assignment, you will be practicing filtering by hand on a given "image". The assignment Part 1: Written Questions (6 points) Note that lack of submission of either the code or the PDF will also result in loss of points. If you are using Jupyter, assuming you set things up correctly, you should be able to simply pint the notebook into a PDF file for submission. The scripts and results (as screenshots or otherwise) should be pasted into a single PDF file and clearly labeled. In this assignment, you also need to hand in scripts showing tests of your functions on all the cases specified as well as the images and other answers requested. You will lose marks for insufficient or unclear comments. To get full marks, your functions (i.e., *.py or *.ipynb files) must not only work correctly, but also must be clearly documented with sufficient comments for others to easily use and understand the code. Hand in all parts of this assignment using Canvas (both the code and PDF file as specified). In regular Python you can use img.show() and in Jupyter you can use display(img). Recall that visualizing imagies in regular Python and in Jupyter differs a bit. HINT: Review Assignment 0 for the basics of reading/writing images, converting colour to greyscale, and converting PIL images to/from Numpy arrays. If you are using Jupyter Notebook with Google Colab or on your personal machine, you will, in addition, would also want to import: For consistency (and to make life easier for the markers) you are required to import modules for this assignment exactly as follows: There are different ways to import libraries/modules into Python. The purpose of this assignment is to get some initial experience with Python and to learn the basics of constructing and using linear filters. Now in the section below, I will take you through a tutorial on the Python Imaging Library.Assignment 1: Image Filtering and Hybrid Imagesĭue: At the end of the day 11:59pm, Wednsday, September 30th, 2020. This Python library is already available in the Python standard library, but to use the latest version, I will recommend that you run the pip install command mentioned below before getting your hands on the Python Image Library:Īs mentioned earlier, it is used as PIL but installed as Pillow. ![]() also provides some powerful image processing capabilities. ![]() Some of the important features that this library offers you for image processing are: Pillow is a fork of the PIL library in Python, that’s why to install PIL we write “pip install Pillow”, instead of “pip install PIL”. The PIL or Python Imaging Library is often confused with Pillow. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |