Practical Image and Video Processing Using...

21
Chapter 6 – Arithmetic and logic operations Practical Image and Video Processing Using MATLAB® By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Transcript of Practical Image and Video Processing Using...

Page 1: Practical Image and Video Processing Using …instructor.sdu.edu.kz/.../cv2015/week04/Slides_Chapter06.pdfTitle Practical Image and Video Processing Using MATLAB® Author Oge Marques

Chapter 6 – Arithmetic and logic operations

Practical Image and Video Processing Using MATLAB®

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 2: Practical Image and Video Processing Using …instructor.sdu.edu.kz/.../cv2015/week04/Slides_Chapter06.pdfTitle Practical Image and Video Processing Using MATLAB® Author Oge Marques

What will we learn?

Which arithmetic and logic operations can I apply to digital images?

How are they performed in MATLAB?

What are they used for?

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 3: Practical Image and Video Processing Using …instructor.sdu.edu.kz/.../cv2015/week04/Slides_Chapter06.pdfTitle Practical Image and Video Processing Using MATLAB® Author Oge Marques

Arithmetic and logic operations

Combine two images, pixel-by-pixel, using an arithmetic or logical operator, resulting in a third image, Z:

X opn Y = Z

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 4: Practical Image and Video Processing Using …instructor.sdu.edu.kz/.../cv2015/week04/Slides_Chapter06.pdfTitle Practical Image and Video Processing Using MATLAB® Author Oge Marques

Addition

Used to blend the pixel contents from two images or to add a constant value to an image's pixel values.

Example 1 (blending two images):

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 5: Practical Image and Video Processing Using …instructor.sdu.edu.kz/.../cv2015/week04/Slides_Chapter06.pdfTitle Practical Image and Video Processing Using MATLAB® Author Oge Marques

Addition

Example 2 (additive image offset):

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 6: Practical Image and Video Processing Using …instructor.sdu.edu.kz/.../cv2015/week04/Slides_Chapter06.pdfTitle Practical Image and Video Processing Using MATLAB® Author Oge Marques

Addition

Example 3 (additive noise):

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 7: Practical Image and Video Processing Using …instructor.sdu.edu.kz/.../cv2015/week04/Slides_Chapter06.pdfTitle Practical Image and Video Processing Using MATLAB® Author Oge Marques

Addition in MATLAB

imadd function (see Tutorial 6.1)

Handling overflow:

Truncation

Normalization

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 8: Practical Image and Video Processing Using …instructor.sdu.edu.kz/.../cv2015/week04/Slides_Chapter06.pdfTitle Practical Image and Video Processing Using MATLAB® Author Oge Marques

Addition in MATLAB

Handling overflow (Example 6.1):

X = uint8([200 100 100; 0 10 50; 50 250 120])

Y = uint8([100 220 230; 45 95 120; 205 100 0])

W = uint16(X) + uint16(Y)

fmax = max(W(:))

fmin = min(W(:))

Za = uint8(255.0*double((W-fmin))/double((fmax-fmin)))

Zb = imadd(X,Y)

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 9: Practical Image and Video Processing Using …instructor.sdu.edu.kz/.../cv2015/week04/Slides_Chapter06.pdfTitle Practical Image and Video Processing Using MATLAB® Author Oge Marques

Subtraction

Used to used to detect differences between two images, decrease its overall brightness, or obtain its negative.

Example 1 (subtractive image offset):

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 10: Practical Image and Video Processing Using …instructor.sdu.edu.kz/.../cv2015/week04/Slides_Chapter06.pdfTitle Practical Image and Video Processing Using MATLAB® Author Oge Marques

Subtraction

Example 2 (negative of an image):

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 11: Practical Image and Video Processing Using …instructor.sdu.edu.kz/.../cv2015/week04/Slides_Chapter06.pdfTitle Practical Image and Video Processing Using MATLAB® Author Oge Marques

Subtraction in MATLAB

Three functions: imsubtract

imabsdiff

imcomplement

Example 6.2:

X = uint8([200 100 100; 0 10 50; 50 250 120])

Y = uint8([100 220 230; 45 95 120; 205 100 0])

Za = imsubtract(X,Y)

Zb = imsubtract(Y,X)

Zc = imabsdiff(Y,X)

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 12: Practical Image and Video Processing Using …instructor.sdu.edu.kz/.../cv2015/week04/Slides_Chapter06.pdfTitle Practical Image and Video Processing Using MATLAB® Author Oge Marques

Multiplication and division in MATLAB

Functions: immultiply

imdivide

Example (Fig. 6.6):

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 13: Practical Image and Video Processing Using …instructor.sdu.edu.kz/.../cv2015/week04/Slides_Chapter06.pdfTitle Practical Image and Video Processing Using MATLAB® Author Oge Marques

Combining arithmetic operations

imlincomb function

Example 6.3:

X = uint8([200 100 100; 0 10 50; 50 250 120])

Y = uint8([100 220 230; 45 95 120; 205 100 0])

Z = uint8([200 160 130; 145 195 120; 105 240 150])

Sa = imdivide(imadd(X,imadd(Y,Z)),3)

a = uint16(X) + uint16(Y)

b = a + uint16(Z)

Sb = uint8(b/3)

Sc = imlincomb(1/3,X,1/3,Y,1/3,Z,'uint8')

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 14: Practical Image and Video Processing Using …instructor.sdu.edu.kz/.../cv2015/week04/Slides_Chapter06.pdfTitle Practical Image and Video Processing Using MATLAB® Author Oge Marques

Logic operations

Performed in a bit-wise fashion on the binary contents of each pixel value.

AND, XOR and OR require two or more arguments.

NOT operator only requires only one argument.

Book examples use the convention: 1 (true) for white pixels; 0 (false) for black pixels.

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 15: Practical Image and Video Processing Using …instructor.sdu.edu.kz/.../cv2015/week04/Slides_Chapter06.pdfTitle Practical Image and Video Processing Using MATLAB® Author Oge Marques

Logic operations

Examples using binary test images

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 16: Practical Image and Video Processing Using …instructor.sdu.edu.kz/.../cv2015/week04/Slides_Chapter06.pdfTitle Practical Image and Video Processing Using MATLAB® Author Oge Marques

Logic operations on monochrome images

Example 1 (AND)

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 17: Practical Image and Video Processing Using …instructor.sdu.edu.kz/.../cv2015/week04/Slides_Chapter06.pdfTitle Practical Image and Video Processing Using MATLAB® Author Oge Marques

Example 2 (OR)

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Logic operations on monochrome images

Page 18: Practical Image and Video Processing Using …instructor.sdu.edu.kz/.../cv2015/week04/Slides_Chapter06.pdfTitle Practical Image and Video Processing Using MATLAB® Author Oge Marques

Example 3 (XOR)

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Logic operations on monochrome images

Page 19: Practical Image and Video Processing Using …instructor.sdu.edu.kz/.../cv2015/week04/Slides_Chapter06.pdfTitle Practical Image and Video Processing Using MATLAB® Author Oge Marques

Example 4 (NOT)

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Logic operations on monochrome images

Page 20: Practical Image and Video Processing Using …instructor.sdu.edu.kz/.../cv2015/week04/Slides_Chapter06.pdfTitle Practical Image and Video Processing Using MATLAB® Author Oge Marques

Logic operations in MATLAB

Functions (see Tutorial 6.2):

bitand

bitor

bitxor

bitcmp

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.

Page 21: Practical Image and Video Processing Using …instructor.sdu.edu.kz/.../cv2015/week04/Slides_Chapter06.pdfTitle Practical Image and Video Processing Using MATLAB® Author Oge Marques

Hands-on

Tutorial 6.1: Arithmetic operations (page 113)

Tutorial 6.2: Logic operations and region of interest (ROI) processing (page 118)

By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.