Download as pdf or txt
Download as pdf or txt
You are on page 1of 35

Escuela Profesional de

Ciencia de la Computación

ICC Fase 1

Computer graphics
Image Arithmetic

MSc. Vicente Machaca Arceda

Universidad Nacional de San Agustín de Arequipa

May 16, 2020

MSc. Vicente Machaca Arceda (UNSA) 1704146 1 / 32


Overview

1 Introduction
Objectives

2 Pixel addition
Definition
Examples
Colors

3 Pixel Subtraction
Definition
Characters segmentation
vmachacaa@unsa.edu.pe

Change detection

MSc. Vicente Machaca Arceda (UNSA) 1704146 2 / 32


Introduction Objectives

Table of Contents

1 Introduction
Objectives

2 Pixel addition
Definition
Examples
Colors

3 Pixel Subtraction
Definition
Characters segmentation
vmachacaa@unsa.edu.pe

Change detection

MSc. Vicente Machaca Arceda (UNSA) 1704146 3 / 32


Introduction Objectives

Objectives

Understand about the arithmetic between images.


vmachacaa@unsa.edu.pe

MSc. Vicente Machaca Arceda (UNSA) 1704146 4 / 32


Introduction Objectives

Objectives

Understand about the arithmetic between images.


Learn addition, subtraction, multiplication, division and
blending between images.
vmachacaa@unsa.edu.pe

MSc. Vicente Machaca Arceda (UNSA) 1704146 4 / 32


Pixel addition Definition

Table of Contents

1 Introduction
Objectives

2 Pixel addition
Definition
Examples
Colors

3 Pixel Subtraction
Definition
Characters segmentation
vmachacaa@unsa.edu.pe

Change detection

MSc. Vicente Machaca Arceda (UNSA) 1704146 5 / 32


Pixel addition Definition

Pixel addition
Definition

This operator takes as input two identically sized images and


produces as output a third image of the same size as the first
two. Each pixel value is the sum of the values of the
corresponding pixel from each of the two input images.
vmachacaa@unsa.edu.pe

MSc. Vicente Machaca Arceda (UNSA) 1704146 6 / 32


Pixel addition Definition

Pixel addition
Definition

Normal addition :

Q(i, j) = P1 (i, j) + P2 (i, j) (1)


vmachacaa@unsa.edu.pe

MSc. Vicente Machaca Arceda (UNSA) 1704146 7 / 32


Pixel addition Definition

Pixel addition
Definition

Normal addition :

Q(i, j) = P1 (i, j) + P2 (i, j) (1)

Almost always, we need to scale the image:

Q(i, j) = P1 (i, j)/2 + P2 (i, j)/2 (2)


vmachacaa@unsa.edu.pe

MSc. Vicente Machaca Arceda (UNSA) 1704146 7 / 32


Pixel addition Definition

Pixel addition
Definition

Normal addition :

Q(i, j) = P1 (i, j) + P2 (i, j) (1)

Almost always, we need to scale the image:

Q(i, j) = P1 (i, j)/2 + P2 (i, j)/2 (2)

Also, we could add a constant value:

Q(i, j) = P1 (i, j) + C (3)


vmachacaa@unsa.edu.pe

MSc. Vicente Machaca Arceda (UNSA) 1704146 7 / 32


Pixel addition Examples

Table of Contents

1 Introduction
Objectives

2 Pixel addition
Definition
Examples
Colors

3 Pixel Subtraction
Definition
Characters segmentation
vmachacaa@unsa.edu.pe

Change detection

MSc. Vicente Machaca Arceda (UNSA) 1704146 8 / 32


Pixel addition Examples

Pixel addition
Example with scaling

Figure: Example of pixel addition using Equation 5. OpenCV limits the


vmachacaa@unsa.edu.pe

values to [0-255] (int8).

MSc. Vicente Machaca Arceda (UNSA) 1704146 9 / 32


Pixel addition Examples

Pixel addition
Example without scaling

Figure: Example of pixel addition using Equation 5. We cast the image


vmachacaa@unsa.edu.pe

to int, before the adding operation.

MSc. Vicente Machaca Arceda (UNSA) 1704146 10 / 32


Pixel addition Examples

Pixel addition
Example with scaling
vmachacaa@unsa.edu.pe

Figure: Example of pixel addition using Equation 2.

MSc. Vicente Machaca Arceda (UNSA) 1704146 11 / 32


Pixel addition Examples

Pixel addition
Image plus constant
vmachacaa@unsa.edu.pe

Figure: Adding a constant to a image.

MSc. Vicente Machaca Arceda (UNSA) 1704146 12 / 32


Pixel addition Examples

Pixel addition
Image plus constant
vmachacaa@unsa.edu.pe

Figure: If you use OpenCV, this problem could occurs. It is because


OpenCV limits the pixel values to [0-255].

MSc. Vicente Machaca Arceda (UNSA) 1704146 13 / 32


Pixel addition Examples

Pixel addition
Image plus constant
vmachacaa@unsa.edu.pe

Figure: Before add a constant, cast the image type to int (img =
img.astype(int)).

MSc. Vicente Machaca Arceda (UNSA) 1704146 14 / 32


Pixel addition Examples

Pixel addition
Image plus constant
vmachacaa@unsa.edu.pe

Figure: We scale the image before adding a constant.

MSc. Vicente Machaca Arceda (UNSA) 1704146 15 / 32


Pixel addition Examples

Pixel addition
Image addition with colors
vmachacaa@unsa.edu.pe

Figure: Two images for addition.

MSc. Vicente Machaca Arceda (UNSA) 1704146 16 / 32


Pixel addition Colors

Table of Contents

1 Introduction
Objectives

2 Pixel addition
Definition
Examples
Colors

3 Pixel Subtraction
Definition
Characters segmentation
vmachacaa@unsa.edu.pe

Change detection

MSc. Vicente Machaca Arceda (UNSA) 1704146 17 / 32


Pixel addition Colors

Pixel addition
Image addition with colors
vmachacaa@unsa.edu.pe

Figure: Addition of two images with colors.

MSc. Vicente Machaca Arceda (UNSA) 1704146 18 / 32


Pixel Subtraction Definition

Table of Contents

1 Introduction
Objectives

2 Pixel addition
Definition
Examples
Colors

3 Pixel Subtraction
Definition
Characters segmentation
vmachacaa@unsa.edu.pe

Change detection

MSc. Vicente Machaca Arceda (UNSA) 1704146 19 / 32


Pixel Subtraction Definition

Pixel subtraction
Definition

The pixel subtraction operator takes two images as input and


produces as output a third image whose pixel values are simply
those of the first image minus the corresponding pixel values
from the second image.
vmachacaa@unsa.edu.pe

MSc. Vicente Machaca Arceda (UNSA) 1704146 20 / 32


Pixel Subtraction Definition

Pixel subtraction
Definition

Q(i, j) = |P1 (i, j) − P2 (i, j)| (4)


Q(i, j) = |P1 (i, j) − C| (5)
vmachacaa@unsa.edu.pe

MSc. Vicente Machaca Arceda (UNSA) 1704146 21 / 32


Pixel Subtraction Definition

Pixel subtraction
Example
vmachacaa@unsa.edu.pe

Figure: Example of subtraction operator.

MSc. Vicente Machaca Arceda (UNSA) 1704146 22 / 32


Pixel Subtraction Characters segmentation

Table of Contents

1 Introduction
Objectives

2 Pixel addition
Definition
Examples
Colors

3 Pixel Subtraction
Definition
Characters segmentation
vmachacaa@unsa.edu.pe

Change detection

MSc. Vicente Machaca Arceda (UNSA) 1704146 23 / 32


Pixel Subtraction Characters segmentation

Pixel subtraction
Applications - Segmentation of Characters

Suppose we want to segment the characters, the result will be:


vmachacaa@unsa.edu.pe

Figure: Photo. Figure: Thresholding (θ = 127).

MSc. Vicente Machaca Arceda (UNSA) 1704146 24 / 32


Pixel Subtraction Characters segmentation

Pixel subtraction
Applications - Segmentation of Characters

We could take a photo of a white paper to apply subtraction:


vmachacaa@unsa.edu.pe

Figure: Photo. Figure: Photo of white paper.

MSc. Vicente Machaca Arceda (UNSA) 1704146 25 / 32


Pixel Subtraction Characters segmentation

Pixel subtraction
Applications - Segmentation of Characters

We take the normal photo and subtracts the white paper photo
to get a new image:
vmachacaa@unsa.edu.pe

Figure: Result after applying subtraction and an addition of 100 to avoid


negative values.

MSc. Vicente Machaca Arceda (UNSA) 1704146 26 / 32


Pixel Subtraction Characters segmentation

Pixel subtraction
Applications - Segmentation of Characters

Then we apply thresholding with θ = 80


vmachacaa@unsa.edu.pe

Figure: Difference Figure: Thresholding (θ = 80).

MSc. Vicente Machaca Arceda (UNSA) 1704146 27 / 32


Pixel Subtraction Characters segmentation

Pixel subtraction
Applications - Segmentation of Characters

Comparison:
vmachacaa@unsa.edu.pe

Figure: Without subtraction. Figure: With subtraction.

MSc. Vicente Machaca Arceda (UNSA) 1704146 28 / 32


Pixel Subtraction Change detection

Table of Contents

1 Introduction
Objectives

2 Pixel addition
Definition
Examples
Colors

3 Pixel Subtraction
Definition
Characters segmentation
vmachacaa@unsa.edu.pe

Change detection

MSc. Vicente Machaca Arceda (UNSA) 1704146 29 / 32


Pixel Subtraction Change detection

Pixel subtraction
Applications - Change detection

We could use subtraction to detect changes between frames.


vmachacaa@unsa.edu.pe

Figure: Frame 1. Figure: Frame 2.

MSc. Vicente Machaca Arceda (UNSA) 1704146 30 / 32


Pixel Subtraction Change detection

Pixel subtraction
Applications - Change detection
vmachacaa@unsa.edu.pe

Figure: |Frame 1 - Frame 2| and contrast stretching.

MSc. Vicente Machaca Arceda (UNSA) 1704146 31 / 32


Pixel Subtraction Change detection

Questions?
vmachacaa@unsa.edu.pe

MSc. Vicente Machaca Arceda (UNSA) 1704146 32 / 32

You might also like