Você está na página 1de 46

PHASE-I

STUDY

Objective:To study about Simulink and model


based design.
An introduction to MATLAB.
To understand
modelling.

the

process

of

Page | 1

-- Chapter: 1--

SIMULINK : An INTRODUCTION
Simulink is a tool available in MATLAB. It provides an environment for
simulation of Model Based Design. It supports system level design, automatic
code generation and continuous test & verification of embedded system. Some
of its features are as follows:

Graphical editor for building and managing block diagrams.


Libraries of predefined blocks.
Scope and data displays for viewing simulation results.
Legacy Code Tool for importing C & C++ code into models.

Data or information are forwarded from one block to another by lines


connecting each other. It also allows to view the result in blocks called scope
or displays as well as allows to save the result to a file.
Inside Simulink, the environment acts as a physical laboratory to Model,
Design, Analyse as required by a user. It provides necessary examples as well for
better understanding of a model. It also provides us with a library consisting of
various tools necessary.
Simulink software requires MATLAB to run, and it depends on it to define
and evaluate model and block parameters. Simulink can also use many MATLAB
features. For example, Simulink can use the MATLAB environment to:
Define model inputs.
Store model outputs for analysis and visualization.
Perform functions within a model, through integrated calls
to MATLAB operators and functions

Page | 2

-- Chapter: 2--

MODEL BASED DESIGN


Before moving further into Simulink, we must understand what a Model
Based Design is.
A Model Based Design is the process that enables designing of dynamic
system in fast and cost-effective way. In this process, the system model that is
being design is focused primarily. Everything starting from requirements,
designing, testing and to analysing depends on the system model. The model
thus designed is an executable specification of the system, and at the end, the
system shows, whether the model works correctly or not.
Model design improves efficiency by: Using a common design environment across project teams.
Linking designs directly to requirements.
Integrating testing with design to continuously identify and
correct errors.
Refining algorithms through multi-domain simulation.
Generating embedded software code.
Developing and reusing test suites.
Generating documentation.
Reusing designs to deploy systems across multiple
processors and hardware targets.

Page | 3

-- Chapter: 3--

An INTRODUCION to MATLAB
MATLAB, is a software package developed by Math Works Inc. that is used
to perform scientific computations & visualization. Its capability for analysis of
various scientific problems flexibility and graphic makes it a very useful software.
It provides an integrated development environment for programming with
numerous predefined functions for technical computations and visualization.
The environmental components of MATLAB comprises of the following:1. Command Window This is the main window that is activated as soon
as MATLAB is started. In this window commands are entered and
executed in a similar fashion as in C environment.
2. Command History As the name itself describes, it contains all the
commands that have been entered and executed.
3. Workspace Similar to C, variables are generated in MATLAB. The
Workspace contains all the variables that have been generated.
4. Current Directory It lists all the files and folders present in the current
directory similar to DOS.
5. Edit Window This window is used when we are required to create a
script or a function.
6. Figure Window This window is invoked through command when we
are in need to display a graphical representation.
MATLAB has its own file types:1. M Files :- It is an extension that denotes a script or function of MATLAB.
a. A script is a file that contains a set of MATLAB commands. This file
does have its own variable and uses the variables stored in
workspace for its functionality.
b. A function is a file that begins with function definition and similar
to a C program it has its own program and variables.
2. MAT Files :- They denote a binary data file of MATLAB that is saved by
save command.
3. MEX Files :- This type of file contains FORTRAN or C program and is
callable in MATLAB. This file helps in integrating FORTRAN or C language
into programs developed by MATLAB.
Page | 4

MATLAB Operations:- Because Matlab is mathematics based, it can


perform all those operations as performed in mathematics
Some common operation are :Let s take two variables p=3 ; q=2
1. Arithmetic Operations
Operator

Operation

Expression

Result

Addition

p+q

Subtraction

pq

.*

Multiplication

p*q

./

Left Division

p ./ q

1.5

.^

Power

p .^ q

Unary Plus

+p

+3

Unary Minus

-P

-3

Table 1. Arithmetic Operations

2. Relational Operations
Operator

Operation

Expressio
n

Result

<

Less than

p<q

<=

Less than or equal to

p <= q

>

Greater than

p>q

>=

Less than or equal

p >= q

==

Equal to

p == q

-=

Not equal to

p -= q

Table 2. Relational Operations

Page | 5

3. Logical Operations and functions : Let us declare the following variables A=2; B=5; C=-4; D=0
Operator

Function

Description

Expression

Result

&

AND - Returns 1 if both


elements are true

A&B

OR - Returns 1 if either one


elements is true

A|B

Not Compliments the


element

~C

xor()

Returns 1 if only one


element is true

xor(A,B)

any()

Returns 1 if any element of


vector is non-zero

any(A,B)

all()

Returns 1 if all elements are


non-zero

all(A)

Table 3. Logical Operations & functions

MATLAB Functions & Assignments:- Matlab introduces functions and


assignments similar to C program.
Function declaration :- function_name (variable_name or expression)
E.g-

matlab statement :output:-

[ lets say x=2;y=3;z=4]


x = 2; y = 3; z = 4;
a = log(sqrt(x/(y*z)))
a = -0.8959

Assignment Statement :- variable_name = expression


E.gmatlab statement :r = 9;
circle_area = pi*r*r
output:circle_area = 254.4690

Page | 6

Some predefined functions : Cart2pol convert cartesian to polar.


Factorial gives factorial of a number.
Pol2cart convert polar to Cartesian.
Imag returns imaginary part.
Real returns real part.
Tand returns tangent from degrees.
MATLAB Vectors:- Matlab allows declarations of vectors as well as
operations between vectors.
Row Vector it is a (m x 1) matrix which has m number of rows but
a single column. It is declared as
p = [1,2,4]
Column Vector it is a (1 x n) matrix which has n number of columns
but a single row. It is declared as
q = [3;5;6]
Vector Product :- A row & vector can be multiplied with each other,
however these vectors should be of the same length.
matlab statement:r=p*q
Outputr=37
Vector Transpose:- Turns row into column & column into row
matlab statement:pt=p
qt=q
Output:p=1
q=3 5 6
2
4
Some commands for vectors:sum(p)
gives the sum of ass the elements.
mean(p)
gives the average of the elements.
length(p) gives the total number of elements.
max(p)
gives the maximum value among the elements.
min(p)
gives the minimum value among the elements.
MATLAB Matrix :- In matlab, matrix is a rectangular array of real or
complex numbers.
Matrix creation
E.g matlab syntax
A=[5 10; 15 20]; B=[2 4; 6 8]
output
A = 5 10
B= 2 4
15 20
6 8

Page | 7

Addition:-

C=A+B

output-

7 14
21 28

Subtraction:-

C=A-B

output-

3 6
9 12

Multiplication:-

C=A*B

output-

70 100
150 200

MATLAB Graphics:- Matlab provides very good tools for 2D and 3D plots.
2d plot Plot command is used to plot 2d graphs.
E.g A Matlab program to plot a row vector having complex
number:a=[1-2i,3+4i,5+6i,3+8i,4+9i,23+12i];
plot(a);
grid on;
xlabel('x-axis');
ylabel('y-axis');

Figure 1. Plot of complex row vector

Page | 8

Bar Graph- Bar command is used to display bar graph.


E.g A Matlab program to display a bar graph
a=[ 0 1 2 3 4 5 6];
b=[10 15 25 20 30 27 19];
bar(a,b);
xlabel('x-axis');
ylabel('y-axis');
title(Bar graph')

Figure 2. Bar graph

Pie Chart The function pie(x) displays a pie chart.


E.g A matlab program to display a pie chart
industry = [ 4 8 20 2 7 10];
pie(industry);
title('Pie Chart')

Page | 9

Figure 3. Bar graph

Mesh plot the mesh function displays a 3D wireframe plot


E.g A Matlab program to display mesh function
[x,y] = meshgrid(-5:0.1:5);
z=2./(x.^2+y.^2+1);
mesh(x,y,z);
grid on;
title('Mesh plot');
xlabel('x-axis');
ylabel('y-axis');
zlabel('z-axis');

Figure 4. Mesh plot


Page | 10

Surf Plot Displays a 3D surface plot.


E.g - A matlab program to display a surf plot
[X,Y,Z] = peaks(25);
figure;
surf(X,Y,Z);
xlabel('x-axis');
ylabel('y-axis');
zlabel('z-axis');

Figure 5. Surf plot

Page | 11

-- Chapter: 4--

SIMULINK: MODELLING WORKFLOW


Modelling is the process where a dynamic system is described with
mathematical equations and a simplified representation of the system is made
with the model. Modelling workflow has there steps: Defining a System
Modelling the System
Integrating the System
Defining a system:In this step, the components of a system is done, physical characteristics
are determined, and define dynamic behaviours are determined with equations.
These steps are performed outside of the Simulink software environment and
before building the model.
The structure can be given as :Determining
modeling goals

Identify system
components

Define system
equation

Collect parameter
data

Figure 6. Defining a system

Determining modelling goals - Before designing a model, requirements


and goals must be understood.
Understand how system components interact with each other.
Explore controller and fault-tolerance strategies.
Decide between alternative designs.
Observe the response of systems that cannot be solved analytically.
Determine how various inputs and changing model parameters
affect the output.
Identify system components
Identify the components that correspond to structural parts of
the system.
Page | 12

Creating a model that reflects the physical structure of a system.


Identify functional parts that can be independently model and
test.
Describe the relationships between components.
Draw a picture showing the connections between components.
Include major parameters in the diagram.
Creating a picture of the system can help identify and model the
parts that are essential to the behaviours and are required to be
observed.
Define System Equation After identifying the components in system, the
system can now be described mathematically with equations. The
equations are derived using scientific principle or from input-output
response of measured data. System equations mainly falls into three
categories of system
Continuous Differential equations describe the rate of change
for variables but the equations are defined for all values of
times. For e.g the velocity of a car is given by difference
equation
dv(t)/dt= -(b/m)v(t)+u(t)

Discrete Difference equations describe the rate of change for


variables but the equations are defined only at specific times.
For e.g the control signal from a discrete propositionalderivative control controller is given by the difference equationpd[n]=(e[n] - e[n - 1])Kd + e[n]Kp

Without derivatives Equations without derivatives are


algebraic equations. For e.g the total current in a parallel
circuit with two components is given by algebraic equation
It = Ia + Ib

Collect Parameter Data Perform experiments on the system to


determine coefficient values of constant coefficients or collect from
published sources to create a list of equation variable and coefficients.
Use measured data from a system to define equation coefficients and
parameters on the system.
Measurable parts are identified in a system.
Page | 13

Physical characteristics are measured or published property values


are used
Data sheets from manufacturer are a good source for hardware
values.
Experiments are performed to measure the system response
towards various inputs.
Later this data will be used to verify the model design with
simulations
Modelling the System:In this step individual model components are build that implement the
system equations, and define the interfaces for passing data between
components.
The structure can be given as:Model top level
structure

Model component

Simulate component

Change model

No

Expected
Result

Yes
No

Finished
Modelling?
Figure 7. Modelling a system

Page | 14

Model Top Level Structure In Simulink a model is a graphical


representation of a system, using blocks and connections between blocks.
After describing the system is finished, its components, and equations, we
can now can begin to build the model.
System equations are used to build a graphical model in Simulink
editor
If all of the model blocks are placed in one level of a diagram, the
diagram can become difficult to read and understand. One way to
organize the model is to use subsystems. Examples of blocks that
can be used to create a subsystem include Subsystem, Atomic
Subsystem, and Model.
Input and output connections are identified (for example, signal
lines) between subsystems. Input and output values change
dynamically during a simulation.
Model Component After the top-level structure is created for the model,
we can now begin to model the individual components.
System equations are used to create a Simulink model.
Add Simulink blocks in the Simulink Editor. Blocks represent
coefficients and variables from the equations. Connect blocks to
other blocks. Lines connecting blocks represent data transfer.
Build the model for each component separately. The most effective
way to build a model of a system is to consider components
independently.
Start by building simple models using approximations of the
system. Identify assumptions that can affect the accuracy of the
model. Iteratively add detail until the level of complexity satisfies
the modelling and accuracy requirements.
Simulate Component After the model component is built, we can
simulate to validate the design.
Predict the expected output of the integrated model components.
Blocks are added to approximate actual input and control values.
Sink blocks are added to record and visualize results.
Validate the model design by comparing the simulation output to
the expected output.
If the result does not match the prediction, change the model to
improve the accuracy of the prediction. Changes include model
structure and parameters.

Page | 15

Integrating the simulation:Connect component models and simulate the model response over time
to validate the design.
The structure can be given as:-

Connect model
components

Simulate connected
components

Change model

No
Expected result

Yes
Model external
interface

Figure 8. Integrating the system

Connect Model Components After each model built and validated, it can
be connect to create a complete model, then the model is simulated, and
results are analysed. Some guidelines for connecting model components:
Integrate model components by first connecting two of them (for
example, connect a plant to a controller).
After validating the pair by simulation, continue connecting
components until the model is complete. It must be kept in mind

Page | 16

how each component that has been added affects the other parts
of the model.
Simulate Connected Components Validating the model determines if it
accurately represents the physical characteristics of the modelled
dynamic system. Some guidelines for validating subsystems:
Predicting the expected simulation results and outputs of the
subsystems.
Adding realistic inputs using source blocks.
Adding sink blocks to record and visualize results. Simulate the
subsystems and compare the simulated result with the expected
result.
Model External Interface Blocks for connecting external signals into and
out of the model are added.

Page | 17

-- Chapter: 5--

SIMULINK: SIMULATION WORKFLOW


Simulation is a process in which validation and verification of a model is
done by comparing simulation results with:
Data collected from real system.
Functionality described in model requirements.
After the building of model is done, simulation is performed which consists of
two steps: Prepare for simulation.
Run and evaluate simulation.
Prepare for simulation:The external input and output interfaces are defined
The structure can be given as follows:-

Determine
simulation
goals

Collect data

Prepare
model

Set
parameters

Figure 9. Prepare for simulation

Determine simulation goals Before simulating a model, we need to


understand the goals and requirements.
Understand input to output causality for a given input set and
nominal parameter values, look at how the inputs flow through the
system to the outputs.
Verify model Compare simulation results with collected data
from the modelled system. Iteratively debug and improve the
design.
Optimize parameters Change parameters and compare
simulation runs.
Visualize results Send simulation results to a plot or print in a
report.
Page | 18

Collect Data Input and output data from an actual system is collected.
Measured input data is used to drive the simulation. Measured output
data is used to compare with the simulation results from the model.
Measured input data is used to drive a simulation and measured output
data to verify the simulation results.
Prepare model Preparing a model for simulation includes defining the
external interfaces for input data and control signals, and output signals
for viewing and recording simulation results.
Set Parameters For the first simulation, model parameters from the
validated model is used. After comparing the simulation results with
measured output data, model parameters are changed to more
accurately represent the modelled system.
Run and evaluate the simulation:Simulate the model and verify that the simulation results match the
measured data from the modelled system.
The structure can be give as:-

Import data

Run simulation

Change model

Evaluate result

Expected
result

No

Yes
Connect
component
model

Figure 10. Run and evaluate


simulation

Page | 19

Import Data Simulink allows the import of data from external files such
as Excel Sheets or Comma Separated Value (CSV) files if necessary.
Run simulation Using measured input data, a simulation is run and save
results.
Evaluate result The differences between simulated output and
measured output data are evaluated. The evaluation is used to verify the
accuracy of the model and how well it represents the system behaviour.
Decision is taken whether the accuracy of the model adequately
represents the dynamic system that was being modelled.
Change model If necessary determine the changes to improve the
model. Model changes include:
Parameters if some parameters were initially estimated and
approximated. Optimize and update those parameters.
Adding structure if some parts or details of the system were not
modelled. Add missing details.

Page | 20

PHASE-II

DESIGN

Objective:To understand about COLOUR,


DIGITAL IMAGE & HISTOGAM.
To design a simulation in SIMULINK
that displays the histogram of
colour image.
To design a simulation for Image
Enhancement.
Page | 21

--Chapter: 6--

COLOUR, DIGITAL IMAGE & HISTOGRAM


What is COLOUR?
Physically, colour has no existence, it can be called an illusion. Simply
speaking, it is just a combination of light consisting of various wavelengths as
well as frequencies and light is one form of energy that can be actually seen. The
reason we see colour is because inside our eyes there are some special rods that
reacts with the different intensities giving the illusion of colour. Light spectrum
contains only three basic colours RED, GREEN & BLUE, and each of these
colours have their own intensities and combination of these colours in different
intensities gives rise to various different colours that we see.

What is a Digital Image?


A two dimensional image can be numerically represented so that it can be
viewed in electronic devices. This numerical representation is called a digital
image. The numerical representations are such that it creates a digital value
called pixels that describes the colour content and how bright (also called
intensity) the pixel is.

Colour Model & Colour Space in Digital Imaging


Mathematical application have created a model that can describe colour
as rows of numbers, and this model is known as COLOUR MODEL.
Now, since a colour model consists of numbers, the origin of each colour
and its type is described by a number which is known as COLOUR SPACE.
Although there are many different types of colour models, this project
endeavours to discuss only on those colour models that relates to the research
project at hand.
Types of Colour Models:-

Page | 22

1. Grayscale Colour Model Grayscale simply means black and white. In this
model representation of colour is done in a single sample, i.e. the only
information it has is that of the intensity. The colour black and white, as
said earlier is nothing but the combination of similar intensities of all RGB
colour, because of which it is possible to represent them in a single
sample. Digital imaging provides a way to represent the intensities of each
pixel by creating a range from minimum to maximum. Modern
approaches have used 8bit to sample a grayscale, which means it has 256
different intensities to measure where 0 is the lowest and 255 is the
highest.

Figure 11. Grayscale colour model

2. RGB Colour Model The RGB colour model is called an additive colour
model, i.e. apart from RGB colour, all other colours are created by
adding RGB in various ways. This model is mostly used in electronic
systems, and its basic purpose is to represent an image for displaying in
those electronic systems. Now, to create a colour apart from RGB, a
simple procedure is done which is to just to superimpose the three RGB
coloured lights with different intensities. The perception of Black colour
is given when the intensities of each of the RGB colour is none and for
White colour, the intensities of each RGB colour is full.

Page | 23

Figure 12. RGB colour model

What is Histogram?
Introduced by KARL PEARSON, histogram is the representation of
numerical data in graphical format. Statistically speaking it represents the
frequency of an object at which it is being distributed. Therefore in digital
imaging, histogram will represent the frequency at which pixels are being
distributed over the entire image. In image processing there are many
applications such as- Image segmentation, image restoration, image
enhancement etc., all of which depends on the data provided by histogram.
The histogram representation is done in a two dimensional axis.
Horizontal axis (x-axis) represents the intensities where the extreme left displays
the darker intensities and as it moves toward the right it represents the lighter
intensities and ultimately as it reaches the extreme right, it represents the white
intensities. The vertical axis (y-axis) represents the frequency of pixels of that
particular intensity. When we say histogram of an image. we generally mean
the intensity levels of a grayscale image. However it is also possible to find the
histogram of a colour image as well.

Figure 13. Histogram of a grayscale image

Page | 24

What is Colour Histogram?


Just like a normal histogram, a colour histogram also represents the
frequency at which pixels are being distributed over the entire image, however
in this case, it represents each of the data of Red, Green & Blue pixel separately.

Figure 14. Histogram of a Colour image

Process of Histogram
Let us consider a grayscale image A, then
H(k) =Histogram of image A.
Let us say the gray levels are in the range [0, L-1]
The histogram H(k), say, is derived by counting the number of pixels at
each & every gray level k .
H(k) = Nk for k = 0,1,2..L-1;
Where,
Nk is the count of pixels at gray level k,
Therefore, L = total number of bins in the histogram.

Page | 25

Theoretically, the maximum value for L is determined by the pixel depth


M of an image. For instance, for a grayscale image of M = 8 bit, we can have up
to 2M = 256 = L bins whereas for a binary image (1-bit) we can have just 2 bins.
The aforementioned process has been describe for grayscale image, however,
for RGB image the same process is implied, except that, the three RGB channels
are separated at first, and histogram of each channel is calculated separately.

Page | 26

--Chapter: 7--

SIMULINK for HISTOGRAM GENERATION


Now that we have learned about histogram and colour, let us now
continue to our objective Simulating the Histogram generation of Colour
Image. This simulation will help us in displaying what are the process that
follows in finding the histogram of a colour image.

Starting Simulink
1. Open Matlab
2. Click on New -> Simulink Model. (This will open Simulink library browser)
3. In the Simulink library window click on File->New->Model (This will open
Simulink environment)
4. Now browse through the library and add the following models by dragging
them onto the Simulink environment.
Block
Image from file
Video Viewer
Matrix Concatenate
Vector Scope
Histogram

Library
Computer Vision ->
Sources
Computer Vision ->
Sources
Simulink -> Math
operations
DSP System Toolbox > Sinks
DSP System Toolbox > Statistics

Quantity
1
1
1
4
3

Table 4. List of blocks to be used with its quantity and library set

Page | 27

Page | 28

Figure 15. RGB histogram generating model


in SIMULINK

Now set the following parameters: Use the Image From File block to import an RGB image. Set the
block parameters as follows:
o Sample time = inf
o Image signal = Separate colour signals
o Output port labels: = R|G|B
o On the Data Types tab, Output data type: = double
Use the Video Viewer block to automatically display the original
image in the viewer window when you run the model.
o Set the Image signal parameter to Separate colour signals
from the File menu.
Use the Histogram blocks to calculate the histogram of the R, G, and
B values in the image. Set the Main tab block parameters for the
three Histogram blocks as follows:
o Lower limit of histogram: 0
o Upper limit of histogram: 1
o Number of bins: = 256
o Find the histogram over: = Entire Input
The R, G, and B input values to the Histogram block are doubleprecision floating point and range between 0 and 1. The block creates 256
bins between the maximum and minimum input values and counts the
number of R, G, and B values in each bin.
Use the Matrix Concatenate block to concatenate the R, G, and B
column vectors into a single matrix so they can be displayed using
the Vector Scope block. Set the Number of inputs parameter to 3.
Use the Vector Scope block to display the histograms of the R, G,
and B values of the input image. Set the block parameters as
follows:
o Scope Properties pane, Input domain = User-defined
o Display Properties pane, clear the Frame number check box
o Display Properties pane, select the Channel legend check box
o Display Properties pane, select the Compact display check
box
o Axis Properties pane, clear the Inherit sample increment
from input check box.
Page | 29

o
o
o
o
o

Axis Properties pane, Minimum Y-limit = 0


Axis Properties pane, Maximum Y-limit = 1
Axis Properties pane, Y-axis label = Count
Line Properties pane, Line markers = none|none|none
Line Properties pane, Line colours
For the scope used to compare = [1 0 0]|[0 1 0]|[0 0 1]
For the scope for Red = [1 0 0]
For the scope for Green = [0 1 0]
For the scope for Blue = [0 0 1]
Open the Configuration dialog box by selecting Model
Configuration Parameters from the Simulation menu. Set the
parameters as follows:
o Solver pane, Stop time = 0
o Solver pane, Type = Fixed-step
o Solver pane, Solver = Discrete (no continuous states)
Select desired image file in Image From File and run the model.

Figure 16. Image viewer block displaying a colour image

Page | 30

Right click on each of the graph and select auto scale

Figure 17. Vector scope displaying the histogram of RED channel

Figure 18. Vector scope displaying the histogram of GREEN channel

Page | 31

Figure 19. Vector scope displaying the histogram of BLUE channel

Figure 20. Vector scope displaying histogram of all three RGB channels for
comparison
Page | 32

Understanding the simulation:To understand how the simulation worked let us understand the different
blocks used in the simulation First we used the Image from File block to read an image from the
computer as desired by the user. If the image is an M-by-N array, the block
outputs a binary or intensity image, where M and N are the number of rows and
columns in the image. If the image is an M-by-N-by-P array, the block outputs a
colour image, where M and N are the number of rows and columns in each
colour plane, P. The Image signal parameter of this block is used to specify how
the block outputs a colour signal. If One multidimensional signal is selected, the
block outputs an M-by-N-by-P colour video signal, where P is the number of
colour planes, at one port. If Separate colour signals is selected, additional
ports appear on the block. Each port outputs one M-by-N plane of each Red
Green and Blue signal separately.
Now comes the Video Viewer block. The Video Viewer block allows to
view a binary, intensity, or RGB image or a video stream. The block provides
simulation controls for play, pause, and step while running the model.
The Histogram block calculates the histogram from the input values.
The Matrix Concatenate block concatenates the signals at its inputs to
create an output signal whose elements reside in contiguous locations in
memory.
The Vector Scope block is a comprehensive display tool similar to a digital
oscilloscope. The block plots each sample of each input channel sequentially
across the horizontal axis of the plot.

Now let us understand how the simulation has worked:The Image from File block reads an image, and separates the three RGB
channels. Each channel is connected to independent Histogram blocks that
calculates the histogram of its input signal. To view the image, the three RGB
channels are also branched and connected to the Video Viewer block which
displays the image that has been selected. The Vector scope connected to each
separate Histogram block displays the output of the histograms in separate
graphs. We have also branched the output signal of each Histogram block to
the Matrix Concatenate block that combines all the three different signal and
Page | 33

sends the output signal to a Vector Scope that displays all the three signals in a
single graph allowing us to compare the histograms of the RGB channels.

Page | 34

--Chapter: 8--

IMAGE ENHANCEMENT
Image Enhancement
The aim of image enhancement is to improve the interpretability or perception
of information in images for human viewers, or to provide `better' input for
other automated image processing techniques.
Image enhancement techniques can be divided into two broad categories:
1. Spatial domain methods, which operate directly on pixels,
a. Contrast and dynamic range modification
b. Noise reduction
c. Edge enhancement
2. Frequency domain methods, which operate on the Fourier transform of
an image.
However, there is no general theory for determining what `good
enhancement is when it comes to human perception. But when
enhancement techniques are used as pre-processing tools for other
processing techniques, then quantitative measures can determine
techniques are most appropriate.

image
image
image
which

Image Enhancement is often used by photographers, professional photo


editors, etc. and these enhanced image is what we see in the newspapers,
magazines, brochures etc.
In the previous section we understood about histogram and how it is
related to colour images, now let us see an application of histogram for Image
Enhancement based on Spatial Domain Method. Image enhancement is done
through a process called Histogram Equalization.

What is Histogram Equalization ?


Histogram Equalization is a Spatial Domain method of image
enhancement that effects the contrast of the image by adjusting the images
histogram. This method usually increases global contrast of many images,
Page | 35

especially when the usable data of the image is represented by close contrast
values. Through adjustment, the intensities can be better distributed on the
histogram. This allows for areas with lower contrast to gain a higher contrast.
Histogram equalization redistributes the pixel intensity values evenly by
using cumulative (sum) histogram as a transfer function or as a look-up table.
The idea of histogram equalization comes from the cumulative histogram.

Figure 21. The projected intervals get wider or narrower


based on the slope of cumulative histogram.

Looking at the image above, we can see that the frequencies (the number of
pixels) at each intensity value are accumulated. The higher pixel density is, the
greater steepness is. There are 2 intervals with same width, but different slopes;
one interval has slow steepness, and the other interval has steep slope. Let's
project the intervals of the intensity values onto the other axis. Once they are
projected, they have different intervals on the projected axis. If the slope is less
than 1, the interval gets narrower. If the slope is greater than 1, then the interval
is going to be wider. In other words, we are going to spread the intensity range
if the pixel density is high, and shrink the interval if the density is low. Histogram
equalization works best on an over or under exposed image, which has narrow
contrast range.

Page | 36

Process of Histogram Equalization


Consider a discrete grayscale image {x} and let ni be the number of occurrences
of gray level i. The probability of an occurrence of a pixel of level i in the image
is

L being the total number of gray levels in the image (typically 256), n being the
total number of pixels in the image, and
being in fact the image's
histogram for pixel value i, normalized to [0,1].
Let us also define the cumulative distribution function corresponding to px as

,
Which is also the image's accumulated normalized histogram.
We would like to create a transformation of the form y = T(x) to produce a new
image {y}, with a flat histogram. Such an image would have a linearized
cumulative distribution function (CDF) across the value range, i.e.

for some constant K. The properties of the CDF allow us to perform such a
transform; it is defined as

where k is in the range [0,L). Notice that T maps the levels into the range [0,1],
since we used a normalized histogram of {x}. In order to map the values back
into their original range, the following simple transformation needs to be
applied on the result:

Page | 37

The aforementioned, describes histogram equalization on a grayscale


image. However it can also be used on colour images by applying the same
method separately to the Red, Green and Blue components of the RGB colour
values of the image. However, applying the same method on the Red, Green,
and Blue components of an RGB image may yield dramatic changes in the
image's colour balance since the relative distributions of the colour channels
change as a result of applying the algorithm. But, if the image is first converted
to another colour space, Lab colour space, or HSL/HSV colour space in particular,
then the algorithm can be applied to the luminance or value channel without
resulting in changes to the hue and saturation of the image.
For the research project at hand, we will use HSV Colour Space

HSV Colour Model


This is a three dimensional colour model that displays the HUE,
SATURATION and VALUE.
HUE The HUE (H) of colour refers to which pure colour it resembles.
SATURATION The SATURATION (S) describes how white the colour is. A pure
white means fully saturated
VALUE The VALUE (V) also called lightness describes how dark the colour is.
i.e. it refers to the intensity.

Figure 22. HSV Colour Model


Page | 38

Conversion between RGB & HSV colour space


The conversion from R'G'B' to HSV Colour Spaces is done as follows:The R,G,B values are divided by 255 to change the range from 0..255 to 0..1
R = R/255
G = G/255
B = B/255
Cmax = max(R,G,B)
Cmin = min(R,G,B)
= Cmax Cmin

H=

((G-B)/)/6
(2+ (B-R)/))/6
(4+ (R-G)/))/6

If R = Cmax
If G = Cmax
If B = Cmax

S = /Cmax
V = Cmax
The HSV to R'G'B' conversion is defined by the following equations:
H, S, and V vary from 0 to 1, where 1 represents the greatest saturation and
value.

Page | 39

--Chapter: 9--

SIMULINK for HISTOGRAM EQUALIZATION


Simulink Design
Block
Image from file
Video Viewer
Matrix Concatenate
Vector Scope
Histogram
Histogram
Equalization
Colour Space
Conversion

Library
Computer Vision -> Sources
Computer Vision -> Sources
Simulink -> Math operations
DSP System Toolbox -> Sinks
DSP System Toolbox ->
Statistics
Computer Vision -> Analysis
& Enhancements
Computer Vision ->
Conversions

Quantity
1
2
2
2
6
1
2

Set Model Configuration Parameters and block parameters as same as the


previous model.
For the first Colour Space Conversion block set parameter as RGB to HSV
For the second Colour Space Conversion block set parameter as HSV to RGB

Page | 40

Page | 41

Figure 23. Histogram Equalization in SIMULINK

Running the simulation will result in the following:-

Figure 24. ORIGINAL image

Figure 25. EQUALIZED Image

Page | 42

Figure 26. HISTOGAM of Original Image

Figure 27. HISTOGRAM of EQUALIZED Image

Page | 43

Understanding the simulation:The COLOUR SPACE CONVERSION block with RGB to HSV parameter
converts the RGB colour space to HSV colour space. The VISUAL channel which
contains the GRAY levels of the image is then equalized by the HISTORAM
EQUALIZATION block. Then the COLOUR SPACE CONVERSION block with HSV to
RGB parameter then converts the HSV colour space back into RGB colour space.

Page | 44

-- Chapter: 9--

CONCLUSION
We can now conclude that Simulink is indeed an innovative and
exceptional tool to understand, design, analyse, and simulate a hardware or
application before actually physically creating it. Having a virtual laboratory that
can be used as if it has physical existence is not only cost effective but also time
saving. With the option of testing via running the simulation as if it were an
actual application or hardware, it provides us with valuable information
regarding the model at hand allowing us to freely change any parameter or add
or remove any block necessary for the error free functionality of the model.

Page | 45

REFERENCES
1. MATLAB and its application in Engineering
Raj Kumar Bansal
Ashok Kumar Goel
Manoj Kumar Sharma
2. MATLAB Demystified

K K Sharma

3. SIMULINK Getting Started Guide

MATHWORKS

4. Digital Image Processing

Rafael C Gonzalez
Richard E Woods

5. Introduction to Simulink

Telemark University College


Department of
Electrical Engineering,
Information Technology
and Cybernetics

6. Image Histograms

Scientic Volume
Imaging B.V

7. http://www.colourtherapyhealing.com
8. http://www.designersinsights.com
9. http://hidefcolour.com
10. http://wikipedia.prg/Histogram
11. http://homepages.inf.ed.ac.uk
12. http://infohost.nmt.edu
13. http://rapidtables.com

Page | 46

Você também pode gostar