Sie sind auf Seite 1von 70

UDYAM16

Presents
ENDEAVOUR
(Workshop Series)

It all begi
ns here!!!
:)

Workshop
on

Image Processing
using MATLAB

Motivation
Machine Learning
Real Time Image Processing

(PIXELATE, Traffic Control)


Face Recognition
Handwriting Recognition
Image Enhancement
Mosaic

MATrix

MATLA
B
LABorator
y

So, Lets have some FUN with


Matrices!!

MATLAB
A Fourth Generation Programming
Language
OOP

Machine
Learning
Algos and
Numerical
Computing

Signal
Processin
g

Simulatio
n

Computer
Vision
DSP

Mathematical
Models
3D Animation

Know your MATLAB window


Address of the current
directory

Workspace

Command
Window
Current
Directory

Command
History

Basics of MATLAB

Variable
s

Creatin
g
Arrays

Indexin
g
Of
Arrays

Operatio
ns
On
Arrays

Function
s

Control
Flow

Variable
s

Creatin
g
Arrays

Indexin
g
Of
Arrays

Operatio
ns
On
Arrays

Function
s

Control
Flow

Variables

Observe that MATLAB is casesensitive too!


ans is a default MATLAB variable

Variable
s

Creatin
g
Arrays

Indexin
g
Of
Arrays

Operatio
ns
On
Arrays

Function
s

Control
Flow

Creating Arrays
Commas or spaces! Both
will do!
Semi colon is used to suppress
output

What about multi dimensional arrays??

Variable
s

Creatin
g
Arrays

Indexin
g
Of
Arrays

Operatio
ns
On
Arrays

Function
s

Control
Flow

Indexing of Arrays
Observe that the first
element is (1,1) and not
(0,0)

The colon operator used for


traversal

Indexing of Arrays (Contd.)

How to check size of an array?


What if we use different brackets for indexing ???

How to access the last element?

Variable
s

Creatin
g
Arrays

Indexin
g
Of
Arrays

Operatio
ns
On
Arrays

Function
s

Control
Flow

Operations on Arrays

Array + Array

Array - Array

Array * Array
Element wise multiplication??

Operations on Arrays (Contd.)


Array + Scalar

Array - Scalar

Array * Scalar
Element-wise
multiplication..??
Array / Scalar

Variable
s

Creatin
g
Arrays

Indexin
g
Of
Arrays

Operatio
ns
On
Arrays

Function
s

Control
Flow

Functions
To open the editor
File -> New -> Script
Ctrl + N
New Blank File Icon
Function header syntax:
function [output variables] = function_name
(input_variables)
eg.
function[sum, product] = operations(A, B)

Remember that the function name and the m-file

name MUST be the same.

Functions (Contd.)

Variable
s

Creatin
g
Arrays

Indexin
g
Of
Arrays

Operatio
ns
On
Arrays

Function
s

Control
Flow

Control Flow Statements

Variable
s

Creatin
g
Arrays

Indexin
g
Of
Arrays

Operatio
ns
On
Arrays

Function
s

Control
Flow

A Few Commands

The command clc clears the screen of the command window


The command help helps. A LOT.

A Few Functions
Trigonometric: sin(), sind(), cos(), cosd(), etc
Inverse trigonometric: asin(), asind(), acos(),

acosd(), etc
min(), max()
size()
sort()
zeros()
ones()
eye()

Try these..!!

!
s
c
i
s
a
B
D
f
:
o
!
!
h
s
g
e
u
g
o
a
n
m
E
I
,
e
y
l
l
m
a
o
s
Fin
e
v
a
h
s

t
e
L

Images

Black
and
White
(Binary
)

Gray
scale

Colour

Images in MATLAB
Each image is seen as a

matrix of size equal to


the number of pixel
rows x number of pixel
columns
Each pixel has a value
of intensity
Each element of the
matrix contains the
value of this intensity at
the corresponding to the
pixel it represents

Images in MATLAB
(Contd.)
Binary

All the elements of the matrix are either


zero or one
Zero represents black and 1 represents
white

Gray
scale

All the elements of the matrix lie between


0 and 255
Zero represents Black, 255 represents
White and the intermediate values
represent shades of Gray.

RGB

Each color has a specific RGB value!


RGB Images are seen as 3D matrices with
the 1st plane corresponding to R, 2nd to G
and 3rd to B

Working with Images


Basic
s

imread()
imshow()
imtool()

imcrop()
PreProcessi imresize()
ng

Analysi

Basic Analysis using Data Cursor


Conversion to Binary i.e. im2bw()
L-Matrix i.e bwlabel()
B-Matrix i,e, bwboundaries()
regionprops()

Processi

ng

Morphological Operations
Contrast Enhancement
Histogram Equalization
Image Smoothing
Blurring

Working with Images


Basic
s

imread()
imshow()
imtool()

imcrop()
PreProcessi imresize()
ng

Analysi

Basic Analysis using Data Cursor


Conversion to Binary i.e. im2bw()
L-Matrix i.e bwlabel()
B-Matrix i,e, bwboundaries()
regionprops()

Processi

ng

Noise Removal / Noise Reduction


Contrast Enhancement
Histogram Equalization
Image Smoothing
Blurring

Basics
imread(): Reads

the image as a
matrix
imshow(): Shows

the image as an
image
imtool(): Same as

imshow but with


different tools
The input argument: File name along
with extension

The input argument: A Matrix

Working with Images


Basic
s

imread()
imshow()
imtool()

imcrop()
PreProcessi imresize()
ng

Analysi

Basic Analysis using Data Cursor


Conversion to Binary i.e. im2bw()
L-Matrix i.e bwlabel()
B-Matrix i,e, bwboundaries()
regionprops()

Processi

ng

Morphological Operations
Contrast Enhancement
Histogram Equalization
Image Smoothing
Blurring

Pre-Processing
imcrop():
imcrop(im) : Interactive crop tool
imcrop(im, [x1,y1,x2,y2])

imresize():
imresize(im, 0.5)
imresize(im, [200, 200])
imresize(im, [200, NaN] )or imresize(im, [NaN,

200] )
imresize(im, 0.5, nearest) or imresize(im, 0.5,
bilinear) or imresize(im, 05, bicubic)

Working with Images


Basic
s

imread()
imshow()
imtool()

imcrop()
PreProcessi imresize()
ng

Analysi

Basic Analysis using Data Cursor


Conversion to Binary i.e. im2bw()
L-Matrix i.e bwlabel()
B-Matrix i,e, bwboundaries()
regionprops()

Processi

ng

Noise Removal/ Noise Reduction


Contrast Enhancement
Histogram Equalization
Image Smoothing
Blurring

Conversion to Binary

(stay

tuned for more)

Why converting?
Less information in binary => Computational
Ease
Can focus on only the area of interest
Most of the analysis can be done on Binary only
im2bw(): This

function converts a
RGB image
to a binary image

How to set the threshold


ourselves??

bwlabel() and L-matrix


bwlabel(binary_image) will return a L-matrix which basically

the Label matrix


L-Matrix is a 2 D matrix of the same size as that of the
image.
The various objects present in an image are given filled with
the pixels of the same value, the object number.
Object number is decided by traversing from left to right
and then top to bottom as tie-breaker.
Each object in the binary image is numbered 1,2,3,.... and
all the pixels of L corresponding to the objects in binary
image have value respectively 1, 2, 3,....
The background pixels are 0 by default.
L = bwlabel(bw);

imtool(bw);

L-matrix labels

bwboundaries() and Bmatrix


Traces the exterior boundaries of objects in a binary

image.
>>B=bwboundaries(bw)
Returns B, a P-by-1 cell array, where P is the

number of objects and holes.


Each cell contains Q-by-2 matrix, where Q is the

number of boundary pixels for a region.

More about
bwboundaries()
In the coordinate matrix, the first coordinate is the row number (y

- coordinate) and second coordinate is the column number (xcoordinate) of the boundary pixel. Take this always into
consideration as it can create a lot of confusion.

bwboundaries(bw) will trace the hole boundaries too. So, a better

option is to use
bwboundaries(bw,'noholes')

regionprops()
It is used to measure properties of image regions like

centroid, perimeter, area, etc.


Syntax:

STATS=regionprops(L, properties);
STATS is a structure array of length equal to the number of

labelled objects in L.

properties are a comma-separated list of various

properties to be measured.

Working with Images


Basic
s

imread()
imshow()
imtool()

imcrop()
PreProcessi imresize()
ng

Analysi

Basic Analysis using Data Cursor


Conversion to Binary i.e. im2bw()
L-Matrix i.e bwlabel()
B-Matrix i,e, bwboundaries()
regionprops()

Processi
ng

Morphological Operations
Contrast Enhancement
Image Smoothing
Image Blurring

Morphological
Operations
imerode()
imdilate()
imopen()
imclose()
imfill()
bwmorph(

)
bwperim()

For any queries contact-

Piyush- 7752957837
Arshiyan 8418950295
Sairam- 9479450482
Saloni- 7408843517

Contrast Enhancement
imhist(): Returns the histogram of a gray

scale image.

Contrast Enhancement (Contd.)


imadjust(): Saturates the 1% of data at low

and high intensities.

imadjust()

Contrast Enhancement (Contd.)


histeq(): Perform Histogram Equalisation i.e.,

Transforms the given image such that its


histogram becomes equal to uniform
distribution

histeq()

Contrast Enhancement (Contd.)


adapthisteq(): Adaptive Histogram

Equalisation i.e., Does the same thing as


histeq but operates on small data regions
(tiles) rather than the entire image.

adapthisteq()

Thresholding
Global Threshold

Thresholding (Contd.)
Adaptive

Thresholding:
This works by
thresholding on
smaller tiles of
the image.

Image Smoothing and


Blurring
Averaging Filter:

Blurs/smooths the image.


Can be used to reduce the
effect of noise.

What is applying a
Filter??
The following figure shows how
to compute the (2,4) output
pixel

Implementation in
MATLAB

A Use of Blurring:

Median Filter
Just as a note, the blurring results in loss of

edges but median filter removes the noise still


keeping the edges intact.

B = medfilt2(A, [m n])

Demo:

Unsharp Mask
oMask
corresponding to a
derivative:

[ 0 0 0;
0 -1 1;
0 0 0;]

Unsharp Mask
Mask corresponding to a derivative:

[ 0 0 0;
0 -1 1;
0 0 0;]
Mask corresponding to a
double derivative:

[ 0 0 0;
1 -2 1;
0 0 0;]

Edge Detection
BW = edge(I) takes a grayscale or a binary image I

as its input, and returns a binary image BW of the


same size as I, with 1's where the function finds
edges in I and 0's elsewhere.
Syntax:
BW = edge(I,'sobel')
BW = edge(I,'prewitt')
BW = edge(I,'roberts')
BW = edge(I,'canny')

What are these methods anyway?

DEMO
Detecting a Cell Using Image segemtation

Watershed Segmentation

HOUGH TRANSFORM

Das könnte Ihnen auch gefallen