In your notebook, execute your algorithm and show the input image and output image next
to each other, for each of the three approaches. Also briefly discuss in a comment in your
notebook which approach yields the best contrast-stretched colour image and provide
reasons for why that approach works better than the other two.
2. Histogram Calculation
The histogram of an image shows the counts of the intensity values. It gives only statistical
information about the pixels and removes the location information. For a digital image with
𝐿𝐿
gray levels, from
0
to
𝐿𝐿 − 1
, the histogram is a discrete function
ℎ(𝑖𝑖) = 𝑛𝑛
𝑖𝑖
where
𝑖𝑖 ∈
[0, 𝐿𝐿 − 1]
is the
𝑖𝑖
th gray level and
𝑛𝑛
𝑖𝑖
is the number of pixels having that gray level.
Task (0.5 mark):
Write an algorithm that computes and plots the histogram of an image and
also reports the minimum pixel value and the maximum pixel value in the image. Then execute
your algorithm to compare the histograms and extreme values before and after contrast
stretching of image
Oakland.png
for each of the three approaches in the previous task.
More specifically, for the first contrast-stretching approach, show the histogram and extreme
values for each of the three channels (R, G, B) of both the input image and the output image.
For the second approach, show the histogram and extreme values of only the gray value
representation (Y) of both the input image and the output image after conversion. For the
third approach, show the histogram and extreme values of only the value channel (V) of both
the input image and the output image after conversion.
To facilitate visual comparison, present the histograms of the input image and corresponding
output image side by side in each case.
3. Image Thresholding
A crucial first step for quantitative analysis of objects (or regions) of interest in images, is to
identify which pixels belong to the objects (the relevant pixels) and which belong to the
background (the irrelevant pixels). This task is called image segmentation.
The simplest technique to perform this task is thresholding. Here, a pixel is considered to
belong to an object if its value is above the threshold, and to the background if its value is
lower than or equal to the threshold.
While an optimal threshold for each image could be selected manually by the user, this is
undesirable in applications that require full automation. Fortunately, several automatic
thresholding techniques exist, as discussed in the lecture.
Task (0.75 mark):
Write an algorithm that can threshold an image using the three different
thresholding methods discussed in the lecture: Otsu, IsoData, Triangle. Apply your algorithm
to the images
Hardware.png
(the objects are the dark nuts and bolts),
Nuclei.png
(the objects
are the bright cell nuclei), and
Orca.png
(the object of interest is the Orca).
In your notebook, show the results in table form to facilitate visual comparison of all images.
For example, one table row per input image, successively showing the input image, its
histogram, and the thresholding results using the three methods.
Also briefly discuss the differences in the results in your notebook and provide explanations
(based on the histograms or otherwise) why for some images one thresholding method may
work better than others, while for other images it may be the other way around, or perhaps
in some cases none of the methods work well. Present some general rules of thumb for which
thresholding methods are best for what kind of images.
4. Edge Detection
Edges are an important source of semantic information in images. A gray-scale image can be
thought of as a 2D landscape with areas of different intensities corresponding to different
heights. The edges are the transitions from one such area to the next.
The Laplacian is a second-order derivative operator that can be used to find edges. It
emphasizes pixels in areas of strong intensity changes and de-emphasizes pixels in areas with
slowly varying intensities. The edges are the zero-crossings in the Laplacian image.
Task (0.5 mark):
Write an algorithm that computes the Laplacian image of an input image
using the above kernel. Apply the algorithm to the image
Laplace.png
.
Notice that the calculations may produce negative output pixel values. Thus, make sure you
use the right data types for the calculations and for the output image, and the right intensity
mapping to display the output image.
Coding Requirements
Make sure that in your Jupyter notebook, the input images are readable from the location
specified as an argument, and all output images and other requested results are displayed in
the notebook environment. All cells in your notebook should have been executed so that the
tutor/marker does not have to execute the notebook again to see the results.