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...

1 answer below »
use code examples


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 basic colour correction, 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 incorrect 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 be 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 representation of this YUV420 format it produces a basic reconstruction of the original uint8 YUV image array. To keep things simple, the missing U and V values can simply be estimated by 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 array 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 RGBYUV and YUVRGB colorspace conversions (see. rgb2yuv() 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 correct 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 errors). 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 range of the bright 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 brighter 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="" ()="" where)(="" )(="" 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="" worry="" 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 array? (include your working, you may assume the array 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
Answered Same DayAug 17, 2020

Answer To: 7060 Image Sensors & Processing ELEC ENG 061/7060 Image Processing Page 1 of 7 7060 Image Sensors &...

Anupam answered on Aug 26 2020
158 Votes
A1_code/adap_med_filt.asv
% Adaptive median filter. Adaptively use up to 7x7 median filtering to
% remove salt and pepper noise from an image
%
function Iamf = adap_med_filt(I)
if (isa(I,'uint8'))
I=double(I(:,:,1))/255;
end
Iamf=I;
% find the nxn local maxima and minima images (required for your solution)
Imax = max_filter(I,3);
Imin = min_filter(I,3);
% compute 3x3, 5x5 and 7x7 median images (required for your solution)
Imed3 = med_filter(I,3);
Imed5 = med_filter(I,5);
Imed7 = med_filter
(I,7);
% ---- ADD YOUR CODE HERE ----
% SEE Assignment sheet for algorithm. In short if point is same as local max
% or min use med3x3, if still max or min use med5x5 else med7x7.
[rows,cols]=size(I)
for i=4:rows-4
for j=4:cols-4
if Iamf(i,j)==Imax(i,j) || Iamf(i,j)==Imin(i,j)
if Imed3(i,j)==Imax(i,j) || Imed3(i,j)==Imin(i,j)
if Imed5(i,j)==Imax(i,j) || Imed5(i,j)==Imin(i,j)
if Imed7(i,j)==Imax(i,j) || Imed7(i,j)==Imin(i,j)
Iamf=I;
%Iamf = rand(size(I)); % <-- dummy random noise result
% ---- ADD YOUR CODE HERE ----
return
% HINT: the basic implementation for the max,min and median functions is
% the same, so once yolu have one going the other two should be
% straightforward. I suggest you use a for loop structure similar to the one
% you would have used for the earlier noise filter.
% ----------------------------------------------------------------------
% MEDIAN FILTER
function Imed = med_filter(I,n)
halfn = floor(n/2);
Imed=zeros(size(I));
% ---- ADD YOUR CODE HERE ----
[rows, cols]=size(I);
% --- YOUR CODE TO GO HERE ---
for i=1+halfn :rows-halfn
for j=1+halfn:cols-halfn
window=I(i-halfn:i+halfn,j-halfn:j+halfn);
window_reshaped=reshape(window,1,n^2);
Imed(i,j)=median(window_reshaped);
end
end
%Imed = rand(size(I)); % <-- dummy random noise result
% ---- ADD YOUR CODE HERE ----
return
% ----------------------------------------------------------------------
% MAX FILTER - generate an image containing the max value over the nxn
% neighbourhood around each point in the image.
function Imax = max_filter(I,n)
halfn = floor(n/2);
Imax=zeros(size(I));
% ---- ADD YOUR CODE HERE ----
[rows, cols]=size(I);
% --- YOUR CODE TO GO HERE ---
for i=1+halfn :rows-halfn
for j=1+halfn:cols-halfn
window=I(i-halfn:i+halfn,j-halfn:j+halfn);
window_reshaped=reshape(window,1,n^2);
Imax(i,j)=max(window_reshaped);
end
end
%Imax = rand(size(I)); % <-- dummy random noise result
% ---- ADD YOUR CODE HERE ----
return
% ----------------------------------------------------------------------
% MIN FILTER- generate an image containing the min value over the nxn
% neighbourhood around each point in the image.
function Imin = min_filter(I,n)
halfn = floor(n/2);
Imin=zeros(size(I));
% ---- ADD YOUR CODE HERE ----
[rows, cols]=size(I);
% --- YOUR CODE TO GO HERE ---
for i=1+halfn :rows-halfn
for j=1+halfn:cols-halfn
window=I(i-halfn:i+halfn,j-halfn:j+halfn);
window_reshaped=reshape(window,1,n^2);
Imin(i,j)=min(window_reshaped);
end
end
%Imin = rand(size(I)); % <-- dummy random noise result
% ---- ADD YOUR CODE HERE ----
return
% ----------------------------------------------------------------------
A1_code/adap_med_filt.m
% Adaptive median filter. Adaptively use up to 7x7 median filtering to
% remove salt and pepper noise from an image
%
function Iamf = adap_med_filt(I)
if (isa(I,'uint8'))
I=double(I(:,:,1))/255;
end
Iamf=I;
% find the nxn local maxima and minima images (required for your solution)
Imax = max_filter(I,3);
Imin = min_filter(I,3);
% compute 3x3, 5x5 and 7x7 median images (required for your solution)
Imed3 = med_filter(I,3);
Imed5 = med_filter(I,5);
Imed7 = med_filter(I,7);
% ---- ADD YOUR CODE HERE ----
% SEE Assignment sheet for algorithm. In short if point is same as local max
% or min use med3x3, if still max or min use med5x5 else med7x7.
[rows,cols]=size(I);
for i=4:rows-4
for j=4:cols-4
if Iamf(i,j)==Imax(i,j) || Iamf(i,j)==Imin(i,j)
if Imed3(i,j)==Imax(i,j) || Imed3(i,j)==Imin(i,j)
if Imed5(i,j)==Imax(i,j) || Imed5(i,j)==Imin(i,j)
if Imed7(i,j)==Imax(i,j) || Imed7(i,j)==Imin(i,j)
Iamf(i,j)=I(i,j);
else
Iamf(i,j)=Imed7(i,j);
end
else
Iamf(i,j)=Imed5(i,j);
end
else
Iamf(i,j)=Imed3(i,j);
end
else
Iamf(i,j)=I(i,j);
end
end
end
%Iamf = rand(size(I)); % <-- dummy random noise result
% ---- ADD YOUR CODE HERE ----
return
% HINT: the basic implementation for the max,min and median functions is
% the same, so once yolu have one going the other two should be
% straightforward. I suggest you use a for loop structure similar to the one
% you would have used for the earlier noise filter.
%...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here