Assignment Specification
Software: You are required to use OpenCV 3+ with Python 3+ and submit your code as a Jupyter notebook (see deliverables above and coding requirements below).
Objectives: This assignment is to familiarise you with basic image processing methods. It also introduces you to common image processing and analysis tasks using OpenCV.
Learning Outcomes: After completing this assignment, you will have learned how to:
- Open and read image files.
- Display and write image files.
- Perform mathematical operations on images.
- Apply basic image filtering operations.
- Perform image adjustment and restoration.
Description: Many computer vision applications use image processing techniques to suppress artifacts and enhance relevant features to prepare images for quantitative analysis.
The goal of this assignment is to write image processing code that can open a digital image, perform a sequence of pixel manipulation operations (step-by-step as listed under Tasks below), in order to remove background shading.
Below is an image (on the left) from an astronomy project where the goal is to count and measure the stars. However, these measurements are impeded by the haze of the Milkyway in the background. Thus, the shading needs to be removed (as on the right).
Tasks: This assignment consists of three tasks, described below. Each task depends on the previous one, so you need to do them in the given order.
Task 1 (4 marks): Background Estimation
Open the given image Stars.png. Like the example shown above, it has background shading patterns that need to be removed. The first step to get rid of the shading is to make an accurate estimate of the background of the image.
Write an algorithm that performs the following two steps:
- Create a new image, which we will call image ??, having the same size (number of pixel rows and columns) as the input image, which we call image ??.
- Go through the pixels of image ?? one by one, and for each pixel (??, ??) find the minimum gray value in a neighbourhood (see below) centred around that pixel, and then write that minimum value in the corresponding pixel location (??, ??) in ??.
The resulting image ?? is called the min-filtered image of input image ??.
The neighbourhood is a square of size ?? × ?? pixels, where ?? is a free parameter of the algorithm and typically has an odd value (3, 5, 7, ...), with the pixel (??, ??) under consideration being the centre pixel. Manually try different values of ?? and mention in your report what is the smallest value of ?? that causes the stars in ?? to visually disappear altogether in image ??. Also explain why this value of ??, and not smaller values, causes the stars to disappear, and what is the effect of taking larger values than this smallest value.
The min-filtering causes the gray values in ?? to be smaller than the actual background values in ??, so a correction is needed. Extend your algorithm with two more steps:
- Create another new image, which we call image ?? here, of the same size as ?? and ??.
- Go through the pixels of ?? one by one, and for each pixel (??, ??) find the maximum gray value in a neighbourhood of the same size (?? × ?? pixels) centred around that pixel, and then write that maximum gray value to (??, ??) in ??.
The resulting image ?? is called the max-filtered image of the image ??.
Task 2 (1 mark): Background Subtraction
Now that your algorithm can estimate the background ?? of an image ??, removing the shading artifacts from ?? can be done simply by subtracting ?? from ?? pixel by pixel, resulting in the output image ??. Extend your algorithm to perform this subtraction.
Task 3 (5 marks): Algorithm Extensions
Open the given image Nuclei.png. It is a microscopy image showing many cell nuclei (the dark blobs). Like Stars.png, the image has a background shading pattern (also dark) that needs to be removed. There are three main differences between the two images:
- The sizes of the images are different.
- The sizes of the objects (stars versus cell nuclei) in the images are different.
- The objects in Nuclei.png are dark and the background is bright (except for the dark shading pattern), whereas in Stars.png the objects are bright and the background is dark (except for the bright shading patterns).
the order of the min-filtering and max-filtering operations. Specifically:
* If the user sets ?? = 0, the algorithm should first perform min-filtering (image ?? to ??), then max-filtering (image ?? to ??), and then pixelwise subtraction (?? = ?? − ??).
* If the user sets ?? = 1, the algorithm should first perform max-filtering (image ?? to ??), then min-filtering (image ?? to ??), and then pixelwise subtraction (?? = ?? − ?? + 255).
In your report, explain why you must use the ?? = 0 (and not ?? = 1) variant of your algorithm to make it work for Stars.png, and conversely why you must use the ?? = 1 (and not ?? = 0) variant to make it work for Nuclei.png. Also explain why the ?? = 1 variant requires adding 255 (for 8-bit images) to each subtracted pixel value in image ?? (see above).
Furthermore, mention what is a good value of ?? for Nuclei.png and why. And include images ?? and ?? computed from Nuclei.png in your report.