7060 Image Sensors & Processing
ELEC ENG 061/7060 Image Processing Page 1 of 7
7060 Image Sensors & Processing / 4061 Image Processing
Assignment 1
August 2018
(Total Marks: 12%)
Overview
This assignment is intended to give you some hands-on experience with manipulating image
data in MATLAB and the basic image manipulation concepts covered in the course up to the
end of Week 3.
In this assignment work you will be required to modify several functions which implement
asic colour co
ection, contrast enhancement and noise filtering steps.
IMPORTANT: No routines from the image processing toolbox (such as histeq, medfilt2,
imfilter) etc may be used in your part of the assignment solutions unless specifically advised.
Using such routines will result in zero marks for that component of the assignment work.
Assignment Submission
Assignments are to be submitted as a standard ZIP archive file (please do NOT use other
formats such as 7z, RAR, PKZIP) containing the key MATLAB functions and any test code you
have written and a Word (MS Office) or PDF document summarising your results with
comments on the performance of the processing steps employed (in 1A-1D) and written
answers to questions (1E).
• All submitted materials MUST be your own individual original work.
• Marks will be deducted for late submission or inco
ect submission format (please
check myUni for the due date)
As part of the submission, you are expected to write up the results of experimenting with
your code for different settings and images. Do not simply submit your code with screen
shots of the basic test script output.
Source Materials
Source code, test functions and example imagery for this assignment is located on the
MyUni website (https:
www.myuni.adelaide.edu.au). You are welcome to add your own
example imagery for testing and reporting purposes.
DO YOU NEED HELP? - The coding required to complete this assignment is not intended to
e complicated but it does assume familiarity with MATLAB programming. If you are having
problems getting your code working, then please ask questions during the tutorial session or
come and see me during my consulting times.
https:
www.myuni.adelaide.edu.au
ELEC ENG 061/7060 Image Processing Page 2 of 7
Exercise 1A – ( 1.5% ) – Simple YUV420 Reconstruction
Video image frames are sometimes recorded in YUV format with only subsampled U and V
values. Once such simple format is known as YUV420. In YUV420 the Y value of each pixel is
preserved but only half the horizontal and vertical U and V values are recorded. For example,
a 64x64 pixel full colour image would be stored as a 64x64 pixel Y channel and two 32x32
pixel U and V channels (a YUV420 image can thus be stored using only half the space).
Modify the supplied function decode_yuv420.m such that when given a simple uint8
epresentation of this YUV420 format it produces a basic reconstruction of the original uint8
YUV image a
ay. To keep things simple, the missing U and V values can simply be estimated
y duplicating the known values over 2x2 patches. Make sure your solution can handle both
odd and even sized image inputs (even if the estimates at the edges are inaccurate).
The MATLAB pcode script encode_yuv420.p has been supplied to convert uint8 YUV images
into a simple uint8 YUV420 representation (the .p on the filename is not a typo, it means it’s
a partly compiled MATLAB function!). The YUV420 is stored as a full size YUV a
ay with the
subsampled U and V values stored as half sized images with zero padding. The supplied
script yuv420_test.m can be used to test your solutions. Note that the test code uses an
integer approximation to the RGBYUV and YUVRGB colorspace conversions (see.
gb2yuv() and yuv2rgb()). YUV colorspace is similar to YCbCr however the weightings used to
convert from RGB to YUV are different to those used in YCbCr.
An example output for the “pepper” image is shown below.
Above: An example output from the supplied test script (yuv420_test.m). Note that the
YUV images are not shown in their co
ect RGB colours.
Carefully examine the differences between the two imagery and comment on this as part of
your write up (note the RGB YUV RGB conversion functions also introduce additional
e
ors).
ELEC ENG 061/7060 Image Processing Page 3 of 7
Exercise 1B – ( 2.5% ) – Contrast Enhancement Using Stretching
Modify the function contrast_stretch.m so that given an image the function returns
a contrast stretched version of the input image. The mapping of the original and new
pixel values is based on the following sigmoid function:
)(1
1
)(
kxte
xf
Where the mapping function m(x) employed is:
osxsfxm )()( where
)0()255(
255
ff
s
and )0(sfso
The latter values s and so are used to rescale the sigmoid function to the range 0..255
for pixel (x) values in 0..255.
The values t and k control the magnitude of the contrast stretch and the centre value
of the sigmoid curve respectively. Typically, t is between 0.0 and 0.4 and k is usually
around 128 (the mid-grey value). As with the contrast stretching described in class
(which used a different Sigmoid function) this function should compress the dynamic
ange of the
ight and dark regions and stretch the contrast of the mid-grey values.
Note however, altering the value of k
128 (eg. 220) will tend to contrast stretch
the
ighter regions, whilst a value of k
128 (eg. 32) will tend to contrast stretch
the darker regions.
The input and output images should again both be 8-bit unsigned integers.
The call for this function is of the form:
stretched_image = contrast_stretch(input_image,t,k);
An example output from the supplied test function contrast_test.m is shown below.
Write up your results and compare the results to histogram equalisation. Q: Under what
conditions does this approach tend to work well?
Above: An example contrast stretching for t=0.05 and k=128.
ELEC ENG 061/7060 Image Processing Page 4 of 7
Exercise 1B – ( 3% ) – The Alpha Trimmed Filter
Complete the implementation of the function alpha_trimmed(img,n,d1,d2) such
that it implements an n by n alpha trimmed mean filter similar to that described in
class. The value n may be any integer value (odd or even). Unlike the version given in
the notes, this version should employ two values d1 and d2 which are the number of
pixels to remove from the start and the end of the sorted list of elements before you
calculate the average. In this way an image with a different proportion of salt and
pepper samples can be dealt with.
The alpha trimmed filter is defined as:
valueslocal oflist sorted theis XXXXXXXXXXwhere)(
)(
1
),('
2
2
1 1
,
21
2
siS
ddn
yxI
dni
di
yx
The function sort() can be used to greatly simplify your solution. Also, you do not
need to wo
y about pixels close to the boundary in your solution.
The script alpha_test.m can be used to check your code.
Above: two example outputs from the test script for the Alpha trimmed filter.
Write up your results and include various examples and parameter combinations (not just
the one in the test script).
ELEC ENG 061/7060 Image Processing Page 5 of 7
Exercise 1D – ( 3% ) – Adaptive Median Filtering
Modify the function adap_med_filter(I) such that it implements a version of the
adaptive median filter described in lectures using 3x3 max/min filters and 3x3, 5x5
and 7x7 median filters. The pseudo-code for this is as follows:
Calculate local max/min estimates over 3x3 neighbourhood.
Precompute the 3x3,5x5 and 7x7 median filtered images.
At each location (i,j) in the image:
If value at (I,j) is same as the local max/min ( and max > min ) then
If the 3x3 median is the same as local max min then
If 5x5 median same as local max min then
…etc up to a 7x7 filter…
else replace with 5x5 median value.
else replace with 3x3 median value.
else use the original pixel value.
To do this you will need to modify the local functions med_filter(), max_filter() and
min_filter(). The max and min filters should be minor modifications of your median
filter solution (note - you only need to handle odd sized filter sizes). You may use the
MATLAB commands sort(), min(), max() and median() to assist in implementing the
med, max and min and median filtering steps. It is suggested you get your solution
working for a 3x3 median first before adding the layers required to use the 5x5 and
7x7 filters if required. Again, you may disregard pixels near the boundary when
calculating the median results.
Test your solution using greyscale imagery of your choice and the supplied script
adap_med_test(). You can modify the given test files to use other imagery.
Write up your results and include various examples (not just the one in the test
script). Try modifying the tests to increase the level of noise introduced into the
imagery and comment on the performance your solutions.
Above: An example output from the Adaptive median filter test script.
ELEC ENG 061/7060 Image Processing Page 6 of 7
Exercise 1E – (2%) – Written Questions
Write up your answers (in your own words) to the following questions and include them in
your assignment report:
1. (1%) You have been asked to setup a video surveillance camera to monitor stock on a
cattle station. The camera is required to have a 45-degree field of view to cover the
observable area. The tracking software to be used requires that any objects being
tracked must be at least 8x8 pixels in size in any captured imagery.
Q1: If the furthest distance cattle can be from the sensor is 50 metres and that a typical
cow is around 1.5metres in height, what is the minimum possible resolution of the
sensor a
ay? (include your working, you may assume the a
ay is square)
Hint: this can be worked out using some basic geometry and/or material covered in
lecture 1.
Q2: If we used a camera resolution of 512x512 pixels what would be the maximum
distance cattle