0% found this document useful (0 votes)
34 views

Computer Graphics: Image Arithmetic

This document discusses image arithmetic, specifically pixel addition. It begins with objectives to understand addition between images and learn operations like addition, subtraction, multiplication and blending. It defines pixel addition as taking two identically sized images and producing an output where each pixel is the sum of corresponding pixels from the inputs. Examples show adding with and without scaling, and adding a constant value, demonstrating how OpenCV limits output values.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Computer Graphics: Image Arithmetic

This document discusses image arithmetic, specifically pixel addition. It begins with objectives to understand addition between images and learn operations like addition, subtraction, multiplication and blending. It defines pixel addition as taking two identically sized images and producing an output where each pixel is the sum of corresponding pixels from the inputs. Examples show adding with and without scaling, and adding a constant value, demonstrating how OpenCV limits output values.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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
[email protected]

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
[email protected]

Change detection

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


Introduction Objectives

Objectives

Understand about the arithmetic between images.


[email protected]

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.
[email protected]

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
[email protected]

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.
[email protected]

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)


[email protected]

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)


[email protected]

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)


[email protected]

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
[email protected]

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


[email protected]

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


[email protected]

to int, before the adding operation.

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


Pixel addition Examples

Pixel addition
Example with scaling
[email protected]

Figure: Example of pixel addition using Equation 2.

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


Pixel addition Examples

Pixel addition
Image plus constant
[email protected]

Figure: Adding a constant to a image.

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


Pixel addition Examples

Pixel addition
Image plus constant
[email protected]

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
[email protected]

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
[email protected]

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
[email protected]

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
[email protected]

Change detection

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


Pixel addition Colors

Pixel addition
Image addition with colors
[email protected]

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
[email protected]

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.
[email protected]

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)
[email protected]

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


Pixel Subtraction Definition

Pixel subtraction
Example
[email protected]

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
[email protected]

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:


[email protected]

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:


[email protected]

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:
[email protected]

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


[email protected]

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

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


Pixel Subtraction Characters segmentation

Pixel subtraction
Applications - Segmentation of Characters

Comparison:
[email protected]

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
[email protected]

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.


[email protected]

Figure: Frame 1. Figure: Frame 2.

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


Pixel Subtraction Change detection

Pixel subtraction
Applications - Change detection
[email protected]

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

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


Pixel Subtraction Change detection

Questions?
[email protected]

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

You might also like