联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp

您当前位置:首页 >> Matlab编程Matlab编程

日期:2018-11-20 09:11

UNIVERSITY OF BATH Dept. of Electronic & Electrical Engineering EE10134 MATLAB

1

LAB 6-8: MOTION DETECTION

OVERVIEW

This lab script describes a problem requiring the detection of motion between two images. It then

leads you through the different elements required for creating a MATLAB function to perform this

task. During these sessions you will have the opportunity to test your programme on some test images.

At the end you will submit your code and it may be tested on a number of unseen images to assess

the quality of the code.

This assessment accounts for 25% of the module, with the remaining 25% coursework comprising of

15% from the lab quizzes and 10% from a further assessment near the end of the course.

The deadline for submitting this assignment is 4pm Weds 28

th November (Week 9)

OBJECTIVES

After completing this experiment you should:

be able to apply computing techniques to two-dimensional data to solve a complex task

understand how digital images are represented and the basics of block-based video

compression

PREPARATORY WORK

Carefully read through the laboratory script. If any parts are not clear, re-read and if necessary make

a note of any points to ask the laboratory demonstrators. There will be an introductory Moodle quiz

to make sure that you have read the script. You will not be able to submit your work until you have

taken this quiz.

SUBMISSION & ASSESSMENT

PLAGIARISM

You are expected to carry out this assignment individually and your submission will be checked for

plagiarism using the University’s plagiarism detection software, Turnitin. Note that this will also detect

plagiarism from previous years. Previously students have been found guilty of plagiarism and have had

marks deducted of differing degrees depending on the severity of the incident. If you find the

assignment hard, it is better to submit an incomplete or reduced quantity of work than to copy

someone else and risk your academic career.

WHAT SHOULD BE SUBMITTED?

A single Word document that describes your solution to this task and separately a zip file containing

your m-files. If you don’t complete all the exercises, submit what you have done, explaining how far

you have got. Don’t submit late.

UNIVERSITY OF BATH Dept. of Electronic & Electrical Engineering EE10134 MATLAB

2

The university policy is that assignments should be marked anonymously. Therefore do not use your

name in any documents that you are submitting in the headers/footers or in the file title. If you wish

to label your documents, only use your SAMIS student code.

You should submit:

A zip file containing all the code you have written. This could include a number of script and

function files.

A single Word document containing all the code you have written

o The code should be suitably commented

o You should include images and results demonstrating the extent to which the code

works (as well as any input parameters required to achieve such images with the

submitted code, so that I can reproduce the results with your code if necessary)

o A reflection on how well your code does or doesn’t work, including a description of

any alternative solutions that you considered but discarded

LATE SUBMISSION (FROM PROGRAMME HANDBOOK)

If there are valid circumstances preventing you from meeting the submission deadline, the Director of

Studies may grant an extension to a submission date, or you might be eligible to register some

‘Individual Mitigating Circumstances’ (see programme handbook for details). If you have not been

granted an extension, then your marks will be limited as follows:

0-5 days late: maximum mark is the pass mark, 40%

>5 days late: maximum mark is 0%

HOW WILL THE COURSEWORK BE ASSESSED?

Excellent

(>75%)

In addition to the ‘Good’ criteria

The submitted code excels at performing the required task

The reflection shows an appreciation of alternative solutions to the problem

and an argument as to why a particular one was chosen

The submitted code is robust, i.e. it can cope with a wide range of unexpected

circumstances

Good

(60-70%)

Submitted code successfully achieves the task and this is clearly

demonstrated in the Word document

The code comments clearly explain how the code solves the task at the block

level as well as the line-by-line level

The commented code is complete, well-structured and well-presented

Adequate

(50-60%)

Partial code functionality demonstrated

The code has comments describing the function at the line-by-line level, but

does not adequately explain how the commands join to perform the task of a

code section

Marginal

(40-50%)

Limited code functionality demonstrated within commented code

Comments do not explain the code correctly

UNIVERSITY OF BATH Dept. of Electronic & Electrical Engineering EE10134 MATLAB

3

INTRODUCTION & BACKGROUND

Image sequences need a large number of bytes to represent them, placing excessive requirements on

digital storage and transmission. To improve this situation many satellite and cable companies use

video coding techniques to reduce the volume of data associated with the image sequences.

A key component of all video compression (or coding) schemes is motion estimation. If the motion

between two consecutive frames (a video frame is one of the many still images which compose the

complete moving picture) is known then, once the first frame has been transmitted, instead of

transmitting the second frame the motion field can be transmitted and used to reconstruct an

approximation of the second frame from the first frame. The reconstructed image will generally not

be exactly the same as the original second frame but provides a good approximation. An approach of

this type is much more efficient in terms of bandwidth than transmitting the full image information.

For example, consider a sequence in which a camera tracks a man walking along a pavement. The

background will largely be constant but its position in each frame will shift relative to the man. If these

shifts are found, they can be encoded and transmitted far more efficiently than sending lots of

complete video frames.

The motion estimation scheme employed by the Moving Picture Experts Group (MPEG) II standard is

block matching, in which small parts, or blocks, from the next frame to be sent are compared with a

number of blocks from the previous frame in the sequence and the closest match chosen.

The main stages of the block-based video coding scheme for two consecutive frames from an image

sequence are as follows.

1. The second frame is split into a series of non-overlapping sub-images, or blocks.

2. For each block from the second frame, the block that best matches it in the first frame is

found, using some measure of similarity/dissimilarity. The displacement between the

original and best match blocks is termed the motion vector. The motion field is then

defined as the set of motion vectors for all the blocks in the second frame.

3. Transmit the motion field

4. Reconstruct an approximation of the second frame using the motion field and the first

frame.

Figure 1: Frame 1 Frame 2

UNIVERSITY OF BATH Dept. of Electronic & Electrical Engineering EE10134 MATLAB

4

For example, consider the two frames shown above. The second frame has been ‘tiled’ into 16 nonoverlapping

blocks. In this example the only movement is caused by a translation of the camera

position and it is fairly easy to visually match up most of the blocks with positions in the first frame by

eye.

COURSEWORK TASK

Overall task: You are required to create a script to fully automate

the block matching algorithm using similar frames as those above

using your knowledge of programming in MATLAB.

There are two distinct steps: Compression and Reconstruction.

For the Compression step, your script will identify the most similar

block in the old frame (Frame 1) to each one in the new frame

(Frame 2). This results in a ‘motion field’.

For the Reconstruction step, you will create an approximate

reconstruction of Frame 2, using only Frame 1 and the ‘motion field’

calculated during the compression step.

The code should be tested with the images provided, so that

comparison can be made between the reconstruction of Frame 2 and

the original Frame 2, thus allowing assessment of the effectiveness

of your code.

Steps: See hints within the script for how to break down the problem

into smaller problems.

Greyscale images in MATLAB are represented as matrices, with values ranging between 0 (black) and

255 (white). Thus the command frame2(x,y) returns the value of the image frame2 at point x,y, often

abbreviated to f(x,y).

One metric that has been proposed to gauge the similarity between two blocks is the sum of the

absolute value of differences (SAVD), which is the total of the absolute value of the difference between

corresponding points in two N×N blocks. Mathematically this can be expressed as

SAVD =

N

x

N

y

f x y g x u y v

1 1

( , ) ( , )

where f(x,y) is as previously defined and g(x+u,y+v) is the intensity value at position ?? + ??, ?? + ?? in

frame1, where ?? and ?? are the displacements in the ?? and ?? directions respectively. The summation

adds the absolute value of the differences for all points in a square block of size ??????. If the blocks

from frame2 and frame1 are identical then the SAVD will be zero, otherwise the smallest SAVD occurs

at the best match position.

UNIVERSITY OF BATH Dept. of Electronic & Electrical Engineering EE10134 MATLAB

5

Any of the blocks in frame1 could be the best match for a block from frame2. However, evaluating

every possible matching block involves a lot of computational effort and to reduce this the inter-frame

motion is restricted to a limited range, constraining the area that needs to be searched. This process

is illustrated in Figure 2 in which matches for a block located at position (x,y) are searched for within

a search area of radius R and this determines the range of values for u and v that need to be used in

the SAVD equation. In practice it is often easier to use a square search area instead of a circular one,

for example by looking at u and v values from say -15 to +15.

R

Figure 2

If the SAVD is calculated at each point within the search window, the position with the minimum value

is selected as the best match and the motion vector for the block is then given as (u,v).

When the motion vectors for every block in frame2 have been found they can be used to construct an

approximation of frame2 from frame1.

Download the file test frame sequences from the MATLAB Moodle site into your MATLAB working

directory and use the load command to import the images. This will load two images from a sequence,

F1 and F2 (or frame1 & frame2), into your MATLAB Workspace.

The frames can be displayed by typing

imagesc(F1);

at the MATLAB command prompt. It may be necessary to set your colourmap by typing

colormap(gray);

Using square blocks of e.g. 30x30 pixels and a search area of your choice find the motion vector for

each block in frame2, using the SAVD. The resulting motion field should then be displayed by using

the MATLAB quiver command, as shown in the figures below.

UNIVERSITY OF BATH Dept. of Electronic & Electrical Engineering EE10134 MATLAB

6

NOTE

MATLAB contains an image processing toolbox that contains several commands/functions that carry

out complex tasks. The aim of this course is to teach you the basic concepts in programming. Therefore

you should not use commands from this toolbox, except for the very basic, such as imread and

imwrite. If in doubt whether any specific commands are permitted, please discuss with Dr Shields.

HINTS

You might find the following exercises helpful to do first before trying to solve this problem. Whilst

this is not compulsory, they are highly recommended if you are struggling.

Exercise 1:

Create a function to compute the Sum of the Absolute Value of

Differences (SAVD) for two matrices of identical size.

e.g. [SAVD] = calculateSAVD(Image1, Image2)

Notes:

1. Two images are provided as input arguments when this function

is called.

2. Two nested for loops would allow you to look at every pixel in

turn.

3. For each pixel position in each image you can find the value of

the difference between the pixel value in Image1 and the

corresponding pixel value in Image2.

4. Summing these differences will give you a single value for the

SAVD for the two input images.

5. You will need to call this function lots of times, so it is better for

it to execute quickly. So make it as simple as possible.

UNIVERSITY OF BATH Dept. of Electronic & Electrical Engineering EE10134 MATLAB

7

Exercise 2:

Create a function to find the location (i.e. row and column) of the

minimum value in a matrix.

e.g. [row, column] = findlocationofmin(matrix)

Useful commands: magic (to create a matrix for testing your

function), find

Exercise 3:

Work out how to display a green arrow with a linewidth of 5 at

position x0, y0 with direction u,v on the current figure using the

quiver command (u and v are the x and y components of the arrow).

Determine what happens when x0, y0, u and v are vectors rather

than scalars.


版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp