digital image processing - montefiore institute
TRANSCRIPT
![Page 1: Digital Image Processing - Montefiore Institute](https://reader030.vdocuments.us/reader030/viewer/2022020703/61fb47f42e268c58cd5c4f9b/html5/thumbnails/1.jpg)
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 Institute](https://reader030.vdocuments.us/reader030/viewer/2022020703/61fb47f42e268c58cd5c4f9b/html5/thumbnails/2.jpg)
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 Institute](https://reader030.vdocuments.us/reader030/viewer/2022020703/61fb47f42e268c58cd5c4f9b/html5/thumbnails/3.jpg)
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 Institute](https://reader030.vdocuments.us/reader030/viewer/2022020703/61fb47f42e268c58cd5c4f9b/html5/thumbnails/4.jpg)
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 Institute](https://reader030.vdocuments.us/reader030/viewer/2022020703/61fb47f42e268c58cd5c4f9b/html5/thumbnails/5.jpg)
5of29
Model example
system
sourcesink
![Page 6: Digital Image Processing - Montefiore Institute](https://reader030.vdocuments.us/reader030/viewer/2022020703/61fb47f42e268c58cd5c4f9b/html5/thumbnails/6.jpg)
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 Institute](https://reader030.vdocuments.us/reader030/viewer/2022020703/61fb47f42e268c58cd5c4f9b/html5/thumbnails/7.jpg)
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 Institute](https://reader030.vdocuments.us/reader030/viewer/2022020703/61fb47f42e268c58cd5c4f9b/html5/thumbnails/8.jpg)
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 Institute](https://reader030.vdocuments.us/reader030/viewer/2022020703/61fb47f42e268c58cd5c4f9b/html5/thumbnails/9.jpg)
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 Institute](https://reader030.vdocuments.us/reader030/viewer/2022020703/61fb47f42e268c58cd5c4f9b/html5/thumbnails/10.jpg)
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 Institute](https://reader030.vdocuments.us/reader030/viewer/2022020703/61fb47f42e268c58cd5c4f9b/html5/thumbnails/11.jpg)
11of29
Build a model step by step
system
sourcesink
![Page 12: Digital Image Processing - Montefiore Institute](https://reader030.vdocuments.us/reader030/viewer/2022020703/61fb47f42e268c58cd5c4f9b/html5/thumbnails/12.jpg)
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 Institute](https://reader030.vdocuments.us/reader030/viewer/2022020703/61fb47f42e268c58cd5c4f9b/html5/thumbnails/13.jpg)
13of29
Build a model step by step(2)
Find all the necessary blocks
![Page 14: Digital Image Processing - Montefiore Institute](https://reader030.vdocuments.us/reader030/viewer/2022020703/61fb47f42e268c58cd5c4f9b/html5/thumbnails/14.jpg)
14of29
Build a model step by step(3)
Connect blocks
![Page 15: Digital Image Processing - Montefiore Institute](https://reader030.vdocuments.us/reader030/viewer/2022020703/61fb47f42e268c58cd5c4f9b/html5/thumbnails/15.jpg)
15of29
Build a model step by step(4)
Adjust the layout
![Page 16: Digital Image Processing - Montefiore Institute](https://reader030.vdocuments.us/reader030/viewer/2022020703/61fb47f42e268c58cd5c4f9b/html5/thumbnails/16.jpg)
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 Institute](https://reader030.vdocuments.us/reader030/viewer/2022020703/61fb47f42e268c58cd5c4f9b/html5/thumbnails/17.jpg)
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 Institute](https://reader030.vdocuments.us/reader030/viewer/2022020703/61fb47f42e268c58cd5c4f9b/html5/thumbnails/18.jpg)
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 Institute](https://reader030.vdocuments.us/reader030/viewer/2022020703/61fb47f42e268c58cd5c4f9b/html5/thumbnails/19.jpg)
19of29
Subsystems
Select portions of the model using the mouse and turn them into a subsystem.
![Page 20: Digital Image Processing - Montefiore Institute](https://reader030.vdocuments.us/reader030/viewer/2022020703/61fb47f42e268c58cd5c4f9b/html5/thumbnails/20.jpg)
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 Institute](https://reader030.vdocuments.us/reader030/viewer/2022020703/61fb47f42e268c58cd5c4f9b/html5/thumbnails/21.jpg)
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 Institute](https://reader030.vdocuments.us/reader030/viewer/2022020703/61fb47f42e268c58cd5c4f9b/html5/thumbnails/22.jpg)
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 Institute](https://reader030.vdocuments.us/reader030/viewer/2022020703/61fb47f42e268c58cd5c4f9b/html5/thumbnails/23.jpg)
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 Institute](https://reader030.vdocuments.us/reader030/viewer/2022020703/61fb47f42e268c58cd5c4f9b/html5/thumbnails/24.jpg)
24of29
Simulink Implementation(2)
Combine elements into vector.
– mid = [cx,cy]
– Concatenation Block
![Page 25: Digital Image Processing - Montefiore Institute](https://reader030.vdocuments.us/reader030/viewer/2022020703/61fb47f42e268c58cd5c4f9b/html5/thumbnails/25.jpg)
25of29
Does it work?
Test: add source and sink.– Constant– Display
![Page 26: Digital Image Processing - Montefiore Institute](https://reader030.vdocuments.us/reader030/viewer/2022020703/61fb47f42e268c58cd5c4f9b/html5/thumbnails/26.jpg)
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 Institute](https://reader030.vdocuments.us/reader030/viewer/2022020703/61fb47f42e268c58cd5c4f9b/html5/thumbnails/27.jpg)
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 Institute](https://reader030.vdocuments.us/reader030/viewer/2022020703/61fb47f42e268c58cd5c4f9b/html5/thumbnails/28.jpg)
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 Institute](https://reader030.vdocuments.us/reader030/viewer/2022020703/61fb47f42e268c58cd5c4f9b/html5/thumbnails/29.jpg)
29of29
That’s all!
Have fun in the lab! – Get familiar with SIMULINK and IVP
blockset.