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

Post on 11-Mar-2018

218 Views

Category:

Documents

1 Downloads

Preview:

Click to see full reader

Transcript

SIMULINK andImage and Video Processing

Blockset

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

University of Liège

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

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

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

5of29

Model example

system

sourcesink

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

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, …

8of29

Source and Sink Blocks

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

loader, …

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

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

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

11of29

Build a model step by step

system

sourcesink

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

13of29

Build a model step by step(2)

Find all the necessary blocks

14of29

Build a model step by step(3)

Connect blocks

15of29

Build a model step by step(4)

Adjust the layout

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

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

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.

19of29

Subsystems

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

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

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?

22of29

Simulink Implementation(1)

Select elements from a vector.

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

–Selector Block

23of29

Simulink Implementation(2)

Sum and Divide

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

– Sum and Gain/Divide Block

24of29

Simulink Implementation(2)

Combine elements into vector.

– mid = [cx,cy]

– Concatenation Block

25of29

Does it work?

Test: add source and sink.– Constant– Display

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– …

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!

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

29of29

That’s all!

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

blockset.

top related