Image Processing: Introduction University of the Philippines - - PowerPoint PPT Presentation

image processing introduction
SMART_READER_LITE
LIVE PREVIEW

Image Processing: Introduction University of the Philippines - - PowerPoint PPT Presentation

Image Processing: Introduction University of the Philippines August 2006 Diane Lingrand University of Nice Sophia Antipolis, France lingrand@polytech.unice.fr http://www.polytech.unice.fr/~lingrand 2006 2006 Sophia Antipolis Sophia


slide-1
SLIDE 1

2006

Image Processing: Introduction

University of the Philippines August 2006 Diane Lingrand University of Nice – Sophia Antipolis, France

lingrand@polytech.unice.fr http://www.polytech.unice.fr/~lingrand

slide-2
SLIDE 2

2006 Sophia Antipolis Sophia Antipolis

slide-3
SLIDE 3

2006

Course overview

  • Basics: image format, color representation
  • Quantification, Sampling and applications
  • Image segmentation
  • Noise and image restauration
  • Image and video compression
slide-4
SLIDE 4

2006

Today

  • Image acquisition
  • Image format
  • Data structures
  • Color representation
slide-5
SLIDE 5

2006

5

Image formation (1)

Sensor

Real world image sensor + =

slide-6
SLIDE 6

2006

6

Image Formation (2)

  • Visual sensors :

– photochimic (biological systems, photographic

films)

– photoelectric (CMOS, CCD)

  • Other sensors

– Medical imaging (IRM, rayons X, …) – Sismic imaging

slide-7
SLIDE 7

2006

7

Signal

  • Dimension :

– 1D, 2D, 3D, 2D+T, 3D+T, …

  • Nature :

– Analog – Digital

  • How to put an image on a computer ?

– Sampling (space) – Quantification (values)

slide-8
SLIDE 8

2006

8

An image on computer

  • An array of pixels

– 1D array – 2D array – 3D array (video sequence or volumetric image) – …

  • A pixel (= picture element)

– Its value is an intensity (scalar), a color ... – dimension ?

slide-9
SLIDE 9

2006

9

Tesselation: how to arrange the pixels

hexagonal rectangular triangular « quite real »

slide-10
SLIDE 10

2006

10

Neighbourhood

  • Square or rectangular

pixels :

  • Hexagonal pixels :

4-connexity 8-connexity 6 neighbours

slide-11
SLIDE 11

2006

11

Distances

  • Euclidean Distance

(k - i)2 + (l - j)2

  • Block Distance

(Manhattan) | k – i | + | l – j |

  • Chess Distance

max( | k - i | , | l – j |)

i k j l

slide-12
SLIDE 12

2006

12

2D visible images

  • Black and white images

– a pixel value is black or white (binary)

  • Grey images / Grey levels images

– a pixel value is represented by a scalar value

  • Color images

– a pixel value is represented by 3 or more scalar values (RGB, …)

  • Multi-spectral images, …
slide-13
SLIDE 13

2006

13

Quantification

  • Only few grey levels or colors are considered:

– grey levels: 256 – number of colors: 256 * 256 * 256

  • Consequences :

– quality decreasing – artefacts

256*256*256 = 16777216 colors 8*8*8 = 512 colors 2*2*2 = 8 colors

slide-14
SLIDE 14

2006

14

Trade-off between …

… visual quality and memory space. The more colors ou grey levels we have, the better the visual quality but bigger the memory space used. do not increase the quantification step if the improved quality is not visible.

slide-15
SLIDE 15

2006

15

Idea of values

28 = 256 colors pixel on 8 bits 216 colors = 65536 pixel on 16 bits

memory space * 2

  • nb. of colors * 256
slide-16
SLIDE 16

2006

Image Formats

  • r

How to memorize an image as a file on my computer disk.

slide-17
SLIDE 17

2006

17

What do I need ?

  • Necessary informations :

– image width (in pixels) – image heigth (in pixels) – image value (intensity) for each pixel

  • Image values :

– are usually given line by line from top to bottom and then from left to right

slide-18
SLIDE 18

2006

18

A very simple image format: PBM

  • Black and white images

> more ph021-ascii.pbm P1 # CREATOR: XV Version 3.10a Rev: 12/29/94 (PNG patch 1.2) 640 480 1 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 0 1 1 1 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 …

indicates the format : PBM width and height of images, in pixels l

slide-19
SLIDE 19

2006

19

The whole image in PBM

slide-20
SLIDE 20

2006

20 > more ph021-ascii.pgm P2 # CREATOR: XV Version 3.10a Rev: 12/29/94 (PNG patch 1.2) 640 480 255 73 154 125 160 172 163 172 168 131 162 171 171 170 174 165 171 167 166 159 170 164 170 157 93 54 67 86 96 50 75 61 88 135 163 54 85 82 70 66 72 45 56 56 54 80 84 111 134 103 120 154 169 175 182 174 175 172 172 176 175 173 177 173 174 155 115 122 114 104 99 91 102 95 102 117 103 106 190 178 176 177 176 176 180 179 176 176 175 177 179 179 178 180 182 180 179 180 177 181 184 179 180 180 178 178 179 179 179 181 181 183 185 182 184 182 182 182 181 182 183 184 183 185 182 184 186 186 184 185 182 184 183 184 184 184 186 185 184 184 186 183 184 184 187 190 183 187 184 185 185 186 187 186 188 187 188 187 185 191 189 185 186 188 187 187 185 185 185 188 185 …

Another very simple format : PGM

  • For grey levels images

indicates the format: PGM width and height max grey level

slide-21
SLIDE 21

2006

21

Previous image in PGM format

slide-22
SLIDE 22

2006

22 > more ph021-ascii.ppm P3 # CREATOR: XV Version 3.10a Rev: 12/29/94 (PNG patch 1.2) 640 480 255 89 62 79 167 143 165 130 117 145 155 155 191 160 169 210 137 170 203 151 176 206 158 167 198 127 125 164 155 156 200 156 169 211 155 170 211 153 170 213 153 177 215 139 172 205 150 174 210 146 171 202 140 175 195 136 169 178 152 180 181 144 175 177 148 183 177 140 175 142 82 113 54 45 72 19 62 79 45 82 97 64 92 108 71 46 63 18 72 92 33 64 79 0 87 109 26 129 157 82 158 184 113 54 72 0 79 107 30 71 102 43 60 88 37 60 86 21 68 88 35 44 55 21 53 67 31 51 69 27 50 68 18 81 94 38 …

Another very simple format : PPM

  • For RGB color

images

indicates the format: PPM width and height each color component between 0 and 255

(r,g,b)

slide-23
SLIDE 23

2006

23

The same image but ... in color !

slide-24
SLIDE 24

2006

24

Size of files

  • In our example (640x480):

PBM : 620 KB PGM : 1,2 MB PPM : 3,6 MB

slide-25
SLIDE 25

2006

25

Binary formats

  • The headings are still in ASCII, the data is saved

in binary.

  • We need to know the pixel value representation

(int, char, ….). – example of PGM : unsigned char (8 bits)

  • Code in C / C++

size_t fread(void *data, size_t size, size_t nobj, FILE *stream) size_t fwrite(const void *data, size_t size, size_t nobj, FILE *stream)

slide-26
SLIDE 26

2006

26

Be careful of little and big endians !

  • Little endian :

– light bytes will be stored to lowest addressel – ex: Intel processor

  • Big endian :

– heavy level bytes will be saved to the lowest adresses – ex: Motorola processor (Mac)

  • Example : Byte3 Byte2 Byte1 Byte0 will be saved as :

@ + 0 : Byte3 @ + 1 : Byte2 @ + 2 : Byte1 @ + 3 : Byte0 @ + 0 : Byte0 @ + 1 : Byte1 @ + 2 : Byte2 @ + 3 : Byte3

Big endian Little endian

slide-27
SLIDE 27

2006

27

Endians and Images

  • Two choices are possible :

– format depends on the computer that wrote the file: we need to store this information in the file heading – format does not depend on the computer that wrote the file: little or big endian is chosed for the file format

  • Examples :

– Big endian : Adobe Photoshop, JPEG, MacPaint – Little endian : BMP, GIF, QTM (QuickTime) – Both : TIFF, XWD (X Window Dump)

slide-28
SLIDE 28

2006

28

Back to our example

PBM ascii : 620 KB PBM raw : 40 KB PGM ascii : 1,2 MB PGM raw : 310 KB PPM ascii : 3,6 MB PPM raw : 900 KB ∗ 16 ∗4 ∗4 P1 P1 P4 P4 P5 P5 P3 P3 P2 P2 P6 P6

slide-29
SLIDE 29

2006

29

ASCII / binary : no confusion !

mMNM&%w

mkMH$MUMFPM,NM#Z%% :!.:x )!!X)$MMWWMM$**$$Nx~~` !<!*R@@MNR$$$B$WWXXtdn."?XT!: :~` tH!~!!MBT5$$$$$$$WRHb!"! !. .<.$f <!!HR$$$$$$$$$$$X?`>!)X?~( ~-!#@\~/!!!@$$$$$$$$$$$R! `<!M>-!%. .!!"X !XXM$$$$$$$$$$$R!! !X!!i"~ `: :!t! <: !?X***$$$$$$$***~! ??>X ` ' `!~~: ~x. !R$$$$* . x W` - > ~! ::" `L?X#$F.uC"L" . $ `n % ~<%!.#mT$"<$k"$$Q?:xW " ' ~ 4BhU@$W$?!$$ "$$WdN"'. R$$$$$$* $$k'$$$$$ !&!x Albert !T$$$$6n'$$$ $$$(T .?" Einstein @!M$$$$ec.")d$$$$! `. !!8$f"` " `^T$!~ !!R$ :xxox..o:d" " #@!$WN@W$$$~" \ "~R$$$$$$" N. . "#"""" :X `Wmu. '<:<!! .u$M $!$$$bou. .:!!!~!!? . :ud$$$! ~@XR$$$$$$$eu. <!!!!RnL`"% ~\ X~ti `$RM$R~ :` #W$$$R$$$T$$$c <!!!!XX?*> ~ .-` `% XxU@$R~ ~: . ^*$M"$$B$$$"$!:Mm m!!!!!M8X! :`.:L ~UT?8$F .!-.x!: "N `9$$$":"$LFDSA HDFB<FLOYDXM ~:X. `"X:. '*$$" :?ud$RW:~<x %'$$$# $s$EYNRBx

slide-30
SLIDE 30

2006

30

Compression

  • Some consecutives pixels have same value

: counting identical pixels:

– [red, red, red ] => [(red, 3)]

  • Eliminate rare colors or similar colors
  • Some pixel's values are rare, some others

are frequent: using less memory for frequent pixels

  • Same reasoning on image transforms.
slide-31
SLIDE 31

2006

31

Color Model

  • Direct : pixel value corresponds to a grey level
  • r to a (R;G;B) triplet value :

it is the pen's color

  • Indirect: pixel value corresponds to a color

index in a color table : it is the pen's index

slide-32
SLIDE 32

2006

32

Other image formats

  • without compression : PBM, PGM, PPM, TIFF
  • with compression:

– lossless :

  • TIFF (PZW)
  • GIF (8 bits, propriétaire)
  • PNG (licence GNU www.visualtek.com/PNG)

– lossly : JPEG

  • vectorial drawing : PostScript, SVG
  • … back to our example :

– JPEG format = 88 KB

slide-33
SLIDE 33

2006

Data structure

slide-34
SLIDE 34

2006

34

Data structure

  • We want a structure that enables us :

– to access to pixel values regarding the coordinates (i,j) – to browse an image from the first to the last pixel – to access to pixel (i,j) neighbours

slide-35
SLIDE 35

2006

35

Image frame

  • Usually :

x y width height

slide-36
SLIDE 36

2006

36

A 2D image seen as a 1D array

  • allow to have only one loop for the entire image

browsing :

for (int i = 0 ; i < im.getWidth()*im.getHeight(); i++) { …}

  • not so easy to access to neighbours:

i i+1 i -1 i-image.getWidth()

slide-37
SLIDE 37

2006

37

A 2D image seen as a 2D array

  • Allow to easily access to neighbours

data[i+1][j-1] ….

  • Need two imbricated loops for the entire image

browsing: for( int i = 0 ; i < image.getWidth() ; i++) { for ( int j = 0 ; j < image.getHeight(); j++) { …. }}

slide-38
SLIDE 38

2006

38

Several “tricks”

  • Introducing an auxiliary counter variable :

int ij = i + j*image.getWidth();

  • Adding pointers to rows :

char * char char **img = img[y][x] pointer on data : char *p = &img[0][0]; p

slide-39
SLIDE 39

2006

39

Example in C

typedef struct { int width; int height; unsigned char *data; } ImageChar ; typedef struct { int width; int height; unsigned char **img; unsigned char *data; } ImageChar ;

slide-40
SLIDE 40

2006

40

Example in C++ : template class

template <class Type> class Image { public: Image( const Type&); private: Type *data; int width, height; … }

slide-41
SLIDE 41

2006

41

File reading in C++

  • Problem of templates instanciation: we do not

know the type of pixels before file reading.

  • Solution : polymorphism !

– a mother class BaseImage with the template class as daughter – while reading, we create a BaseImage qui est that is in fact a Image <short> i or a Image

<double> i …

slide-42
SLIDE 42

2006

42

In Java

public class Image { private int width; private int height; private int [] data; public Image(int w, int h) { height = h; width = w; data = new int [h*w]; } public int getPixel(int i, int j) { …. } public int getPixel(int ij) { …. } public int setPixel(int i, int j, int value) { …. } …. } 1 pixel = 32 bits = 4 * 8 bits

blue (8 bits) green (8 bits) red (8 bits) Alpha (8 bits)

slide-43
SLIDE 43

2006

43

Images in Java

  • Push Model ou Producer/Consumer (jdk 1.1.*,

1.2.*)

– Image – ImageProducer – ImageConsumer – ImageObserver

  • Immediate Mode ou Image Buffer Model (new in

Java 2D)

– BufferedImage, Raster – BufferedImageOp, RasterOp

  • Pull Model (JAI = Java Advanced Imaging)

– RenderableImage, RenderableImageOp, ...

slide-44
SLIDE 44

2006

44

BufferedImage

Buffered Image Raster Color Model DataBuffer Sample Model Color Space has a

slide-45
SLIDE 45

2006

45

Java 2D

  • Imaging Interfaces
  • Image Data Class

– BufferedImage, LookupTable, DataBuffer, DataBufferByte, DataBufferInt, …, Kernel, Raster, ….

  • Image Operation Classes

– AffineTransformOp, BandCombineOp, BufferedImageFilter, ColorCongreenOp, ConvolveOp, LookupOp, RescaleOp

  • Sample Model Classes

– BandedSampleModel, ComponentSampleModel, …

  • Color Model Classes

– ColorModel, ComponentColorModel, DirectColorModel, IndexColorModel, PackedColorModel

  • Exception Classes

– ImagingOpException, RasterFormatException

slide-46
SLIDE 46

2006

46

Input - Output

  • Javax.imageio.ImageIO (since j2sdk 1.4.0)

– Simplification of reading and writing – Formats : gif, jpeg, png, xbm – Possibility of adding other formats

  • Image file reading

File f = new File(“toto.gif”); BufferedImage bi; try { bi = ImageIO.read(f);} catch(IOException e) {...}

  • Image file writing

File f = new File(“toto.jpg”); try { ImageIO.write(bi, ”jpg”, f);} catch(IOException e) {...}

slide-47
SLIDE 47

2006

47

A very famous image : LENA (http://www.lenna.org/)

slide-48
SLIDE 48

2006

48

Let's talk about color

slide-49
SLIDE 49

2006

49

What is color ?

  • physical process

– physical interactions of electromagnetic waves with physical objects

  • psycho-physiological process

– our visual system's interpretation of these penonomenons (eye + brain)

slide-50
SLIDE 50

2006

50

Color perception

  • in the retina:

photoreceptors – rod cells

  • 1 pigment

– cone cells

  • 3 pigments:

– red – green – blue

slide-51
SLIDE 51

2006

51

Eye's sensibility

555

max of perception

= red luminosity perception during the day green red blue

slide-52
SLIDE 52

2006

52

Eye's performances

  • The eye

distinguishes:

– 350000 colors, – 150 hues – 3000 colored lights

  • f same intensity

red Purples blue green yellow

slide-53
SLIDE 53

2006

53

Light spectrum

wavelength frequency U.V. I.R. ~ 1015 Hz

slide-54
SLIDE 54

2006

54

Definitions

  • hue : name of the color, dominant wavelength

– non additive

  • saturation : degree of dilution in white
  • luminosity : intensity of achromatic light

– measurable and additive – unit: 1cd.m-2 = 10 nits

slide-55
SLIDE 55

2006

55

Small history of color photography

  • 1848 : 1st photography of the visible spectrum by

Becquerel

  • 1870 : black chamber de Ducos du Hauron
  • 1894 : interferentiel process de Gabriel Lippman
  • 1907 : autochrome process from the Lumières

brothers

  • 1930 : Kodachrome system
  • 1932 : Color film
slide-56
SLIDE 56

2006

56

Color acquisition

  • 1st step :

– Filter to stop infra-red wavelenghts

  • Then :

– colored optical filters

  • filters + monochrome camera

– mono-CCD color camera

  • overload of filters masks

– tri-CCD color camera

  • prism duplicates the image in 3
slide-57
SLIDE 57

2006

57

Gamma correction

  • The

intensity measured by cameras depends on a concave logarithm of real

  • intensity. Colors appear less satured and

chromatic coordinates are erroneous.

I = A.Dγ

camera monitor

slide-58
SLIDE 58

2006

Examples of gamma correction

1 1.7 2 0.7 1 1.5

slide-59
SLIDE 59

2006

Color representation

slide-60
SLIDE 60

2006

60

Color representation

  • Color Atlas :

– Munsell, 1929

  • ordered by tonality, clarity and

saturation

  • 10 tonalitiess, 10 levels of clarity

– NCS (Natural System of Colors)

  • 3-D space representations :

– based on our perception – related to physical entities

slide-61
SLIDE 61

2006

61

3D space

  • primary colors (RBG)

– red (700 nm), green (546 nm), blue (435.8 nm) – used by projection

  • secondary colors (YCM)

– yellow, cyan, magenta – used by printers

slide-62
SLIDE 62

2006

62

additives colors

green blue red yellow = red + green magenta = red + blue cyan = blue + green white = red + green + blue = magenta + yellow + cyan

slide-63
SLIDE 63

2006

63

substractives colors

green = -yellow -cyan cyan yellow blue =

  • cyan -magenta

magenta red =

  • magenta -yellow

black = -green - blue - red = -yellow - cyan -magenta

slide-64
SLIDE 64

2006

Printing

slide-65
SLIDE 65

2006

65

Addition - substraction

  • color C = rR + gG + bB
  • Coordinates or chromaticity values :

r = r / (r + g + b) g = g / (r + g + b) b = b / (r + g + b)

slide-66
SLIDE 66

2006

66

RGB color model

wavelength

slide-67
SLIDE 67

2006

67

metamerism: different spectrum, same color

wavelength luminosity

  • > color blindness
slide-68
SLIDE 68

2006

68

Chromaticity diagram CIE (1935)

  • Primary colors :

– Theoretical colors : X, Y et Z – Y luminance – Equal proportions gives white

  • No more negative

values

  • CIEXYZ model
slide-69
SLIDE 69

2006

69

CIE XYZ

X = 0.489989 R + 0.310008 G + 0.2 B Y = 0.26533R + 0.81249 G + 0.01 B Z = 0.0 R + 0.01 G + 0.99 B R = 2.3647 X - 0.89658 Y – 0.468083 Z G = -0.515155 X + 1.426409 Y – 0.088746 Z B = -0.005203 X - 0.014407 Y + 1.0092 Z

slide-70
SLIDE 70

2006

70

Chromaticity diagram

slide-71
SLIDE 71

2006

71

colors

slide-72
SLIDE 72

2006

72

colors (2)

Film Colour monitor (sRGB) Printing inks

slide-73
SLIDE 73

2006

73

Smith's HSV Pyramid

Hue, Saturation, Value Green Yellow Hue Black White Red

slide-74
SLIDE 74

2006

74

Other models

Luminance : Y = 0.299 R + 0.587 G + 0.114 B

  • Betacam (Y pb pr )

pb = 0.5 (B – Y) / (1 – 0.114) pr = 0.5 (R – Y)/ (1 – 0.299)

  • Digital Video System (Y Cb Cr )

Cb = 128 + 112 pb Cr = 128 + 112 pr

  • YUV

U = 0.493 ( B – Y ) V = 0.877 ( R – Y)

  • NTSC YIQ

I = 0.6 R – 0.28 G – 0.32 B Q = 0.21 R – 0.52 G + 0.31 B

slide-75
SLIDE 75

2006

75

sRGB format

  • in order to normalize the representation of \

RGB / YCMK for all printers, monitors, ...

  • RGB + gamma de 2.2
  • exists in Java2D

sRGB monitor

without transformation !

slide-76
SLIDE 76

2006

slide-77
SLIDE 77

2006

Illusions in color perception

the Hermann Grid Illusion

slide-78
SLIDE 78

2006

78

Cells « on-center »

+ + + +

slide-79
SLIDE 79

2006

79

Hermann Grid Illusion

  • Near the fovea
  • Peripheric area
slide-80
SLIDE 80

2006

80

Mach Bandes

w/3 2w/3 w 255

(0,0,0) (0,255,0)

… perception signal

slide-81
SLIDE 81

2006

81

Illusions (suite)

slide-82
SLIDE 82

2006

82

Illusions (suite)

slide-83
SLIDE 83

2006

Bibliography

  • “Digital Image Processing" par W. K. Pratt, John

Wiley & Sons, inc., Third Edition, 2001

  • "Digital Image Processing" par Gonzalez et Woods,

Prentice Hall, Second Edition, 2002

  • http://www.dai.ed.ac.uk/HIPR2/
  • Books available on the web

http://homepages.inf.ed.ac.uk/rbf/CVonline/books.ht

  • Computer Vision Online

http://www.dai.ed.ac.uk/CVonline/transf.htm

  • Vetterli's talks (wavelets, ..)

http://lcavwww.epfl.ch/~vetterli/talks/index.html

slide-84
SLIDE 84

2006

84

Illusions (suite) Color persistence