• Aucun résultat trouvé

Image Processing: Introduction

N/A
N/A
Protected

Academic year: 2022

Partager "Image Processing: Introduction"

Copied!
84
0
0

Texte intégral

(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

(2)

2006 Sophia AntipolisSophia Antipolis

(3)

2006

Course overview

• Basics: image format, color representation

• Quantification, Sampling and applications

• Image segmentation

• Noise and image restauration

• Image and video compression

(4)

2006

Today

• Image acquisition

• Image format

• Data structures

• Color representation

(5)

2006 5

Image formation (1)

Sensor

Real world + sensor = image

(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

(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)

(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 ?

(9)

2006 9

Tesselation: how to arrange the pixels

hexagonal rectangular

triangular « quite

real »

(10)

2006 10

Neighbourhood

• Square or rectangular pixels :

• Hexagonal pixels :

4­connexity 8­connexity

6 neighbours

(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

(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, …

(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

(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.

(15)

2006 15

Idea of values

2

8

= 256 colors pixel on 8 bits

2

16

colors = 65536 pixel on 16 bits

memory space * 2

nb. of colors * 256

(16)

2006

Image Formats

or

How to memorize an image as a

file on my computer disk.

(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

(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

(19)

2006 19

The whole image in PBM

(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

(21)

2006 21

Previous image in PGM

format

(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)

(23)

2006 23

The same image but ...

in color !

(24)

2006 24

Size of files

• In our example (640x480):

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

(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)

(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

(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)

(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

  

P1P1

P4P4 P5P5

P3P3 P2P2

P6P6

(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

(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.

(31)

2006 31

Color Model

• Direct : pixel value corresponds to a grey level or 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

(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

(33)

2006

Data structure

(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

(35)

2006 35

Image frame

• Usually :

x

y

0 width

height

(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()

(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++) {

….

}}

(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

(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 ;

(40)

2006 40

Example in C++ : template class

template <class Type> class Image { public:

Image( const Type&);

private:

Type *data;

int width, height;

}

(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

(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)

(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, ...

(44)

2006 44

BufferedImage

Buffered Image

Raster Color Model

DataBuffer Sample Model Color Space

has a

(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

(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) {...}

(47)

2006 47

A very famous image : LENA

(

http://www.lenna.org/)

(48)

2006 48

Let's talk about color

(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)

(50)

2006 50

Color

perception

• in the retina:

photoreceptors – rod cells

1 pigment

– cone cells

3 pigments:

– red – green – blue

(51)

2006 51

Eye's sensibility

555

max of perception

= red luminosity perception during the day

green red

blue

(52)

2006 52

Eye's performances

• The eye

distinguishes:

– 350000 colors, – 150 hues

– 3000 colored lights

of same intensity red

Purples blue

green

yellow

(53)

2006 53

Light spectrum

wavelength frequency

U.V. I.R.

~ 1015 Hz

(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

(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

(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

(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

(58)

2006

Examples of gamma correction

1 1.7 2

0.7 1 1.5

(59)

2006

Color representation

(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

(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

(62)

2006 62

additives colors

green blue

red

yellow =  red + green magenta =

red + blue

cyan = blue + green white 

= red + green + blue 

= magenta + yellow + cyan

(63)

2006 63

substractives colors

green = ­yellow ­cyan cyan

yellow blue = 

­cyan ­magenta

magenta

red =

­magenta ­yellow

black

= ­green ­ blue ­ red

= ­yellow ­ cyan ­magenta

(64)

2006

Printing

(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)

(66)

2006 66

RGB color model

wavelength

(67)

2006 67

metamerism: different spectrum, same color

wavelength luminosity

-> color blindness

(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

(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

(70)

2006 70

Chromaticity

diagram

(71)

2006 71

colors

(72)

2006 72

colors (2)

Film Colour monitor (sRGB)

Printing inks

(73)

2006 73

Smith's HSV Pyramid

Hue, Saturation, Value

Green Yellow

Hue

Black White

Red

(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

(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 !

(76)

2006

(77)

2006

Illusions in color perception

the Hermann Grid Illusion

(78)

2006 78

Cells « on-center »

+

+

+

+

­ ­ ­

­

­ ­ ­

­

­

­ ­

­

(79)

2006 79

Hermann Grid Illusion

• Near the fovea • Peripheric area

(80)

2006 80

Mach Bandes

w/3 2w/3 w

0 255

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

perception signal

(81)

2006 81

Illusions (suite)

(82)

2006 82

Illusions (suite)

(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.htm

•Computer Vision Online

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

•Vetterli's talks (wavelets, ..)

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

(84)

2006 84

Illusions (suite)

Color persistence

Références

Documents relatifs

Note: The expiry date field is analogous to the option contract month field of the risk array record in previous versions of the risk parameter file format. • For ordinary

Each entry is a symbolic link to the file or device opened on that file descrip- tor.You can write to or read from these symbolic links; this writes to or reads from the

This field contains 03034H, the hexadecimal encoding of the ASCII character ’04’, which specifies the record type to be an Extended Linear Address

If this token is present, the auto-login process will supply the specified string if the remote server requires an additional account password.

The End-of-File control word causes input processing to revert to the file that invoked, the current imbed file.. If the current file was not imbedded,

Action: With prototype (a), each line in the given line-number range “lpar” is blanked according to the pattern of the string specified by the string expression “strexp”,

Then insert the newly created CP/M operations diskette in disk drive A, and insert the NEVADA SOFTWARE distribution diskette in drive Band type (ctl-c) to

The goal of this paper is to shed light on this complex problem by performing a comprehensive analysis of the factors that affect the parsing of the PE executable file format and on