Top Banner
SIMULINK and Image and Video Processing Blockset prepared by Wei Du 07/2007 Rev. 1.1 by Justus Piater 11/2007 University of Liège
29

Digital Image Processing - montefiore.ulg.ac.bepiater/Cours/INFO0903/tutorial-Simulink.pdf · SIMULINK and Image and Video Processing ... To Matlab workspace systems ... –Filtering

Mar 11, 2018

Download

Documents

duongmien
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Digital Image Processing - montefiore.ulg.ac.bepiater/Cours/INFO0903/tutorial-Simulink.pdf · SIMULINK and Image and Video Processing ... To Matlab workspace systems ... –Filtering

SIMULINK andImage and Video Processing

Blockset

prepared by Wei Du 07/2007Rev. 1.1 by Justus Piater 11/2007

University of Liège

Page 2: Digital Image Processing - montefiore.ulg.ac.bepiater/Cours/INFO0903/tutorial-Simulink.pdf · SIMULINK and Image and Video Processing ... To Matlab workspace systems ... –Filtering

2of29

Contents

Tired of writing MATLAB code? Let’s try something different: build a system by assembling blocks!

– SIMULINK

– Image and Video Processing (IVP) Blockset

Page 3: Digital Image Processing - montefiore.ulg.ac.bepiater/Cours/INFO0903/tutorial-Simulink.pdf · SIMULINK and Image and Video Processing ... To Matlab workspace systems ... –Filtering

3of29

What is SIMULINK?

A platform for building and simulating models

Integrated with MATLAB and toolboxes

Graphical editing: block diagram– Can drag and drop blocks

Extensive libraries of blocks available

Page 4: Digital Image Processing - montefiore.ulg.ac.bepiater/Cours/INFO0903/tutorial-Simulink.pdf · SIMULINK and Image and Video Processing ... To Matlab workspace systems ... –Filtering

4of29

Structure of SIMULINK Model

A typical SIMULINK model includes sources, systems and sinks.

sources sinks

To disk filesTo display

To Matlab workspace

systems

From disk filesFrom Matlab workspace

Interconnections of blocks

Page 5: Digital Image Processing - montefiore.ulg.ac.bepiater/Cours/INFO0903/tutorial-Simulink.pdf · SIMULINK and Image and Video Processing ... To Matlab workspace systems ... –Filtering

5of29

Model example

system

sourcesink

Page 6: Digital Image Processing - montefiore.ulg.ac.bepiater/Cours/INFO0903/tutorial-Simulink.pdf · SIMULINK and Image and Video Processing ... To Matlab workspace systems ... –Filtering

6of29

Basic element -- Block

A block is an operator in a black box!

Blocks are connected by directed lines, passing along the signals.

block

input signals output signals

>

Input ports

>

Output ports

>>

>

outp

ut o

f oth

er b

locks

input o

f oth

er b

locks

Page 7: Digital Image Processing - montefiore.ulg.ac.bepiater/Cours/INFO0903/tutorial-Simulink.pdf · SIMULINK and Image and Video Processing ... To Matlab workspace systems ... –Filtering

7of29

Basic Blocks

Math operation: sum, product, gain, …

Logic and Bit operations: and, or, …

Signal Routing: Selector, …

Commonly Used Blocks: integrator, delay, data type conversion, …

Page 8: Digital Image Processing - montefiore.ulg.ac.bepiater/Cours/INFO0903/tutorial-Simulink.pdf · SIMULINK and Image and Video Processing ... To Matlab workspace systems ... –Filtering

8of29

Source and Sink Blocks

Source: blocks without input ports– constant, sine function, random, file

loader, …

Sink: blocks without output ports– display, file saver, …

Page 9: Digital Image Processing - montefiore.ulg.ac.bepiater/Cours/INFO0903/tutorial-Simulink.pdf · SIMULINK and Image and Video Processing ... To Matlab workspace systems ... –Filtering

9of29

Signals

Data type - single, double, signed or unsigned 8-, 16-, or 32-bit integers; fixed-point; and Boolean

Dimensions - scalar, vector, or matrix

Watch out: make sure the signal attributes match!

block1> >

>

>

block2>>

>

signals

signalssignals

Page 10: Digital Image Processing - montefiore.ulg.ac.bepiater/Cours/INFO0903/tutorial-Simulink.pdf · SIMULINK and Image and Video Processing ... To Matlab workspace systems ... –Filtering

10of29

How many blocks do we have?

Standard SIMULINK libraries– More than 200 built-in blocks

Blocksets: more than 10– Image and Video Processing– Signal Processing– …

User defined libraries– M-function, S-function

Blockset

Libraries

Blocks

Page 11: Digital Image Processing - montefiore.ulg.ac.bepiater/Cours/INFO0903/tutorial-Simulink.pdf · SIMULINK and Image and Video Processing ... To Matlab workspace systems ... –Filtering

11of29

Build a model step by step

system

sourcesink

Page 12: Digital Image Processing - montefiore.ulg.ac.bepiater/Cours/INFO0903/tutorial-Simulink.pdf · SIMULINK and Image and Video Processing ... To Matlab workspace systems ... –Filtering

12of29

Build a model step by step(1)

Launch SIMULINK and create a new model

– Click SIMULINK button– Type in “simulink” in matlab command

window

Page 13: Digital Image Processing - montefiore.ulg.ac.bepiater/Cours/INFO0903/tutorial-Simulink.pdf · SIMULINK and Image and Video Processing ... To Matlab workspace systems ... –Filtering

13of29

Build a model step by step(2)

Find all the necessary blocks

Page 14: Digital Image Processing - montefiore.ulg.ac.bepiater/Cours/INFO0903/tutorial-Simulink.pdf · SIMULINK and Image and Video Processing ... To Matlab workspace systems ... –Filtering

14of29

Build a model step by step(3)

Connect blocks

Page 15: Digital Image Processing - montefiore.ulg.ac.bepiater/Cours/INFO0903/tutorial-Simulink.pdf · SIMULINK and Image and Video Processing ... To Matlab workspace systems ... –Filtering

15of29

Build a model step by step(4)

Adjust the layout

Page 16: Digital Image Processing - montefiore.ulg.ac.bepiater/Cours/INFO0903/tutorial-Simulink.pdf · SIMULINK and Image and Video Processing ... To Matlab workspace systems ... –Filtering

16of29

Build a model step by step(5)

Change the labels and add annotations

Input Signal

Original Signal

Filtered SignalAmplify

Gain You can add text annotations anywhere you want

Page 17: Digital Image Processing - montefiore.ulg.ac.bepiater/Cours/INFO0903/tutorial-Simulink.pdf · SIMULINK and Image and Video Processing ... To Matlab workspace systems ... –Filtering

17of29

Build a model step by step(5)

Ctrl-T, Run!

Input Signal

Original Signal

Filtered SignalAmplify

Gain You can add text annotations anywhere you want

Page 18: Digital Image Processing - montefiore.ulg.ac.bepiater/Cours/INFO0903/tutorial-Simulink.pdf · SIMULINK and Image and Video Processing ... To Matlab workspace systems ... –Filtering

18of29

More SIMULINK basics

Double-click on a block to open its Dialog Box. Parameters for the block can be set in this box.

Click on the HELP button on the Dialog Box of a block to launch the HELP file for the block.

You can rotate, flip or resize a block. Useful to create a more readable block diagram.

Page 19: Digital Image Processing - montefiore.ulg.ac.bepiater/Cours/INFO0903/tutorial-Simulink.pdf · SIMULINK and Image and Video Processing ... To Matlab workspace systems ... –Filtering

19of29

Subsystems

Select portions of the model using the mouse and turn them into a subsystem.

Page 20: Digital Image Processing - montefiore.ulg.ac.bepiater/Cours/INFO0903/tutorial-Simulink.pdf · SIMULINK and Image and Video Processing ... To Matlab workspace systems ... –Filtering

20of29

A real problem

Given a rectangle box = [r,c,h,w], compute the center mid = [cx,cy] of the rectangle.

c

r

h

w

*

O

[ r, c, h, w ]

*

O

Row

Column X

Ymatrix coordinate image coordinate

cy

cx

Page 21: Digital Image Processing - montefiore.ulg.ac.bepiater/Cours/INFO0903/tutorial-Simulink.pdf · SIMULINK and Image and Video Processing ... To Matlab workspace systems ... –Filtering

21of29

Matlab Implementation

function mid = Box2Center(box)

r = box(1); c = box(2); h = box(3); w = box(4);cy = r+h/2;cx = c+w/2;mid = [cx,cy];return

How to do it with SIMULINK?

Page 22: Digital Image Processing - montefiore.ulg.ac.bepiater/Cours/INFO0903/tutorial-Simulink.pdf · SIMULINK and Image and Video Processing ... To Matlab workspace systems ... –Filtering

22of29

Simulink Implementation(1)

Select elements from a vector.

–r = box(1); c = box(2); h = box(3); w = box(4);

–Selector Block

Page 23: Digital Image Processing - montefiore.ulg.ac.bepiater/Cours/INFO0903/tutorial-Simulink.pdf · SIMULINK and Image and Video Processing ... To Matlab workspace systems ... –Filtering

23of29

Simulink Implementation(2)

Sum and Divide

– cy = r+h/2; cx = c+w/2;

– Sum and Gain/Divide Block

Page 24: Digital Image Processing - montefiore.ulg.ac.bepiater/Cours/INFO0903/tutorial-Simulink.pdf · SIMULINK and Image and Video Processing ... To Matlab workspace systems ... –Filtering

24of29

Simulink Implementation(2)

Combine elements into vector.

– mid = [cx,cy]

– Concatenation Block

Page 25: Digital Image Processing - montefiore.ulg.ac.bepiater/Cours/INFO0903/tutorial-Simulink.pdf · SIMULINK and Image and Video Processing ... To Matlab workspace systems ... –Filtering

25of29

Does it work?

Test: add source and sink.– Constant– Display

Page 26: Digital Image Processing - montefiore.ulg.ac.bepiater/Cours/INFO0903/tutorial-Simulink.pdf · SIMULINK and Image and Video Processing ... To Matlab workspace systems ... –Filtering

26of29

Image and Video Processing(IVP) Blockset

A set of blocks that do image and video processing.

– Access image and video files– Filtering– Morphology– Edge detection– Geometric transform– Text and graphics– …

Page 27: Digital Image Processing - montefiore.ulg.ac.bepiater/Cours/INFO0903/tutorial-Simulink.pdf · SIMULINK and Image and Video Processing ... To Matlab workspace systems ... –Filtering

27of29

A real problem

Convert RGB images to gray-scale.– Source: Image or Video Loader– Sink: Image or Video Viewer– System: Add and Gain blocks

Watch out: data types of signals must match!

Page 28: Digital Image Processing - montefiore.ulg.ac.bepiater/Cours/INFO0903/tutorial-Simulink.pdf · SIMULINK and Image and Video Processing ... To Matlab workspace systems ... –Filtering

28of29

A real problem

Draw rectangles in an image, and plot a marker at the center of each rectangle.

– Source: Image or Video Loader and Constant

– Sink: Image or Video viewer– Box2Center– Text and graphics blocks

Page 29: Digital Image Processing - montefiore.ulg.ac.bepiater/Cours/INFO0903/tutorial-Simulink.pdf · SIMULINK and Image and Video Processing ... To Matlab workspace systems ... –Filtering

29of29

That’s all!

Have fun in the lab! – Get familiar with SIMULINK and IVP

blockset.