0% found this document useful (0 votes)
17 views8 pages

Session 2 Student Text1

This document discusses modeling random variables and classification using MATLAB. It contains two parts: 1. Modeling network traffic and classifying periods as "quiet" or "busy" based on packet transfer times. Conditional probability distributions are estimated from the data and used to build a maximum a posteriori probability classifier. 2. Segmenting an image into "hand" and "background" classes. Similar to the network traffic problem, conditional distributions will be estimated from pixel intensities and used to build a MAP classifier to segment the image. DIPimage, a digital image processing toolbox, is introduced for working with images in MATLAB.

Uploaded by

uki
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views8 pages

Session 2 Student Text1

This document discusses modeling random variables and classification using MATLAB. It contains two parts: 1. Modeling network traffic and classifying periods as "quiet" or "busy" based on packet transfer times. Conditional probability distributions are estimated from the data and used to build a maximum a posteriori probability classifier. 2. Segmenting an image into "hand" and "background" classes. Similar to the network traffic problem, conditional distributions will be estimated from pixel intensities and used to build a MAP classifier to segment the image. DIPimage, a digital image processing toolbox, is introduced for working with images in MATLAB.

Uploaded by

uki
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 8

ET3502/ET3260in/ET2505-D1 4 November 2005

Practical Stochastic Processes using MATLAB Session 2

Session 2 – Modeling Random Variables / Classification

Part 1 Modeling Network Traffic – Traffic Management

Part 2 Image segmentation


1. Introduction
2. DIPimage introduction
3. Segmentation procedure

Theory
Continuous and discrete random variables. Estimation of the PDF and the PMF. Expected
value. Variance. A priori probabilities. Law of total probability. Bayes’ theorem. MAP decision
rule. Classification/segmentation errors.

Part 1 Modeling Network Traffic – Traffic Management

Variations in transfer times of data packets can lead to loss of packets. It is therefore
important to determine the status of the network in terms of the instantaneous network
load. The simplest way the determine the network status is to discriminate between quiet
and busy periods. If the network management takes the type (quiet, busy) of period into
account, these two periods must be identified.

For a simple network that experiences alternating quiet and busy periods in traffic load, the
following data set could be observed: mixed_arrivaltimes.mat

a. Plot the data set in terms of packet number versus packet transfer time; paste the
plot into the text.

Answer:

b. We model the network status “quiet” and “busy” with the Bernoulli random variable
S. Then, S=0 indicates a quiet period and S=1 indicates a busy period. fX|S=0(x)
defines the PDF of (continuous) random variable X, given that X originates from a
quiet period.

Select subsets of the data representing “quiet” and “busy” periods on the network,
such that you have at least 100 samples for each period. Choose an appropriate PDF
to model the conditional random variables X|S=0 and X|S=1. Estimate the
parameters of both (conditional) PDFs. Plot the PDFs in two separate plots in overlay
with the relative frequencies. Make sure that the plots satisfy the requirements
imposed on PDFs (for instance, is the integral over the PDF equal to 1?).

Answer:

c. For continuous random variables the law of total probability is given by:

2-1
ET3502/ET3260in/ET2505-D1 4 November 2005
Practical Stochastic Processes using MATLAB Session 2

fX(x) = fX|S=0(x) P[S=0] + fX|S=1(x) P[S=1] (1)

Use the definition of the expected value of a continuous random variable and
equation (1) to show that:

E[X] = E[X|S=0] P[S=0] + E[X|S=1] P[S=1] (2)

Answer:

d. Estimate the a priori probabilities P[S=0] and P[S=1] using Equation (2), the PDFs
determined in assignment b, and the data.

Answer:

e. Use the results from assignments b. and d. to plot the marginal PDF fX(x) on top of
the relative frequencies of the data. Does the model fit to the data?

Answer:

We now have a random (stochastic) model that describes the behavior of the data packet
transfer times. On the basis of this model, we will build a “classifier” that determines whether
the status S of the network is quiet (S=0) or busy (S=1), given the observed transfer time of
one data packet.

f. Explain – on the basis of the two conditional PDFs obtained in assignment b – why
classifying the network status on the basis of the observed transfer time of a single
data packet can not be done error free.

Answer:

A commonly used approach to the classification problem is the Maximum A Posteriori


Probability (MAP) decision rule. In the MAP decision rule, a data sample is classified as S=0 if
the conditional probability of S=0 is larger than that of S=1, given the particular value of the
sample (see also page 305 of the course textbook). In other words:

2-2
ET3502/ET3260in/ET2505-D1 4 November 2005
Practical Stochastic Processes using MATLAB Session 2

(3)

g. Rewrite this equation in terms of the a priori probabilities of the classes S and the
conditional PDFs (i.e. use Bayes’ rule).

Answer:

h. Implement the decision rule derived under assignment g and apply the decision rule
to the data set. As a consequence, every sample X will be classified either as class
“quiet” (S=0) or “busy” (S=1).

Answer:

i. Plot the relative frequencies of the transfer times of the samples classified as class
S=0. Do the same for the samples classified as class S=1.

Answer:

The two plots in assignment h show that the decision rule effectively applies a threshold T to
the transfer times. Transfer times smaller than this threshold T are classified as S=0,
otherwise S=1. We can therefore reformulate 1 the decision rule derived in assignment f also
as:
(4)

Of course, this decision rule can also be implemented (and is actually simpler to implement
than the one under assignment h).

j. What is the value of T that the decision rule in assignment h automatically selected?

Answer:

1
To do this analytically can be sometimes very difficult.

2-3
ET3502/ET3260in/ET2505-D1 4 November 2005
Practical Stochastic Processes using MATLAB Session 2

k. Explain the advantage of starting with the MAP decision rule instead of with equation
(4) with a manually selected threshold T.

Answer:

l. As you explained in assignment f, the classification is not without error. I.e., transfer
times originating from class “quiet” are classified as “busy”, and vice versa. The
probability of error is given by

(5)

This probability Perr is dependent on the value of the threshold T. Calculate and plot
(in a single figure):
 the error P[D(x)=1|S=0],
 the error P[D(x)=0|S=1],
 the error Perr

on the basis of the PDF models developed above as a function of T . Find the value of
T for which Perr is minimized. Compare this value with the result under assignment j.
What is your conclusion?

Answer:

2-4
ET3502/ET3260in/ET2505-D1 4 November 2005
Practical Stochastic Processes using MATLAB Session 2

Part 2 Image Segmentation

1. Introduction

In the first part of this session, we introduced the concept of a decision rule to classify the
status of an IP-Network. In part two we will follow the same approach to segmenting the
image (or classifying the pixels in an image) into two classes, namely belonging to a “hand”
or to the “background”. Such segmentation is important in applications such as object
tracking using camera images.

The figure on the left shows a typical camera image. The right figure shows the desired
result of the segmentation procedure. It is important to realize that – like in part 1 of this
session – such error free segmentation is usually not possible.

2. DIP Image introduction

DIP image is a digital image processing (DIP) toolbox that has been developed at
TUDelft/Faculty of Applied Physics. This toolbox has several advantages with respect to the
image processing toolbox available in MATLAB. The main advantage of DIPimage is its
flexibilty in handling different data formats. This in contrast to the image processing toolbox
of MATLAB which requires unsigned 8-bit integers for images.

First of all, DIPimage has a user-friendly interface that opens when you type in

>> dipimage

From this window you can open images and apply manipulations on these images. The
actual code that is execute to perform certain manipulations, is outputted on the command
line. This can be used afterwards in your m-files.

An image in DIPimage is a DIPimage object, this object can be manipulated by means of the
default mathematical operators, like +,-,*,/ and relational operators like <, >, ==. Contrary
to default MATLAB operations, for DIPimage objects these manipulations are pixel wise
operations.

One considers an image as a matrix where each matrix element represents the intensity at a
certain pixel position. You can read a matrix into an image as follows:

2-5
ET3502/ET3260in/ET2505-D1 4 November 2005
Practical Stochastic Processes using MATLAB Session 2

>> A = 2*randn(100);
>> NA = dip_image( A )

This results in a DIPimage object with Gaussian noise of zero mean and variance 2. If the
semi-colon is omitted after a statement, the output is presented as an image.

Other possible DIPimage manipulations are, for instance,

>> B = rand(100);
>> NB = dip_image(B);
>> SUM = NA + NB;
>> MULT = NA * NB;
>> NA2 = NA + 2;

A DIPimage object can be converted to a default MATLAB matrix as follows

>> MLB = double(NA);


>> MLB2 = uint8(NA2);

For more information about DIPimage see the “DIPimage User Manual” and “DIPimage
Reference” reachable from the Help menu in the DIPimage interface.

3. Segmentation procedure

Color images have three or more color components, called channels. Cameras usually output
RGB images, i.e. an image with a red, green, and blue channel. Each pixel in the color image
therefore has three values [Rc , Gc , Bc]. For the segmentation, we will use one out of three
pure colors (namely pure red), defined as Rp = Rc/(Rc+Gc+Bc) . We model Rp as a random
variable.

The image hand1.ics contains the color image. The images hand1r.ics,
hand1g.ics, and hand1b.ics contain the three color components.

a. Visualize the four images. Then calculate and visualize the pure red color.

Answer:

b. Compare the Rc , Gc , Bc images with the pure red image Rp. What is the advantage of
using the pure red color instead of the RGB channels when segmenting this image
into hand and background?

Answer:

2-6
ET3502/ET3260in/ET2505-D1 4 November 2005
Practical Stochastic Processes using MATLAB Session 2

c. In order to segment the image into hand and background, we use the MAP decision
rule. To this end, you need to model and estimate the model parameters of:
 The conditional PDF or PMF2 of Rp in the background,
 The conditional PDF or PMF2 of Rp in the hand,
 The a priori probabilities P[background] and P[hand].

Plot the PDFs/PMFs and give all required (estimated) parameters.

Answer:

d. Derive and apply the MAP decision rule for segmenting the image into hand and
background. Display the segmentation result.

Answer:

e. Explain the cause of the classification/segmentation errors (wrongly classified pixels).


Which ways can you envision to reduce the number of segmentation errors?

Answer:

f. Can the decision rule derived in assignment d also be applied in case the hand is in
front of another background? In other words, how generally applicable is your hand-
detector? Which ways can you envision to improve the generality of the segmentation
procedure?

Answer:

2
In case you decide to model Rp as a discrete random variable, first reduce the sample space of Rp to
256 different values, i.e. quantize RP into 8 bit as follows: >> RPDiscrete = round(255*RP);

2-7
ET3502/ET3260in/ET2505-D1 4 November 2005
Practical Stochastic Processes using MATLAB Session 2

2-8

You might also like