Teaching Notes on Image Processing Dr. Mohammed

11 downloads 0 Views 3MB Size Report
Image Processing: History, Objectives and Applications. 2 Elementary Image Information and Operations. 3 Fundamentals of Signal and Image Processing.
Teaching Notes on Image Processing For senior students

Lectures 2: Elementary Image Operations Dr. Mohammed Abdel-Megeed Salem Scientific Computing Department, Faculty of Computer and Information Sciences, Ain Shams University in Cairo

Outline • Course Information & Objectives • Introduction – Definitions • Images, Image Processing, Image Analysis, Computer Vision, Computer Graphics

– Image Processing: History, Objectives and Applications

Salem, Teaching Notes on Image Processing, 2015

Lecture 2

2

Course Info - Contents 1

Introduction – Definitions • Images, Image Processing, Image Analysis, Computer Vision, Computer Graphics

– Image Processing: History, Objectives and Applications

2

Elementary Image Information and Operations

3

Fundamentals of Signal and Image Processing

4

Acquisition and Digitizing Images

5

Image Processing Operations

6

Applications

Salem, Teaching Notes on Image Processing, 2015

Lecture 2

3

Quick Check [Lecture 2] • Draw a new Venn diagram for the term “Image” similar to the diagram of Castleman but based on your own understanding. • Repeat the last image denoising example on one of your own images. Write down your observations/ comments.

Salem, Teaching Notes on Image Processing, 2015

Lecture 2

4

Definitions – Images [Lecture 2]

Salem, Teaching Notes on Image Processing, 2015

Lecture 2

5

Simple Example [Lecture 2] • The following code should run on Matlab: RGB = imread('saturn.png'); I = rgb2gray(RGB); J =imnoise(I,'gaussian',0,0.025); imshow(J) K = wiener2(J,[5 5]); figure, imshow(K)

Salem, Teaching Notes on Image Processing, 2015

Lecture 2

6

Definitions – Images [Lecture 2] • The image is treated as a grid of discrete elements, ordered from top to bottom and left to right. • The first component r (the row) increases downward, while the second component c (the col.) increases to the right. • Pixel coordinates are integer values and range between 1 and the length of the row or column.

The Pixel Coordinate System

Salem, Teaching Notes on Image Processing, 2015

Lecture 2

7

Definitions – Images [Lecture 2] • A grey level image:

Salem, Teaching Notes on Image Processing, 2015

Lecture 2

8

Definitions – Images [Lecture 2] • RGB-coloured image:

Salem, Teaching Notes on Image Processing, 2015

Lecture 2

9

Course Info - Contents 1

Introduction

2

Elementary Image Information and Operations – Image Statistics – Histogram

– Point Operations

3

Fundamentals of Signal and Image Processing

4

Acquisition and Digitizing Images

5

Image Processing Operations

6

Applications

Salem, Teaching Notes on Image Processing, 2015

Lecture 2

10

Objective • The objective of this lecture is to gain a touchable feeling about the basic information of images and basic operation may be operated on images. This understanding will help us in the coming lecture to study the fundamentals of Signal and Image Processing. • For you to achieve this objective you should try to implement these operations on images created by your own or, when this is not available, on standard set of images. Ex: http://imagedatabase.cs.washington.edu/groundtruth/ Salem, Teaching Notes on Image Processing, 2015

Lecture 2

11

Image Statistics • • • •

Image Size: total number of pixels. Minimum gray level, Maximum gray level, Range, the difference between the maximum and the minimum. • Entropy: a measure of randomness – used to characterize the texture of the image.

Salem, Teaching Notes on Image Processing, 2015

Lecture 2

12

Image Statistics Image Size: 768x1024 = 786432 Minimum gray level: 0 Maxmum gray level: 255 Range: 255 Mean gray level: 142,9 Mode gray level: 160 Median gray level: 151 Entropy: 7.7554

Salem, Teaching Notes on Image Processing, 2015

Lecture 2

13

Image Histogram • Provides information on grey scale distribution • Represents the Discrete Probability Function for the colour distribution

Salem, Teaching Notes on Image Processing, 2015

Lecture 2

14

Image Histogram • Most used: normalized histogram with relative frequencies hg of grey values • For M pixel with G grey values (g = 0, 1,… G-1) and ag as number of pixels with grey value g holds:

and

Salem, Teaching Notes on Image Processing, 2015

and

Lecture 2

15

Image Histogram Interpretation of typical histograms • Homogeneous image: one bar of length 1 • Two level image: two bars • Dark image with low contrast: there are more values of hg for lower g • Bright image with low contrast: there are more values of hg for larger g • High contrast image: all hg equal (e.g. = 1 / 256)

• Typical foreground / background image: bimodal histogram

Salem, Teaching Notes on Image Processing, 2015

Lecture 2

16

Image Histogram

Marsa Matrouh - Dark

Salem, Teaching Notes on Image Processing, 2015

Marsa Matrouh

Marsa Matrouh - Light

Lecture 2

17

Image Histogram

Marsa Matrouh – High Contrast

Salem, Teaching Notes on Image Processing, 2015

Marsa Matrouh

Marsa Matrouh – Low Contrast

Lecture 2

18

Report 2-1 • Apply the operations of increasing and decreasing the brightness and contrast on one of your own images. Show the histogram of the output images in comparison to the input image and comment the results.

Salem, Teaching Notes on Image Processing, 2015

Lecture 2

19

Image Histogram Nearly bimodal histogram

Meffert and Salem

Image Processing for Mechatronics Engineering

Lecture 21

20

Image Histogram Properties of histograms

• Spatial information is lost • Every image has a special histogram • BUT: every histogram is not assigned to a single image • Example: if objects in an image were rearranged then the histogram is not changed • The structure of an image can not derived from the histogram

• Histogram tells the user if an image is scaled well

Meffert and Salem

Image Processing for Mechatronics Engineering

Lecture 21

21

Image Histogram Two different images and their (identical) histogram

10

Meffert and Salem

Image Processing for Mechatronics Engineering

Lecture 21

22

Image Histogram N-dimensional histogram

• Useful for a lot of joint processes • In image processing (e.g.): multi-channel images • Definition with

number of corresponding pixel pairs

• Example: number of pixels having the value gμ in the matrix for red and gν in the matrix for blue Salem, Teaching Notes on Image Processing, 2015

Lecture 2

23

Image Statistics - Histogram red

Two-dimensional histogram

number of pixels with the two defined grey values blue Meffert and Salem

Image Processing for Mechatronics Engineering

Lecture 21

24

Image Statistics - Histogram

The baboons colour image BUNT

Meffert and Salem

Image Processing for Mechatronics Engineering

Lecture 21

25

Image Statistics - Histogram

G

B

G

B

R

Color

BUNT

R

Meffert and Salem

Image Processing for Mechatronics Engineering

Lecture 21

26

Image Statistics - Histogram

BUNT

R

G

red

green

5

5 hRlabe l

hGlabe l

512

512

0

100

200 label

300

0

100

200

300

label H1

Lecture 21

27

Image Statistics - Histogram

BUNT

R

B

blue

red

5

5

hRlabe l

hBlabe l

512

512

0

100

200 label

Meffert and Salem

300

0

100

200

300

label

Image Processing for Mechatronics Engineering H4

Lecture 21

28

Image Statistics - Histogram

BUNT

G

B

blue

green

5

5

hGlabe l

hBlabe l

512

512

0

100

200 label

Meffert and Salem

300

0

100

200

300

label

Image Processing for Mechatronics Engineering H4

Lecture 21

29

Wikipedia: Mandrillus is the genus of the mandrill and its close relative the drill. These two species are closely related to the baboons, and until recently were lumped together as a single species of baboon. Both Mandrillus species have long furrows on either side of their elongated snouts. The adult male mandrill's furrows are blue, while the furrows of the drill are black. Both species are terrestrial, living on the ground of the rainforest and occasionally grasslands of Central Africa.

Foto: Haremsmännchen

Meffert and Salem

Image Processing for Mechatronics Engineering

Lecture 21

30

Image Statistics - Histogram • Cumulative Histogram

Salem, Teaching Notes on Image Processing, 2015

Lecture 2

31

Basic Image Processing Operations • Image-Processing operations may be divided into 3 classes based on information required to perform the transformation. • 1) Point Operations • process according to the pixel’s value alone (single pixel).

• 2) Neighborhood processing • process the pixel in a small neighborhood of pixels around the given pixel. • 3)Transforms • process entire image as one large block

Salem, Teaching Notes on Image Processing, 2015

Lecture 2

32

Point Operations • The gray value of each pixel in the output image g(x, y) depends on the gray value of only the corresponding pixel of the input image f (x,y). Every pixel of f(x, y) with the same gray level maps to a single (usually different) gray value in the output image.

Salem, Teaching Notes on Image Processing, 2015

Lecture 2

33

Image Arithmetic • Image arithmetic is the implementation of standard arithmetic operations. – –

– – –

Addition Subtraction Multiplication Division Complement

Salem, Teaching Notes on Image Processing, 2015

Lecture 2

34

Image Arithmetic • Let x is the old gray value, y is the new gray value, c is a positive constant. • • • • •

Addition: y = x + c Subtraction: y = x - c Multiplication: y = cx Division: y = x/c Complement: y= 255 - x

Salem, Teaching Notes on Image Processing, 2015

Lecture 2

35

Image Arithmetic • Image arithmetic has many uses in image processing for example, image subtraction. Image Arithmetic Saturation Rules: • The results of integer arithmetic can easily overflow the data type for storage. • Ex: unit8  [0-255] Result Class Truncated Value 300 uint8 255 -45 uint8 0 10.5 uint8 11 Salem, Teaching Notes on Image Processing, 2015

Lecture 2

36

Report 2-2 • Discuss different techniques to rescale the range of the output images after applying the arithmetic operations into the range of [0,255].

Salem, Teaching Notes on Image Processing, 2015

Lecture 2

37

Image Arithmetic - Addition • Lighten the image • Some details may be lost

+ 128 = Salem, Teaching Notes on Image Processing, 2015

Lecture 2

38

Image Arithmetic - Subtraction • Darken the image • Some details may be lost

- 128 Salem, Teaching Notes on Image Processing, 2015

= Lecture 2

39

Image Arithmetic - Multiplication Lighten the image Some details may be lost but less than addition

* 2 Salem, Teaching Notes on Image Processing, 2015

= Lecture 2

40

Image Arithmetic - Division Darken the image Some details may be lost but less than subtraction

/ 2 Salem, Teaching Notes on Image Processing, 2015

= Lecture 2

41

Image Arithmetic – Addition vs Multiplication

Salem, Teaching Notes on Image Processing, 2015

Lecture 2

42

Image Arithmetic – Subtraction vs Division

Salem, Teaching Notes on Image Processing, 2015

Lecture 2

43

Image Arithmetic – Complement • Create the negative image

Salem, Teaching Notes on Image Processing, 2015

Lecture 2

44

Image Arithmetic • Image arithmetic functions can be used in combination to perform a series of operations.

I = imread('rice.png'); I2 = imread('cameraman.tif'); K = imdivide(imadd(I,I2), 2); % not recommended Salem, Teaching Notes on Image Processing, 2015

Lecture 2

45

Image Arithmetic • imlincomb performs all the arithmetic operations in the linear combination in double precision and only rounds and saturates the final result. • K = imlincomb(.5,I,.5,I2); % recommended

Salem, Teaching Notes on Image Processing, 2015

Lecture 2

46

Report 2-3 • Apply the above mentioned operations on one of your own images or on MarsaMatrouhGrey image. Show the histograms and comment the results.

Salem, Teaching Notes on Image Processing, 2015

Lecture 2

47

Image Arithmetic – Denoising/Sharping

Salem, Teaching Notes on Image Processing, 2015

Lecture 2

48

Image Arithmetic – Fault Detection Where is the defect?

Image g(x,y) (no defect) Salem, Teaching Notes on Image Processing, 2015

Image f (x,y) (with defect) Lecture 2

49

Report 2-4 • Consider the previous images of circuits without and with defects. Apply manual alignment to align both images to each other and then apply the subtraction to find the defect.

Salem, Teaching Notes on Image Processing, 2015

Lecture 2

50

Image Arithmetic – Moving Object Detection

Salem, Teaching Notes on Image Processing, 2015

Lecture 2

51

Image Arithmetic – Moving Object Detection • Identify the active cells?

Salem, Teaching Notes on Image Processing, 2015

Lecture 2

52

Thresholding • Segmentation can be achieved simply by thresholding the image at a particular intensity level. • The technique that‘s most frequently employed for determining thresholds involves the histogram of the image. • Problems: – ignores spatial context, – selection of the threshold parameter

Salem, Teaching Notes on Image Processing, 2015

Lecture 2

53

Thresholding

Salem, Teaching Notes on Image Processing, 2015

Lecture 2

54

Thresholding

Salem, Teaching Notes on Image Processing, 2015

Lecture 2

55

Thresholding

Salem, Teaching Notes on Image Processing, 2015

Lecture 2

56

Double Thresholding • A larger threshold T2 yields “seeds” of the segmentation, which are accepted in all cases. • They grow in all directions where grey values can be found that exceed some smaller threshold T1. • method does take into account spatial context

Salem, Teaching Notes on Image Processing, 2015

Lecture 2

57

Report 2-5 • Program a small image processing code for fault detection for textile or glass industry. For example your program should be able to detect broken/ splitted/ cracked glass.

Salem, Teaching Notes on Image Processing, 2015

Lecture 2

58

Contacts Image Processing for senior students, 2015 Dr. Mohammed Abdel-Megeed M. Salem Faculty of Computer and Information Sciences, Ain Shams University Abbassia, Cairo, Egypt Tel.: +2 011 1727 1050 Email: [email protected] Website: https://sites.google.com/a/fcis.asu.edu.eg/salem/home

Salem, Teaching Notes on Image Processing, 2015

Lecture 2

59