cimg slides

219
Introduction to The CImg Library C++ Template Image Processing Library (v.1.2.5) David Tschumperlé CNRS UMR 6072 (GREYC) - Image Team

Upload: durvalprintes

Post on 24-Mar-2015

144 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CImg Slides

Intro

duct

ion

toT

heC

Img

Libr

ary

C+

+Te

mpl

ate

Imag

eP

roce

ssin

gLi

brar

y(v

.1.2

.5)

Dav

idT

schu

mpe

rlé

CN

RS

UM

R60

72(G

RE

YC

)-

Imag

eTe

am

Page 2: CImg Slides

Thi

sdo

cum

enti

sdi

strib

uted

unde

rth

eC

C-B

Y-N

C-S

Alic

ense

•D

ocum

enta

vaila

ble

at:

http:// img.sour eforge.net/CImgslides.pdf

Page 3: CImg Slides

Out

line

-PA

RT

IofI

I:C

Img

Libr

ary

Ove

rvie

w

•C

onte

xt:

Imag

eP

roce

ssin

gw

ithC

++

.

•A

iman

dta

rget

edau

dien

ce.

•W

hyco

nsid

erin

gT

heC

Img

Libr

ary

?

•C

Img<

T>

:A

clas

sfo

rim

age

man

ipul

atio

n.

•Im

age

cons

truc

tion,

data

acce

ss,m

ath

oper

ator

s.

•B

asic

imag

etr

ansf

orm

atio

ns.

•D

raw

ing

thin

gson

imag

es.

•C

ImgL

ist<

T>

:Im

age

colle

ctio

nm

anip

ulat

ion.

•B

asic

man

ipul

atio

nfu

nctio

ns.

•C

ImgD

ispl

ay:

Imag

edi

spla

yan

dus

erin

tera

ctio

n.

•D

ispl

ayin

gim

ages

inw

indo

ws.

Page 4: CImg Slides

Out

line

-PA

RT

IIof

II:M

ore

insi

ghts

•Im

age

Filt

erin

g:

Goa

land

prin

cipl

e.

•C

onvo

lutio

n-

Cor

rela

tion.

•M

orph

omat

hs-

Med

ian

Filt

er.

•A

niso

trop

icsm

ooth

ing.

•O

ther

rela

ted

func

tions

.

•Im

age

Loop

s:

Usi

ngpr

edefi

ned

mac

ros.

•S

impl

elo

ops.

•N

eigh

borh

ood

loop

s.

•T

hepl

ug-in

mec

hani

sm.

•D

ealin

gw

ith3D

obje

cts.

•S

hare

dim

ages

.

Page 5: CImg Slides

PAR

TIo

fII

Page 6: CImg Slides

Out

line

-PA

RT

IofI

I:C

Img

Libr

ary

Ove

rvie

w

⇒C

onte

xt:

Imag

eP

roce

ssin

gw

ithC

++.

•A

iman

dta

rget

edau

dien

ce.

•W

hyco

nsid

erin

gT

heC

Img

Libr

ary

?

•C

Img<

T>

:A

clas

sfo

rim

age

man

ipul

atio

n.

•Im

age

cons

truc

tion,

data

acce

ss,m

ath

oper

ator

s.

•B

asic

imag

etr

ansf

orm

atio

ns.

•D

raw

ing

thin

gson

imag

es.

•C

ImgL

ist<

T>

:Im

age

colle

ctio

nm

anip

ulat

ion.

•B

asic

man

ipul

atio

nfu

nctio

ns.

•C

ImgD

ispl

ay:

Imag

edi

spla

yan

dus

erin

tera

ctio

n.

•D

ispl

ayin

gim

ages

inw

indo

ws.

Page 7: CImg Slides

Out

line

-PA

RT

IofI

I:C

Img

Libr

ary

Ove

rvie

w

•C

onte

xt:

Imag

eP

roce

ssin

gw

ithC

++

.

⇒A

iman

dta

rget

edau

dien

ce.

•W

hyco

nsid

erin

gT

heC

Img

Libr

ary

?

•C

Img<

T>

:A

clas

sfo

rim

age

man

ipul

atio

n.

•Im

age

cons

truc

tion,

data

acce

ss,m

ath

oper

ator

s.

•B

asic

imag

etr

ansf

orm

atio

ns.

•D

raw

ing

thin

gson

imag

es.

•C

ImgL

ist<

T>

:Im

age

colle

ctio

nm

anip

ulat

ion.

•B

asic

man

ipul

atio

nfu

nctio

ns.

•C

ImgD

ispl

ay:

Imag

edi

spla

yan

dus

erin

tera

ctio

n.

•D

ispl

ayin

gim

ages

inw

indo

ws.

Page 8: CImg Slides

Con

text

•D

igita

lIm

ages

.

•O

na

com

pute

r,im

age

data

stor

edas

adi

scre

tear

ray

ofva

lues

(pix

els

orvo

xels

).

Page 9: CImg Slides

Con

text

•A

cqui

red

digi

tali

mag

esha

vea

loto

fdiff

eren

ttyp

es:

–D

omai

ndi

men

sion

s:

2D(s

tatic

imag

e),

2D+

t(im

age

sequ

ence

),3D

(vol

umet

ricim

age)

,3D

+t

(seq

uenc

eof

volu

met

ricim

ages

),...

Page 10: CImg Slides

Con

text

•A

cqui

red

digi

tali

mag

esha

vea

loto

fdiff

eren

ttyp

es:

–D

omai

ndi

men

sion

s:

2D(s

tatic

imag

e),

2D+

t(im

age

sequ

ence

),3D

(vol

umet

ricim

age)

,3D

+t

(seq

uenc

eof

volu

met

ricim

ages

),...

–P

ixel

dim

ensi

ons

:P

ixel

sca

nbe

scal

ars,

colo

rs,N

−D

vect

ors,

mat

rices

,...

Page 11: CImg Slides

Con

text

•A

cqui

red

digi

tali

mag

esha

vea

loto

fdiff

eren

ttyp

es:

–D

omai

ndi

men

sion

s:

2D(s

tatic

imag

e),

2D+

t(im

age

sequ

ence

),3D

(vol

umet

ricim

age)

,3D

+t

(seq

uenc

eof

volu

met

ricim

ages

),...

–P

ixel

dim

ensi

ons

:P

ixel

sca

nbe

scal

ars,

colo

rs,N

−D

vect

ors,

mat

rices

,...

–P

ixel

data

rang

e:

depe

nds

onth

ese

nsor

sus

edfo

rac

quis

ition

,ca

nbe

N-b

its(u

sual

ly8,

16,2

4,32

...),

som

etim

esflo

at-v

alue

d.

Page 12: CImg Slides

Con

text

•A

cqui

red

digi

tali

mag

esha

vea

loto

fdiff

eren

ttyp

es:

–D

omai

ndi

men

sion

s:

2D(s

tatic

imag

e),

2D+

t(im

age

sequ

ence

),3D

(vol

umet

ricim

age)

,3D

+t

(seq

uenc

eof

volu

met

ricim

ages

),...

–P

ixel

dim

ensi

ons

:P

ixel

sca

nbe

scal

ars,

colo

rs,N

−D

vect

ors,

mat

rices

,...

–P

ixel

data

rang

e:

depe

nds

onth

ese

nsor

sus

edfo

rac

quis

ition

,ca

nbe

N-b

its(u

sual

ly8,

16,2

4,32

...),

som

etim

esflo

at-v

alue

d.

–Ty

peof

sens

orgr

id:

Rec

tang

ular

,Oct

agon

al,.

..

Page 13: CImg Slides

Con

text

•A

cqui

red

digi

tali

mag

esha

vea

loto

fdiff

eren

ttyp

es:

–D

omai

ndi

men

sion

s:

2D(s

tatic

imag

e),

2D+

t(im

age

sequ

ence

),3D

(vol

umet

ricim

age)

,3D

+t

(seq

uenc

eof

volu

met

ricim

ages

),...

–P

ixel

dim

ensi

ons

:P

ixel

sca

nbe

scal

ars,

colo

rs,N

−D

vect

ors,

mat

rices

,...

–P

ixel

data

rang

e:

depe

nds

onth

ese

nsor

sus

edfo

rac

quis

ition

,ca

nbe

N-b

its(u

sual

ly8,

16,2

4,32

...),

som

etim

esflo

at-v

alue

d.

–Ty

peof

sens

orgr

id:

Rec

tang

ular

,Oct

agon

al,.

..

•A

llth

ese

diffe

rent

imag

ety

pes

are

digi

tally

stor

edus

ing

diffe

rent

file

form

ats

:

–P

NG

,JP

EG

,BM

P,T

IFF,

TG

A,D

ICO

M,A

NA

LYZ

E,.

..

Page 14: CImg Slides

Con

text

(a)I1

:W

×H

→[0

,255]3

(b)I2

:W

×H

×D

→[0

,65535]3

2(c

)I3

:W

×H

×T

→[0

,4095]

•I 1

:cl

assi

calR

GB

colo

rim

age

(dig

italp

hoto

grap

h,sc

anne

r,...

)(8

bits

)

•I 2

:D

T-M

RIv

olum

etric

imag

ew

ith32

mag

netic

field

dire

ctio

ns(1

6bi

ts)

•I 3

:S

eque

nce

ofec

hogr

aphy

imag

es(1

2or

16bi

ts).

Page 15: CImg Slides

Con

text

•Im

age

Pro

cess

ing

and

Com

pute

rV

isio

nai

mat

the

elab

orat

ion

ofnu

mer

ical

algo

rithm

sab

leto

auto

mat

ical

lyex

trac

tfe

atur

esfr

omim

ages

,in

terp

ret

them

and

then

take

deci

sion

s.

⇒C

onve

rsio

nof

api

xela

rray

toa

sem

antic

desc

riptio

nof

the

imag

e.

-Is

ther

ean

yw

hite

pixe

lin

this

imag

e?

-Is

ther

ean

yco

ntou

rin

this

imag

e?

-Is

ther

ean

yob

ject

?

-W

here

’sth

eca

r?

-Is

ther

ean

ybod

ydr

ivin

gth

eca

r?

Page 16: CImg Slides

Con

text

Som

eob

serv

atio

nsab

outI

mag

eP

roce

ssin

gan

dC

ompu

ter

Vis

ion

:

•T

here

are

huge

and

activ

ere

sear

chfie

lds.

•T

hefin

algo

alis

alm

osti

mpo

ssib

leto

achi

eve

!

•T

here

are

been

thou

sand

s(m

illio

ns?)

ofal

gorit

hms

prop

osed

inth

isfie

ld,m

osto

fth

emre

lyin

gon

stro

ngm

athe

mat

ical

mod

elin

g.

•T

heco

mm

unity

isva

ried

and

noto

nly

com

pose

dof

very

tale

nted

prog

ram

mer

s.

⇒H

owto

desi

gna

reas

onab

lean

dus

eabl

epr

ogra

mm

ing

libra

ryfo

rsu

chpe

ople

?

Page 17: CImg Slides

Obs

erva

tion

•M

osto

fadv

ance

dim

age

proc

essi

ngte

chni

ques

are

“typ

ein

depe

nden

t”.

•E

x:

Bin

ariz

atio

nof

anim

age

I:Ω→

Γby

ath

resh

old

ǫ∈

R.

I:Ω→

0,1

such

that

∀p∈

Ω,

I(p

)=

0if

‖I(p

)‖<

ǫ

1if

‖I(p

)‖>

I1

∈R2−→

[0,255]

I2

∈R3−→

R

Page 18: CImg Slides

Con

text

•Im

plem

entin

gan

imag

epr

oces

sing

algo

rithm

shou

ldbe

asin

depe

nden

tas

poss

ible

onth

eim

age

form

atan

dco

ding

.

⇒G

ener

icIm

age

Pro

cess

ing

Libr

arie

s:

(...)

,Fre

eIm

age,

Dev

il,(.

..),O

penC

V,P

ando

re,C

Img,

Vig

ra,G

IL,O

lena

,(...

)

•C

++

isa

“goo

d”pr

ogra

mm

ing

lang

uage

for

solv

ing

such

apr

oble

m:

-G

ener

icity

ispo

ssib

le,q

uite

eleg

anta

ndfle

xibl

e(t

empl

ate

mec

hani

sm).

-C

ompi

led

code

.Fa

stex

ecut

able

s(g

ood

for

time-

cons

umin

gal

gorit

hms)

.-

Por

tabl

e,h

uge

base

ofex

istin

gco

de.

•D

ang

er:

Too

muc

hge

neric

itym

ayle

adto

unre

adab

leco

de.

Page 19: CImg Slides

Too

muc

hge

neric

ity...

(Exa

mpl

e1)

.

Page 20: CImg Slides

Too

muc

hge

neric

ity...

(Exa

mpl

e2)

.

•S

tric

tlysp

eaki

ng,t

his

ism

ore

C+

+st

uffs

(pro

blem

s?)

than

imag

epr

oces

sing

.

⇒D

efini

tely

nots

uita

ble

for

non

com

pute

rge

eks

!!

Page 21: CImg Slides

The

CIm

gLi

brar

y

•A

nop

en-s

ourc

eC

++

libra

ryai

min

gto

sim

plify

the

deve

lopm

ent

ofim

age

proc

essi

ngal

gorit

hms

for

gene

ric(e

noug

h)da

tase

ts(C

eCIL

LLi

cens

e).

Page 22: CImg Slides

The

CIm

gLi

brar

y

•A

nop

en-s

ourc

eC

++

libra

ryai

min

gto

sim

plify

the

deve

lopm

ent

ofim

age

proc

essi

ngal

gorit

hms

for

gene

ric(e

noug

h)da

tase

ts(C

eCIL

LLi

cens

e).

•P

rimar

yau

dien

ce:

Stu

dent

san

dre

sear

cher

sw

orki

ngin

Com

pute

rV

isio

nan

dIm

age

Pro

cess

ing

labs

,and

havi

ngst

anda

rdno

tions

ofC

++

.

Page 23: CImg Slides

The

CIm

gLi

brar

y

•A

nop

en-s

ourc

eC

++

libra

ryai

min

gto

sim

plify

the

deve

lopm

ent

ofim

age

proc

essi

ngal

gorit

hms

for

gene

ric(e

noug

h)da

tase

ts(C

eCIL

LLi

cens

e).

•P

rimar

yau

dien

ce:

Stu

dent

san

dre

sear

cher

sw

orki

ngin

Com

pute

rV

isio

nan

dIm

age

Pro

cess

ing

labs

,and

havi

ngst

anda

rdno

tions

ofC

++

.

•It

defin

esa

seto

fC+

+cl

asse

sab

leto

man

ipul

ate

and

proc

ess

imag

eob

ject

s.

Page 24: CImg Slides

The

CIm

gLi

brar

y

•A

nop

en-s

ourc

eC

++

libra

ryai

min

gto

sim

plify

the

deve

lopm

ent

ofim

age

proc

essi

ngal

gorit

hms

for

gene

ric(e

noug

h)da

tase

ts(C

eCIL

LLi

cens

e).

•P

rimar

yau

dien

ce:

Stu

dent

san

dre

sear

cher

sw

orki

ngin

Com

pute

rV

isio

nan

dIm

age

Pro

cess

ing

labs

,and

havi

ngst

anda

rdno

tions

ofC

++

.

•It

defin

esa

seto

fC+

+cl

asse

sab

leto

man

ipul

ate

and

proc

ess

imag

eob

ject

s.

•S

tart

edin

2000

,the

proj

ecti

sno

who

sted

onS

ourc

efor

gesi

nce

Dec

embe

r20

03:

http:// img.sour eforge.net/

Page 25: CImg Slides

Out

line

-PA

RT

IofI

I:C

Img

Libr

ary

Ove

rvie

w

•C

onte

xt:

Imag

eP

roce

ssin

gw

ithC

++

.

•A

iman

dta

rget

edau

dien

ce.

⇒W

hyco

nsid

erin

gT

heC

Img

Libr

ary

?

•C

Img<

T>

:A

clas

sfo

rim

age

man

ipul

atio

n.

•Im

age

cons

truc

tion,

data

acce

ss,m

ath

oper

ator

s.

•B

asic

imag

etr

ansf

orm

atio

ns.

•D

raw

ing

thin

gson

imag

es.

•C

ImgL

ist<

T>

:Im

age

colle

ctio

nm

anip

ulat

ion.

•B

asic

man

ipul

atio

nfu

nctio

ns.

•C

ImgD

ispl

ay:

Imag

edi

spla

yan

dus

erin

tera

ctio

n.

•D

ispl

ayin

gim

ages

inw

indo

ws.

Page 26: CImg Slides

Mai

nch

arac

teris

tics

CIm

gis

light

wei

ght

:

•To

tals

ize

ofth

efu

llC

Img

(.zi

p)pa

ckag

e:

appr

ox.

4.2

Mb.

Page 27: CImg Slides

Mai

nch

arac

teris

tics

CIm

gis

light

wei

ght

:

•To

tals

ize

ofth

efu

llC

Img

(.zi

p)pa

ckag

e:

appr

ox.

4.2

Mb.

•A

llth

elib

rary

isco

ntai

ned

ina

sing

lehe

ader

file

CIm

g.h

,tha

tmus

tbe

incl

uded

inyo

urC

++

sour

ce:

#in ludeCImg.h//Justdothat...

usingnamespa e img library;//...andyou anplaywiththelibrary

Page 28: CImg Slides

Mai

nch

arac

teris

tics

CIm

gis

light

wei

ght

:

•To

tals

ize

ofth

efu

llC

Img

(.zi

p)pa

ckag

e:

appr

ox.

4.2

Mb.

•A

llth

elib

rary

isco

ntai

ned

ina

sing

lehe

ader

file

CIm

g.h

,tha

tmus

tbe

incl

uded

inyo

urC

++

sour

ce:

#in ludeCImg.h//Justdothat...

usingnamespa e img library;//...andyou anplaywiththelibrary

•T

helib

rary

itsel

fonl

yta

kes

1.2M

bof

sour

ces

(app

roxi

mat

ely

2300

0lin

es).

•T

helib

rary

pack

age

cont

ains

the

file

CIm

g.h

asw

ella

sdo

cum

enta

tion,

exam

ples

ofus

e,an

dad

ditio

nalp

lug-

ins.

Page 29: CImg Slides

Mai

nch

arac

teris

tics

CIm

gis

light

wei

ght

:

•W

hat?

alib

rary

defin

edin

asi

ngle

head

erfil

e?

–S

impl

icity

“ala

ST

L”.

Page 30: CImg Slides

Mai

nch

arac

teris

tics

CIm

gis

light

wei

ght

:

•W

hat?

alib

rary

defin

edin

asi

ngle

head

erfil

e?

–S

impl

icity

“ala

ST

L”.

–U

sed

tem

plat

efu

nctio

nsan

dst

ruct

ures

know

thei

rty

peon

lydu

ring

the

com

pila

tion

phas

e:

⇒N

ore

leva

nce

inha

ving

pre-

com

pile

dob

ject

s(.

cpp→

.o).

Page 31: CImg Slides

Mai

nch

arac

teris

tics

CIm

gis

light

wei

ght

:

•W

hat?

alib

rary

defin

edin

asi

ngle

head

erfil

e?

–S

impl

icity

“ala

ST

L”.

–U

sed

tem

plat

efu

nctio

nsan

dst

ruct

ures

know

thei

rty

peon

lydu

ring

the

com

pila

tion

phas

e:

⇒N

ore

leva

nce

inha

ving

pre-

com

pile

dob

ject

s(.

cpp→

.o).

–W

hyno

tsev

eral

head

ers

(one

for

each

clas

s)?

⇒In

terd

epen

denc

eof

the

clas

ses

:al

lhea

ders

wou

ldbe

alw

ays

nece

ssar

y.

Page 32: CImg Slides

Mai

nch

arac

teris

tics

CIm

gis

light

wei

ght

:

•W

hat?

alib

rary

defin

edin

asi

ngle

head

erfil

e?

–S

impl

icity

“ala

ST

L”.

–U

sed

tem

plat

efu

nctio

nsan

dst

ruct

ures

know

thei

rty

peon

lydu

ring

the

com

pila

tion

phas

e:

⇒N

ore

leva

nce

inha

ving

pre-

com

pile

dob

ject

s(.

cpp→

.o).

–W

hyno

tsev

eral

head

ers

(one

for

each

clas

s)?

⇒In

terd

epen

denc

eof

the

clas

ses

:al

lhea

ders

wou

ldbe

alw

ays

nece

ssar

y.

–O

nly

used

func

tions

are

actu

ally

com

pile

d:

⇒S

mal

lgen

erat

edex

ecut

able

s.

Page 33: CImg Slides

Mai

nch

arac

teris

tics

CIm

gis

light

wei

ght

:

•W

hat?

alib

rary

defin

edin

asi

ngle

head

erfil

e?

–S

impl

icity

“ala

ST

L”.

–U

sed

tem

plat

efu

nctio

nsan

dst

ruct

ures

know

thei

rty

peon

lydu

ring

the

com

pila

tion

phas

e:

⇒N

ore

leva

nce

inha

ving

pre-

com

pile

dob

ject

s(.

cpp→

.o).

–W

hyno

tsev

eral

head

ers

(one

for

each

clas

s)?

⇒In

terd

epen

denc

eof

the

clas

ses.

–O

nly

used

func

tions

are

actu

ally

com

pile

d:

⇒S

mal

lgen

erat

edex

ecut

able

s.

•D

raw

back

:C

ompi

latio

ntim

ean

dne

eded

mem

ory

impo

rtan

tw

hen

optim

izat

ion

flags

are

set.

Page 34: CImg Slides

Mai

nch

arac

teris

tics

CIm

gis

(suf

ficie

ntly

)ge

neric

:

•C

Img

impl

emen

tsst

atic

gene

ricity

byus

ing

the

C+

+te

mpl

ate

mec

hani

sm.

•O

nete

mpl

ate

para

met

eron

ly:

the

type

ofth

eim

age

pixe

l.

Page 35: CImg Slides

Mai

nch

arac

teris

tics

CIm

gis

(suf

ficie

ntly

)ge

neric

:

•C

Img

impl

emen

tsst

atic

gene

ricity

byus

ing

the

C+

+te

mpl

ate

mec

hani

sm.

•O

nete

mpl

ate

para

met

eron

ly:

the

type

ofth

eim

age

pixe

l.

•C

Img

defin

esan

imag

ecl

ass

that

can

hand

lehy

pers

pect

ral

volu

met

ric(i.

e4D

)im

ages

ofge

neric

pixe

ltyp

es.

Page 36: CImg Slides

Mai

nch

arac

teris

tics

CIm

gis

(suf

ficie

ntly

)ge

neric

:

•C

Img

impl

emen

tsst

atic

gene

ricity

byus

ing

the

C+

+te

mpl

ate

mec

hani

sm.

•O

nete

mpl

ate

para

met

eron

ly:

the

type

ofth

eim

age

pixe

l.

•C

Img

defin

esan

imag

ecl

ass

that

can

hand

lehy

pers

pect

ral

volu

met

ric(i.

e4D

)im

ages

ofge

neric

pixe

ltyp

es.

•C

Img

defin

esan

imag

elis

tcla

ssth

atca

nha

ndle

tem

pora

lim

age

sequ

ence

s.

Page 37: CImg Slides

Mai

nch

arac

teris

tics

CIm

gis

(suf

ficie

ntly

)ge

neric

:

•C

Img

impl

emen

tsst

atic

gene

ricity

byus

ing

the

C+

+te

mpl

ate

mec

hani

sm.

•O

nete

mpl

ate

para

met

eron

ly:

the

type

ofth

eim

age

pixe

l.

•C

Img

defin

esan

imag

ecl

ass

that

can

hand

lehy

pers

pect

ral

volu

met

ric(i.

e4D

)im

ages

ofge

neric

pixe

ltyp

es.

•C

Img

defin

esan

imag

elis

tcla

ssth

atca

nha

ndle

tem

pora

lim

age

sequ

ence

s.

•...

But

,C

Img

islim

ited

toim

ages

havi

nga

rect

angu

lar

grid

,an

dca

nnot

hand

leim

ages

havi

ngm

ore

than

4di

men

sion

s.

Page 38: CImg Slides

Mai

nch

arac

teris

tics

CIm

gis

(suf

ficie

ntly

)ge

neric

:

•C

Img

impl

emen

tsst

atic

gene

ricity

byus

ing

the

C+

+te

mpl

ate

mec

hani

sm.

•O

nete

mpl

ate

para

met

eron

ly:

the

type

ofth

eim

age

pixe

l.

•C

Img

defin

esan

imag

ecl

ass

that

can

hand

lehy

pers

pect

ral

volu

met

ric(i.

e4D

)im

ages

ofge

neric

pixe

ltyp

es.

•C

Img

defin

esan

imag

elis

tcla

ssth

atca

nha

ndle

tem

pora

lim

age

sequ

ence

s.

•...

But

,C

Img

islim

ited

toim

ages

havi

nga

rect

angu

lar

grid

,an

dca

nnot

hand

leim

ages

havi

ngm

ore

than

4di

men

sion

s.

⇒C

Img

cove

rsac

tual

ly99

%of

the

imag

ety

pes

foun

din

real

wor

ldap

plic

atio

ns.

Page 39: CImg Slides

Mai

nch

arac

teris

tics

CIm

gis

mul

ti-pl

atfo

rm:

•It

does

notd

epen

don

man

ylib

rarie

s.It

can

beco

mpi

led

only

with

exis

ting

syst

emlib

rarie

s.

Page 40: CImg Slides

Mai

nch

arac

teris

tics

CIm

gis

mul

ti-pl

atfo

rm:

•It

does

notd

epen

don

man

ylib

rarie

s.It

can

beco

mpi

led

only

with

exis

ting

syst

emlib

rarie

s.

•A

dvan

ced

tool

sor

libra

ries

may

beus

edby

CIm

g(I

mag

eMag

ick,

XM

edco

n,lib

png,

libjp

eg,l

ibtif

f,lib

fftw

3...)

,the

seto

ols

bein

gfr

eely

avai

labl

efo

ran

ypl

atfo

rm.

Page 41: CImg Slides

Mai

nch

arac

teris

tics

CIm

gis

mul

ti-pl

atfo

rm:

•It

does

notd

epen

don

man

ylib

rarie

s.It

can

beco

mpi

led

only

with

exis

ting

syst

emlib

rarie

s.

•A

dvan

ced

tool

sor

libra

ries

may

beus

edby

CIm

g(I

mag

eMag

ick,

XM

edco

n,lib

png,

libjp

eg,l

ibtif

f,lib

fftw

3...)

,the

seto

ols

bein

gfr

eely

avai

labl

efo

ran

ypl

atfo

rm.

•S

ucce

ssfu

llyte

sted

plat

form

s:

Win

32,L

inux

,Sol

aris

,*B

SD

,Mac

OS

X.

•It

isal

so“m

ulti-

com

pile

r”:

g++

,V

C+

+6.

0,V

isua

lStu

dio

.NE

T,B

orla

ndB

cc5.

6,In

telI

CL,

Dev

-Cpp

.

Page 42: CImg Slides

Mai

nch

arac

teris

tics

And

mos

tofa

ll,...

.C

Img

isve

rysi

mpl

eto

use

:

•O

nly

1si

ngle

file

toin

clud

e.

Page 43: CImg Slides

Mai

nch

arac

teris

tics

And

mos

tofa

ll,...

.C

Img

isve

rysi

mpl

eto

use

:

•O

nly

1si

ngle

file

toin

clud

e.

•O

nly

4C

++

clas

ses

tokn

ow:

CImg<T>,CImgList<T>,CImgDisplay,CImgEx eption.

Page 44: CImg Slides

Mai

nch

arac

teris

tics

And

mos

tofa

ll,...

.C

Img

isve

rysi

mpl

eto

use

:

•O

nly

1si

ngle

file

toin

clud

e.

•O

nly

4C

++

clas

ses

tokn

ow:

CImg<T>,CImgList<T>,CImgDisplay,CImgEx eption.

•V

ery

basi

clo

w-le

vela

rchi

tect

ure,

sim

ple

toap

preh

end

(and

toha

ckif

nece

ssar

y!).

Page 45: CImg Slides

Mai

nch

arac

teris

tics

And

mos

tofa

ll,...

.C

Img

isve

rysi

mpl

eto

use

:

•O

nly

1si

ngle

file

toin

clud

e.

•O

nly

4C

++

clas

ses

tokn

ow:

CImg<T>,CImgList<T>,CImgDisplay,CImgEx eption.

•V

ery

basi

clo

w-le

vela

rchi

tect

ure,

sim

ple

toap

preh

end

(and

toha

ckif

nece

ssar

y!).

•E

noug

hge

neric

ityan

dlib

rary

func

tions

,allo

win

gco

mpl

exim

age

proc

essi

ngta

sks.

Page 46: CImg Slides

Mai

nch

arac

teris

tics

And

mos

tofa

ll,...

.C

Img

isve

rysi

mpl

eto

use

:

•O

nly

1si

ngle

file

toin

clud

e.

•O

nly

4C

++

clas

ses

tokn

ow:

CImg<T>,CImgList<T>,CImgDisplay,CImgEx eption.

•V

ery

basi

clo

w-le

vela

rchi

tect

ure,

sim

ple

toap

preh

end

(and

toha

ckif

nece

ssar

y!).

•E

noug

hge

neric

ityan

dlib

rary

func

tions

,allo

win

gco

mpl

exim

age

proc

essi

ngta

sks.

....

and

exte

nsib

le:

•S

impl

epl

ug-in

mec

hani

smto

easi

lyad

dyo

urow

nfu

nctio

nsto

the

libra

ryco

re(w

ithou

tmod

ifyin

gth

efil

eCImg.h

ofco

urse

).

Page 47: CImg Slides

Hel

loW

orld

step

byst

ep

#in lude"CImg.h"

usingnamespa e img_library;

intmain(intarg , har**argv)

return0;

Page 48: CImg Slides

Hel

loW

orld

step

byst

ep

#in lude"CImg.h"

usingnamespa e img_library;

intmain(intarg , har**argv)

CImg<unsigned har>img(300,200,1,3);

return0;

Page 49: CImg Slides

Hel

loW

orld

step

byst

ep

#in lude"CImg.h"

usingnamespa e img_library;

intmain(intarg , har**argv)

CImg<unsigned har>img(300,200,1,3);

img.fill(32);

return0;

Page 50: CImg Slides

Hel

loW

orld

step

byst

ep

#in lude"CImg.h"

usingnamespa e img_library;

intmain(intarg , har**argv)

CImg<unsigned har>img(300,200,1,3);

img.fill(32);

img.noise(128);

return0;

Page 51: CImg Slides

Hel

loW

orld

step

byst

ep

#in lude"CImg.h"

usingnamespa e img_library;

intmain(intarg , har**argv)

CImg<unsigned har>img(300,200,1,3);

img.fill(32);

img.noise(128);

img.blur(2,0,0);

return0;

Page 52: CImg Slides

Hel

loW

orld

step

byst

ep

#in lude"CImg.h"

usingnamespa e img_library;

intmain(intarg , har**argv)

CImg<unsigned har>img(300,200,1,3);

img.fill(32);

img.noise(128);

img.blur(2,0,0);

onstunsigned harwhite[=255,255,255;

img.draw_text("HelloWorld",80,80,white,0,32);

return0;

Page 53: CImg Slides

Hel

loW

orld

step

byst

ep

#in lude"CImg.h"

usingnamespa e img_library;

intmain(intarg , har**argv)

CImg<unsigned har>img(300,200,1,3);

img.fill(32);

img.noise(128);

img.blur(2,0,0);

onstunsigned harwhite[=255,255,255;

img.draw_text("HelloWorld",80,80,white,0,32);

img.display();

return0;

Page 54: CImg Slides

Hel

loW

orld

step

byst

ep

Page 55: CImg Slides

Hel

loW

orld

step

byst

ep:

anim

ated

#in lude"CImg.h"

usingnamespa e img_library;

intmain(intarg , har**argv)

onstCImg<unsigned har>img=

CImg<unsigned har>(300,200,1,3).fill(32).noise(128).blur(2,0,0).

draw_text("HelloWorld",80,80,CImg<unsigned har>::ve tor(255,255,255).ptr(),0,32);

CImgDisplaydisp(img,"MovingHelloWorld",0);

for(floatt=0;!disp.is_ losed;t+=0.04)

CImg<unsigned har>res(img);

img_forYV(res,y,v)

res.get_shared_line(y,0,v).translate((int)(40*std::sin(t+y/50.0)),0,0,0,2);

disp.display(res).wait(20);

if(disp.is_resized)disp.resize();

return0;

Page 56: CImg Slides

Ano

ther

exam

ple

:C

ompu

ting

grad

ient

norm

ofa

3Dvo

lum

etric

imag

e

•Le

tI:Ω

∈R

3→

R,c

ompu

te

∀p∈

Ω,

‖∇I‖ (

p)=

(

∂I

∂x

)

2

+

(

∂I

∂y

)

2

+

(

∂I

∂z

)

2

•C

ode

:

#in lude``CImg.h''

usingnamespa e img_library;

intmain(intarg , har**argv)

onstCImg<float>img(``brain_irm3d.hdr'');

onstCImgList<float>grad=img.get_gradientXYZ();

CImg<float>norm=(grad[0.pow(2)+grad[1.pow(2)+grad[2.pow(2));

norm.sqrt().get_normalize(0,255).save(``brain_gradient3d.hdr'');

return0;

Page 57: CImg Slides

Ano

ther

exam

ple

:C

ompu

ting

grad

ient

norm

ofa

3Dvo

lum

etric

imag

e

Page 58: CImg Slides

Live

Dem

o!

•Le

tsee

wha

twe

can

dow

ithth

islib

rary

.

Page 59: CImg Slides

Ove

rall

Libr

ary

Str

uctu

re

•T

hew

hole

libra

rycl

asse

san

dfu

nctio

nsar

ede

fined

inth

e

imglibrary::

nam

espa

ce.

Page 60: CImg Slides

Ove

rall

Libr

ary

Str

uctu

re

•T

hew

hole

libra

rycl

asse

san

dfu

nctio

nsar

ede

fined

inth

e

imglibrary::

nam

espa

ce.

•T

helib

rary

isco

mpo

sed

ofon

lyfo

urC

++

clas

ses

:

–C

Img<

T>

,rep

rese

nts

anim

age

with

pixe

lsof

type

T.

Page 61: CImg Slides

Ove

rall

Libr

ary

Str

uctu

re

•T

hew

hole

libra

rycl

asse

san

dfu

nctio

nsar

ede

fined

inth

e

imglibrary::

nam

espa

ce.

•T

helib

rary

isco

mpo

sed

ofon

lyfo

urC

++

clas

ses

:

–C

Img<

T>

,rep

rese

nts

anim

age

with

pixe

lsof

type

T.–

CIm

gLis

t<T

>,r

epre

sent

sa

listo

fim

ages

CImg<T>.

Page 62: CImg Slides

Ove

rall

Libr

ary

Str

uctu

re

•T

hew

hole

libra

rycl

asse

san

dfu

nctio

nsar

ede

fined

inth

e

imglibrary::

nam

espa

ce.

•T

helib

rary

isco

mpo

sed

ofon

lyfo

urC

++

clas

ses

:

–C

Img<

T>

,rep

rese

nts

anim

age

with

pixe

lsof

type

T.–

CIm

gLis

t<T

>,r

epre

sent

sa

listo

fim

ages

CImg<T>.

–C

ImgD

ispl

ay,r

epre

sent

sa

disp

lay

win

dow

.

Page 63: CImg Slides

Ove

rall

Libr

ary

Str

uctu

re

•T

hew

hole

libra

rycl

asse

san

dfu

nctio

nsar

ede

fined

inth

e

imglibrary::

nam

espa

ce.

•T

helib

rary

isco

mpo

sed

ofon

lyfo

urC

++

clas

ses

:

–C

Img<

T>

,rep

rese

nts

anim

age

with

pixe

lsof

type

T.–

CIm

gLis

t<T

>,r

epre

sent

sa

listo

fim

ages

CImg<T>.

–C

ImgD

ispl

ay,r

epre

sent

sa

disp

lay

win

dow

.–

CIm

gExc

eptio

n,us

edto

thro

wlib

rary

exce

ptio

ns.

Page 64: CImg Slides

Ove

rall

Libr

ary

Str

uctu

re

•T

hew

hole

libra

rycl

asse

san

dfu

nctio

nsar

ede

fined

inth

e

imglibrary::

nam

espa

ce.

•T

helib

rary

isco

mpo

sed

ofon

lyfo

urC

++

clas

ses

:

–C

Img<

T>

,rep

rese

nts

anim

age

with

pixe

lsof

type

T.–

CIm

gLis

t<T

>,r

epre

sent

sa

listo

fim

ages

CImg<T>.

–C

ImgD

ispl

ay,r

epre

sent

sa

disp

lay

win

dow

.–

CIm

gExc

eptio

n,us

edto

thro

wlib

rary

exce

ptio

ns.

•A

sub-

nam

espa

ce

imglibrary:: img::defi

nes

som

elo

w-le

vell

ibra

ryfu

nctio

ns(in

clud

ing

som

eus

eful

ones

as

rand(),grand(),min<T>(),max<T>(),abs<T>(),sleep(),

etc.

..).

Page 65: CImg Slides

Ove

rall

Libr

ary

Str

uctu

re

Low

−le

vel f

unct

ions

Imag

eIm

age

List

Dis

play

Win

dow

cim

g_lib

rary

::

cim

g::

CIm

g<T

>C

ImgL

ist<

T>

CIm

gDis

play

CIm

gExc

eptio

nE

rror

han

dlin

g

Page 66: CImg Slides

CIm

gm

etho

ds

•A

llC

Img

clas

ses

inco

rpor

ate

two

diffe

rent

kind

sof

met

hods

:

–M

etho

dsw

hich

actd

irect

lyon

the

inst

ance

obje

ctan

dm

odify

it.T

hese

met

hods

retu

rns

are

fere

nce

toth

ecu

rren

tins

tanc

e,so

that

writ

ting

func

tion

pipe

lines

ispo

ssib

le:

CImg<>(``toto.jpg'').blur(2).mirror('y').rotate(45).save(``tutu.jpg'');

Page 67: CImg Slides

CIm

gm

etho

ds

•A

llC

Img

clas

ses

inco

rpor

ate

two

diffe

rent

kind

sof

met

hods

:

–M

etho

dsw

hich

actd

irect

lyon

the

inst

ance

obje

ctan

dm

odify

it.T

hese

met

hods

retu

rns

are

fere

nce

toth

ecu

rren

tins

tanc

e,so

that

writ

ting

func

tion

pipe

lines

ispo

ssib

le:

CImg<>(``toto.jpg'').blur(2).mirror('y').rotate(45).save(``tutu.jpg'');

–O

ther

met

hods

retu

rna

mod

ified

copy

ofth

ein

stan

ce.

The

sem

etho

dsst

art

with

get_*():

CImg<>img(``toto.jpg'');

CImg<>img2=img.get_blur(2);//'img'isnotmodified

CImg<>img3=img.get_rotate(20).blur(3);//'img'isnotmodified

Page 68: CImg Slides

CIm

gm

etho

ds

•A

llC

Img

clas

ses

inco

rpor

ate

two

diffe

rent

kind

sof

met

hods

:

–M

etho

dsw

hich

actd

irect

lyon

the

inst

ance

obje

ctan

dm

odify

it.T

hese

met

hods

retu

rns

are

fere

nce

toth

ecu

rren

tins

tanc

e,so

that

writ

ting

func

tion

pipe

lines

ispo

ssib

le:

CImg<>(``toto.jpg'').blur(2).mirror('y').rotate(45).save(``tutu.jpg'');

–O

ther

met

hods

retu

rna

mod

ified

copy

ofth

ein

stan

ce.

The

sem

etho

dsst

art

with

get_*():

CImg<>img(``toto.jpg'');

CImg<>img2=img.get_blur(2);//'img'isnotmodified

CImg<>img3=img.get_rotate(20).blur(3);//'img'isnotmodified

⇒A

lmos

tall

CIm

gm

etho

dsar

ede

clin

edin

toth

ese

two

vers

ions

.

Page 69: CImg Slides

Out

line

-PA

RT

IofI

I:C

Img

Libr

ary

Ove

rvie

w

•C

onte

xt:

Imag

eP

roce

ssin

gw

ithC

++

.

•A

iman

dta

rget

edau

dien

ce.

•W

hyco

nsid

erin

gT

heC

Img

Libr

ary

?

⇒C

Img<

T>

:A

clas

sfo

rim

age

man

ipul

atio

n.

•Im

age

cons

truc

tion,

data

acce

ss,m

ath

oper

ator

s.

•B

asic

imag

etr

ansf

orm

atio

ns.

•D

raw

ing

thin

gson

imag

es.

•C

ImgL

ist<

T>

:Im

age

colle

ctio

nm

anip

ulat

ion.

•B

asic

man

ipul

atio

nfu

nctio

ns.

•C

ImgD

ispl

ay:

Imag

edi

spla

yan

dus

erin

tera

ctio

n.

•D

ispl

ayin

gim

ages

inw

indo

ws.

Page 70: CImg Slides

CIm

g<T

>:

Ove

rvie

w

•T

his

isth

em

ain

clas

sof

the

CIm

gLi

brar

y.It

has

asi

ngle

tem

plat

epa

ram

eter

T.•

A

CImg<T>repre

sent

san

imag

ew

ithpi

xels

ofty

pe

T(defaul

tte

mpl

ate

para

met

eris

T=float).Sup

port

edty

pes

are

the

C/C

++

basi

cty

pes

:

bool,unsigned har,

har,unsignedshort,short,unsignedint,int,float,double

,...

Page 71: CImg Slides

CIm

g<T

>:

Ove

rvie

w

•T

his

isth

em

ain

clas

sof

the

CIm

gLi

brar

y.It

has

asi

ngle

tem

plat

epa

ram

eter

T.•

A

CImg<T>repre

sent

san

imag

ew

ithpi

xels

ofty

pe

T(defaul

tte

mpl

ate

para

met

eris

T=float).Sup

port

edty

pes

are

the

C/C

++

basi

cty

pes

:

bool,unsigned har,

har,unsignedshort,short,unsignedint,int,float,double

,...

•A

nim

age

has

alw

ays

3sp

atia

ldim

ensi

ons

(width,height,depth

)+1

hype

rspe

ctra

ldi

men

sion

(dim):It

can

repr

esen

tany

data

from

asc

alar

1Dsi

gnal

toa

3Dvo

lum

eof

vect

or-v

alue

dpi

xels

.

Page 72: CImg Slides

CIm

g<T

>:

Ove

rvie

w

•T

his

isth

em

ain

clas

sof

the

CIm

gLi

brar

y.It

has

asi

ngle

tem

plat

epa

ram

eter

T.•

A

CImg<T>repre

sent

san

imag

ew

ithpi

xels

ofty

pe

T(defaul

tte

mpl

ate

para

met

eris

T=float).Sup

port

edty

pes

are

the

C/C

++

basi

cty

pes

:

bool,unsigned har,

har,unsignedshort,short,unsignedint,int,float,double

,...

•A

nim

age

has

alw

ays

3sp

atia

ldim

ensi

ons

(width,height,depth

)+1

hype

rspe

ctra

ldi

men

sion

(dim):It

can

repr

esen

tany

data

from

asc

alar

1Dsi

gnal

toa

3Dvo

lum

eof

vect

or-v

alue

dpi

xels

.

•Im

age

proc

essi

ngal

gorit

hms

are

met

hods

of

CImg<T>(6=S

TL

):

blur(),resize(), onvolve(),erode(),load(),save()....

•M

etho

dim

plem

enta

tion

aim

sto

hand

leth

em

ost

gene

ral

case

(3D

volu

met

richy

pers

pect

rali

mag

es).

Page 73: CImg Slides

CIm

g<T

>:

Low

-leve

lArc

hite

ctur

e(fo

rha

cker

s!)

•T

hest

ruct

ure

CImg<T>isdefi

ned

as:

template<typenameT>stru tCImg

unsignedintwidth;

unsignedintheight;

unsignedintdepth;

unsignedintdim;

T*data;

;

Page 74: CImg Slides

CIm

g<T

>:

Low

-leve

lArc

hite

ctur

e(fo

rha

cker

s!)

•T

hest

ruct

ure

CImg<T>isdefi

ned

as:

template<typenameT>stru tCImg

unsignedintwidth;

unsignedintheight;

unsignedintdepth;

unsignedintdim;

T*data;

;

•A

CImg<T>imag

eis

alw

ays

entir

ely

stor

edin

mem

ory.

•A

CImg<T>isind

epen

dent

:it

has

itsow

npi

xelb

uffe

r.

Page 75: CImg Slides

CIm

g<T

>:

Low

-leve

lArc

hite

ctur

e(fo

rha

cker

s!)

•T

hest

ruct

ure

CImg<T>isdefi

ned

as:

template<typenameT>stru tCImg

unsignedintwidth;

unsignedintheight;

unsignedintdepth;

unsignedintdim;

T*data;

;

•A

CImg<T>imag

eis

alw

ays

entir

ely

stor

edin

mem

ory.

•A

CImg<T>isind

epen

dent

:it

has

itsow

npi

xelb

uffe

r.

•C

Img

mem

ber

func

tions

(des

truc

tor,

cons

truc

tors

,op

erat

ors,

...)

hand

lem

emor

yal

loca

tion/

desa

lloca

tion

effic

ient

ly.

Page 76: CImg Slides

CIm

g<T

>:

Mem

ory

layo

ut(fo

rha

cker

s!)

template<typenameT>stru tCImg

unsignedintwidth;

unsignedintheight;

unsignedintdepth;

unsignedintdim;

T*data;

; •P

ixel

valu

esar

eno

tsto

red

ina

typi

cal“

RG

BR

GB

RG

BR

GB

RG

B”

orde

r.

•P

ixel

valu

esar

est

ored

first

alon

gth

eX

-axi

s,th

enth

eY-

axis

,the

nth

eZ

-axi

s,th

enth

eV

-axi

s:

R(0

,0)

R(1

,0)

...R

(W-1

,0)

...R

(0,1

)R

(1,1

)...

R(W

-1,1

)...

.R

(0,H

-1)

R(1

,H-1

)...

R(W

-1,H

-1)

...G

(0,0

)...

G(W

-1,H

-1)

...B

(0,0

)...

B(W

-1,H

-1).

Page 77: CImg Slides

Out

line

-PA

RT

IofI

I:C

Img

Libr

ary

Ove

rvie

w

•C

onte

xt:

Imag

eP

roce

ssin

gw

ithC

++

.

•A

iman

dta

rget

edau

dien

ce.

•W

hyco

nsid

erin

gT

heC

Img

Libr

ary

?

•C

Img<

T>

:A

clas

sfo

rim

age

man

ipul

atio

n.

⇒Im

age

cons

truc

tion,

data

acce

ss,m

ath

oper

ator

s.

•B

asic

imag

etr

ansf

orm

atio

ns.

•D

raw

ing

thin

gson

imag

es.

•C

ImgL

ist<

T>

:Im

age

colle

ctio

nm

anip

ulat

ion.

•B

asic

man

ipul

atio

nfu

nctio

ns.

•C

ImgD

ispl

ay:

Imag

edi

spla

yan

dus

erin

tera

ctio

n.

•D

ispl

ayin

gim

ages

inw

indo

ws.

Page 78: CImg Slides

CIm

g<T

>:

Con

stru

ctor

s(1

)

•D

efau

ltco

nstr

ucto

r,co

nstr

ucts

anem

pty

imag

e.

CImg<T>();

•N

om

emor

yal

loca

ted

inth

isca

se,i

mag

esdi

men

sion

sar

eze

ro.

•U

sefu

lto

decl

are

anim

age

with

outa

lloca

ting

itspi

xelv

alue

s.

#in lude``CImg.h''

usingnamespa e img_library;

intmain() CImg<u

nsigned har>img_8bits;

CImg<unsignedshort>img_16bits;

CImg<float>img_float;

return0;

Page 79: CImg Slides

CIm

g<T

>:

Con

stru

ctor

s(2

)

•C

onst

ruct

sa

4Dim

age

with

spec

ified

dim

ensi

ons.

Om

itted

dim

ensi

ons

are

set

to1

(def

ault

para

met

er).

CImg<T>(unsignedint,unsignedint,unsignedint,unsignedint);

#in lude``CImg.h''

usingnamespa e img_library;

intmain() CImg<fl

oat>img(100,100);//2Ds alarimage.

CImg<unsigned har>img2(256,256,1,3);//2D olorimage.

CImg<bool>img3(128,128,128);//3Ds alarimage.

CImg<short>img4(64,64,32,16);//3Dhyperspe tralimage(16bands).

return0;

•N

oin

itial

izat

ion

ofpi

xelv

alue

sis

perf

orm

ed.

Can

bedo

new

ith:

CImg<T>(unsignedint,unsignedint,unsignedint,unsignedint, onstT&);

Page 80: CImg Slides

CIm

g<T

>:

Con

stru

ctor

s(3

)

•C

reat

ean

imag

eby

read

ing

anim

age

from

the

disk

(for

mat

dedu

ced

byth

efil

enam

eex

tens

ion)

.

CImg<T>( onst har*filename);

#in lude``CImg.h''

usingnamespa e img_library;

intmain() CImg<u

nsigned har>img(``nounours.jpg'');

CImg<unsignedshort>img2(``toto.png'');

CImg<float>img3(``toto.png'');

return0;

•P

ixel

data

ofth

efil

efo

rmat

are

conv

erte

d(s

tatic

cast

)to

the

spec

ified

tem

plat

epa

ram

eter

.

Page 81: CImg Slides

CIm

g<T

>:

In-p

lace

cons

truc

tors

CImg<T>&assign(...)

Eac

hco

nstr

ucto

rha

san

in-p

lace

vers

ion

with

sam

epa

ram

eter

s.

CImg<float>img;

img.assign(``toto.jpg'');

img.assign(256,256,1,3,0);

img.assign();

•T

his

prin

cipl

eis

exte

nded

toth

eot

her

CIm

gcl

asse

s.

CImgList<float>list;

list.assign(img1,img2,img3);

CImgDisplaydisp;

disp.assign(list,''Listdisplay'');

Page 82: CImg Slides

CIm

g<T

>:

Acc

ess

toim

age

data

info

rmat

ions

•G

etth

edi

men

sion

alon

gth

eX

,Y,Z

orV

-axi

s(w

idth

,hei

ght,

dept

hor

chan

nels

).

intdimx() onst;

intW=img.dimx(),H=img.dimy(),D=img.dimz(),V=img.dimv();

Page 83: CImg Slides

CIm

g<T

>:

Acc

ess

toim

age

data

info

rmat

ions

•G

etth

edi

men

sion

alon

gth

eX

,Y,Z

orV

-axi

s(w

idth

,hei

ght,

dept

hor

chan

nels

).

intdimx() onst;

intW=img.dimx(),H=img.dimy(),D=img.dimz(),V=img.dimv();

•G

etth

epi

xelv

alue

atsp

ecifi

edco

ordi

nate

s.O

mite

dco

ordi

nate

sar

ese

tto

0.

T&operator()(unsignedint,unsignedint,unsignedint,unsignedint);

unsigned harR=img(x,y),G=img(x,y,0,1),B=img(x,y,2);

floatval=volume(x,y,z,v);

img(x,y,z)=x*y;

(Out

-of-

boun

dsco

ordi

nate

sar

eno

tche

cked

!)

Page 84: CImg Slides

CIm

g<T

>:

Acc

ess

toim

age

data

info

rmat

ions

•G

etth

edi

men

sion

alon

gth

eX

,Y,Z

orV

-axi

s(W

idth

,Hei

ght,

Dep

thor

Cha

nnel

s).

intdimx() onst;

intW=img.dimx(),H=img.dimy(),D=img.dimz(),V=img.dimv();

•G

etth

epi

xelv

alue

atsp

ecifi

edco

ordi

nate

s.O

mite

dco

ordi

nate

sar

ese

tto

0.

T&operator()(unsignedint,unsignedint,unsignedint,unsignedint);

unsigned harR=img(x,y),G=img(x,y,0,1),B=img(x,y,2);

floatval=volume(x,y,z,v);

img(x,y,z)=x*y;

(Out

-of-

boun

dsco

ordi

nate

sar

eno

tche

cked

!)

•G

etth

epi

xelv

alue

atsp

ecifi

edsu

b-pi

xelp

ositi

on,u

sing

bicu

bic

inte

rpol

atio

n.O

ut-

of-b

ound

sco

ordi

nate

sar

ech

ecke

d.

float ubi pix2d(float,float,unsignedint,unsignedint);

floatval=img.get_ ubi _pix2d(x-0.5f,y-0.5f);

Page 85: CImg Slides

CIm

g<T

>:

Cop

ies

and

assi

gnm

ents

•C

onst

ruct

anim

age

byco

py.

Per

form

stat

icpi

xelt

ype

cast

ifne

eded

.

template<typenamet>CImg<T>( onstCImg<t>&img);

CImg<float>img_float(img_double);

Page 86: CImg Slides

CIm

g<T

>:

Cop

ies

and

assi

gnm

ents

•C

onst

ruct

anim

age

byco

py.

Per

form

stat

icpi

xelt

ype

cast

ifne

eded

.

template<typenamet>CImg<T>( onstCImg<t>&img);

CImg<float>img_float(img_double);

•A

ssig

nem

ento

pera

tor.

Rep

lace

the

inst

ance

imag

eby

aco

pyof

img.

template<typenamet>CImg<T>&operator=( onstCImg<t>&img);

CImg<float>img;

CImg<unsigned har>img2(``toto.jpg''),img3(256,256);

img=img2;

img=img3;

•M

odify

ing

aco

pydo

esno

tmod

ifyth

eor

igin

alim

age

(ow

npi

xelb

uffe

r).

Page 87: CImg Slides

CIm

g<T

>:

Mat

hop

erat

ors

and

func

tions

•M

osto

fthe

usua

lmat

hop

erat

ors

are

defin

ed:

+,-,*,/,+=,-=,...

CImg<float>img(``toto.jpg''),dest;

dest=(2*img+5);

dest+=img;

Page 88: CImg Slides

CIm

g<T

>:

Mat

hop

erat

ors

and

func

tions

•M

osto

fthe

usua

lmat

hop

erat

ors

are

defin

ed:

+,-,*,/,+=,-=,...

CImg<float>img(``toto.jpg''),dest;

dest=(2*img+5);

dest+=img;

•O

pera

tors

alw

ays

try

tore

turn

imag

esw

ithth

ebe

stda

taty

pe.

CImg<unsigned har>img(``toto.jpg'');

CImg<float>dest;

dest=img*0.1f;

img*=0.1f;

Page 89: CImg Slides

CIm

g<T

>:

Mat

hop

erat

ors

and

func

tions

•M

osto

fthe

usua

lmat

hop

erat

ors

are

defin

ed:

+,-,*,/,+=,-=,...

CImg<float>img(``toto.jpg''),dest;

dest=(2*img+5);

dest+=img;

•O

pera

tors

alw

ays

try

tore

turn

imag

esw

ithth

ebe

stda

taty

pe.

CImg<unsigned har>img(``toto.jpg'');

CImg<float>dest;

dest=img*0.1f;

img*=0.1f;

•U

sual

mat

hfu

nctio

nsar

eal

sode

fined

:

sqrt(), os(),pow()...

img.pow(2.5);

res=img.get_pow(2.5);

res=img.get_ os().pow(2.5);

Page 90: CImg Slides

CIm

g<T

>:

Mat

rices

oper

atio

ns

•T

he

*and/

oper

ator

sco

rres

pond

sto

am

atrix

prod

uct/d

ivis

ion

!

CImg<float>A(3,3),v(1,3);

CImg<float>res=A*v;

•U

se

CImg<T>::mul()and

CImg<T>::div()forp

oint

wis

eop

erat

ors.

Page 91: CImg Slides

CIm

g<T

>:

Mat

rices

oper

atio

ns

•T

he

*and/

oper

ator

sco

rres

pond

sto

am

atrix

prod

uct/d

ivis

ion

!

CImg<float>A(3,3),v(1,3);

CImg<float>res=A*v;

•U

se

CImg<T>::mul()and

CImg<T>::div()forp

oint

wis

eop

erat

ors.

•U

sual

mat

rixfu

nctio

nsan

dtr

ansf

orm

atio

nsar

eav

aila

ble

inC

Img

:de

term

inan

t,S

VD

,eig

enva

lue

deco

mpo

sitio

n,in

vers

e,...

CImg<float>A(10,10),v(1,10);

onstfloatdeterminant=A.det();

CImg<float>pseudo_inv=

((A*A.get_transpose()).inverse())*A.get_transpose();

CImg<float>pseudo_inv2=A.get_pseudoinverse();

Page 92: CImg Slides

CIm

g<T

>:

Mat

rices

oper

atio

ns

•T

he

*and/

oper

ator

sco

rres

pond

sto

am

atrix

prod

uct/d

ivis

ion

!

CImg<float>A(3,3),v(1,3);

CImg<float>res=A*v;

•U

se

CImg<T>::mul()and

CImg<T>::div()forp

oint

wis

eop

erat

ors.

•U

sual

mat

rixfu

nctio

nsan

dtr

ansf

orm

atio

nsar

eav

aila

ble

inC

Img

:de

term

inan

t,S

VD

,eig

enva

lue

deco

mpo

sitio

n,in

vers

e,...

CImg<float>A(10,10),v(1,10);

onstfloatdeterminant=A.det();

CImg<float>pseudo_inv=

((A*A.get_transpose()).inverse())*A.get_transpose();

CImg<float>pseudo_inv2=A.get_pseudoinverse();

•W

arni

ng:

Mat

rices

are

view

edas

imag

es,

sofir

stin

dice

isth

eco

lum

nnu

mbe

r,se

cond

isth

elin

enu

mbe

r:

Aij

=

A(j,i)

Page 93: CImg Slides

CIm

g<T

>:

Imag

ede

stru

ctio

n

•Im

age

dest

ruct

ion

isdo

nein

the

CImg()meth

od.

•U

sed

pixe

lbuf

fer

mem

ory

(ifan

y)is

auto

mat

ical

lyfr

eed

byth

ede

stru

ctor

.

•D

estr

ucto

ris

auto

mat

ical

lyca

lled

atth

een

dof

abl

ock.

•M

emor

yde

allo

catio

nca

nbe

forc

edby

the

assign()func

tion.

CImg<float>img(10000,10000);//Need4*10000^2bytes=380Mo

floatdet=img.det();

//Wewon'tuseimganymore...

img.assign();

//Equivalentto:

img=CImg<float>();

Page 94: CImg Slides

Out

line

-PA

RT

IofI

I:C

Img

Libr

ary

Ove

rvie

w

•C

onte

xt:

Imag

eP

roce

ssin

gw

ithC

++

.

•A

iman

dta

rget

edau

dien

ce.

•W

hyco

nsid

erin

gT

heC

Img

Libr

ary

?

•C

Img<

T>

:A

clas

sfo

rim

age

man

ipul

atio

n.

•Im

age

cons

truc

tion,

data

acce

ss,m

ath

oper

ator

s.

⇒B

asic

imag

etr

ansf

orm

atio

ns.

•D

raw

ing

thin

gson

imag

es.

•C

ImgL

ist<

T>

:Im

age

colle

ctio

nm

anip

ulat

ion.

•B

asic

man

ipul

atio

nfu

nctio

ns.

•C

ImgD

ispl

ay:

Imag

edi

spla

yan

dus

erin

tera

ctio

n.

•D

ispl

ayin

gim

ages

inw

indo

ws.

Page 95: CImg Slides

CIm

g<T

>:

Imag

em

anip

ulat

ion

fill()

:F

illan

imag

ew

ithon

eor

seve

ralv

alue

s.

CImg<>img(256,256),ve tor(1,6);

img.fill(0);

ve tor.fill(1,2,3,4,5,6);

•A

pply

basi

cgl

obal

tran

sfor

mat

ions

onpi

xelv

alue

s.

normalize(), ut(),quantize(),threshold().

CImg<float>

img(toto.jpg);

img.quantize(16);

img.normalize(0,1);

img. ut(0.2f,0.8f);

img.threshold(0.5f);

img.normalize(0,255);

Page 96: CImg Slides

CIm

g<T

>:

Imag

em

anip

ulat

ion

rotate():Ro

tate

anim

age

with

agi

ven

angl

e.

CImg<>img(``milla.png'');

img.rotate(30);

resize():Re

size

anim

age

with

agi

ven

size

.

CImg<>img(``mini.jpg'');

img.resize(-300,-300);//-300=300%

⇒B

orde

rco

nditi

ons

and

inte

rpol

atio

nty

pes

can

bech

osen

byth

eus

er.

Page 97: CImg Slides

CIm

g<T

>:

Imag

em

anip

ulat

ion

get rop():G

eta

sub−

imag

eof

the

inst

ance

imag

e.

CImg<>img(256,256);

img.get_ rop(0,0,128,128);//Gettheupper-lefthalfimage

•C

olor

spac

e-co

nver

sion

s:

RGBtoYUV(),RGBtoLUT(),RGBtoHSV(),...an

din

vers

etr

ansf

orm

atio

ns.

•F

ilter

ing

:

blur(), onvolve(),erode(),dilate(),FFT(),deri he(),....

•In

the

refe

renc

edo

cum

enta

tion,

func

tions

are

grou

ped

byth

emes

....

http:// img.sour eforge.net/referen e/

Page 98: CImg Slides

CIm

g<T

>:

Imag

em

anip

ulat

ion

#in lude``CImg.h''

usingnamespa e img_library;

intmain() CImg<un

signed har>img(``milla.jpg'');

img.blur(1). rop(15,52,150,188).dilate(10).mirror('x');

img.save(``result.png'');

return0;

Page 99: CImg Slides

Out

line

-PA

RT

IofI

I:C

Img

Libr

ary

Ove

rvie

w

•C

onte

xt:

Imag

eP

roce

ssin

gw

ithC

++

.

•A

iman

dta

rget

edau

dien

ce.

•W

hyco

nsid

erin

gT

heC

Img

Libr

ary

?

•C

Img<

T>

:A

clas

sfo

rim

age

man

ipul

atio

n.

•Im

age

cons

truc

tion,

data

acce

ss,m

ath

oper

ator

s.

•B

asic

imag

etr

ansf

orm

atio

ns.

⇒D

raw

ing

thin

gson

imag

es.

•C

ImgL

ist<

T>

:Im

age

colle

ctio

nm

anip

ulat

ion.

•B

asic

man

ipul

atio

nfu

nctio

ns.

•C

ImgD

ispl

ay:

Imag

edi

spla

yan

dus

erin

tera

ctio

n.

•D

ispl

ayin

gim

ages

inw

indo

ws.

Page 100: CImg Slides

CIm

g<T

>:

Dra

win

gfu

nctio

ns

•C

Img

prop

oses

alo

toff

unct

ions

todr

awfe

atur

esin

imag

es.

⇒P

oint

s,lin

es,c

ircle

s,re

ctan

gles

,tria

ngle

s,te

xt,v

ecto

rfie

lds,

3Dob

ject

s,...

•A

lldr

awin

gfu

nctio

nna

mes

begi

nw

ith

draw*().

•F

eatu

res

are

draw

ndi

rect

lyon

the

inst

ance

imag

e(s

oth

ere

are

not onst

).

Page 101: CImg Slides

CIm

g<T

>:

Dra

win

gfu

nctio

ns

•A

lldr

awin

gfu

nctio

nsw

ork

the

sam

ew

ay:

The

yne

edth

ein

stan

ceim

age,

feat

ure

coor

dina

tes ,

and

aco

lor

(eve

ntua

loth

erop

tiona

lpar

amet

ers

can

bese

t).

Page 102: CImg Slides

CIm

g<T

>:

Dra

win

gfu

nctio

ns

•A

lldr

awin

gfu

nctio

nsw

ork

the

sam

ew

ay:

The

yne

edth

ein

stan

ceim

age,

feat

ure

coor

dina

tes ,

and

aco

lor

(eve

ntua

loth

erop

tiona

lpar

amet

ers

can

bese

t).

•T

hey

retu

rna

refe

renc

eto

the

inst

ance

imag

e,so

they

can

bepi

pelin

ed.

Page 103: CImg Slides

CIm

g<T

>:

Dra

win

gfu

nctio

ns

•A

lldr

awin

gfu

nctio

nsw

ork

the

sam

ew

ay:

The

yne

edth

ein

stan

ceim

age,

feat

ure

coor

dina

tes ,

and

aco

lor

(eve

ntua

loth

erop

tiona

lpar

amet

ers

can

bese

t).

•T

hey

retu

rna

refe

renc

eto

the

inst

ance

imag

e,so

they

can

bepi

pelin

ed.

•T

hey

clip

obje

cts

that

are

outo

fim

age

boun

ds.

Page 104: CImg Slides

CIm

g<T

>:

Dra

win

gfu

nctio

ns

•A

lldr

awin

gfu

nctio

nsw

ork

the

sam

ew

ay:

The

yne

edth

ein

stan

ceim

age,

feat

ure

coor

dina

tes ,

and

aco

lor

(eve

ntua

loth

erop

tiona

lpar

amet

ers

can

bese

t).

•T

hey

retu

rna

refe

renc

eto

the

inst

ance

imag

e,so

they

can

bepi

pelin

ed.

•T

hey

clip

obje

cts

that

are

outo

fim

age

boun

ds.

•E

x:

CImg&drawline(int,int,int,int,T*);

CImg<unsignedshort>img(256,256,1,5);//hyperspe tralimageofushort

unsignedshort olor[5=0,8,16,24,32;// olorusedforthedrawing

img.draw_line(x-2,y-2,x+2,y+2, olor).

draw_line(x-2,y+2,x+2,y-2, olor).

draw_ ir le(x+10,y+10,5, olor);

Page 105: CImg Slides

CIm

g<T

>:

Dra

win

gfu

nctio

ns

•A

lldr

awin

gfu

nctio

nsw

ork

the

sam

ew

ay:

The

yne

edth

ein

stan

ceim

age,

feat

ure

coor

dina

tes ,

and

aco

lor

(eve

ntua

loth

erop

tiona

lpar

amet

ers

can

bese

t).

•T

hey

retu

rna

refe

renc

eto

the

inst

ance

imag

e,so

they

can

bepi

pelin

ed.

•T

hey

clip

obje

cts

that

are

outo

fim

age

boun

ds.

•E

x:

CImg&drawline(int,int,int,int,T*);

CImg<unsignedshort>img(256,256,1,5);//hyperspe tralimageofushort

unsignedshort olor[5=0,8,16,24,32;// olorusedforthedrawing

img.draw_line(x-2,y-2,x+2,y+2, olor).

draw_line(x-2,y+2,x+2,y-2, olor).

draw_ ir le(x+10,y+10,5, olor);

CImg<T>::drawobje t3d()

can

draw

3Dob

ject

s(m

iniO

pen-

GL!

)

Page 106: CImg Slides

CIm

g<T

>:

Pla

sma

ball

(sou

rce

code

)

•T

hefo

llow

ing

code

draw

sa

“pla

sma

ball”

from

scra

tch

:

CImg<unsigned har>img(512,512,1,3,0);

for(floatalpha=0,beta=0;beta<100;alpha+=0.21f,beta+=0.18f)

onstfloat a=s

td:: os(alpha), b=std:: os(beta),

sa=std::sin(alpha),sb=std::sin(beta);

img.draw_line(256+200* a*sa,256+200* b*sa,

256+200*sa*sb,256+200*sb* a,

CImg<unsigned har>::ve tor(alpha*256,beta*256,128).

ptr(),0.5f);

onstunsigned harwhite[3=255,255,255,blue[3=16,32,128;

img.draw_ ir le(256,256,200,white,1.0f,~0U).draw_fill(0,0,blue);

for(intradius=60;radius>0;--radius)

img.draw_ ir le(340,172,radius,white,0.02f);

Page 107: CImg Slides

CIm

g<T

>:

Pla

sma

ball

(res

ult)

Page 108: CImg Slides

Out

line

-PA

RT

IofI

I:C

Img

Libr

ary

Ove

rvie

w

•C

onte

xt:

Imag

eP

roce

ssin

gw

ithC

++

.

•A

iman

dta

rget

edau

dien

ce.

•W

hyco

nsid

erin

gT

heC

Img

Libr

ary

?

•C

Img<

T>

:A

clas

sfo

rim

age

man

ipul

atio

n.

•Im

age

cons

truc

tion,

data

acce

ss,m

ath

oper

ator

s.

•B

asic

imag

etr

ansf

orm

atio

ns.

•D

raw

ing

thin

gson

imag

es.

⇒C

ImgL

ist<

T>

:Im

age

colle

ctio

nm

anip

ulat

ion.

•B

asic

man

ipul

atio

nfu

nctio

ns.

•C

ImgD

ispl

ay:

Imag

edi

spla

yan

dus

erin

tera

ctio

n.

•D

ispl

ayin

gim

ages

inw

indo

ws.

Page 109: CImg Slides

CIm

gLis

t<T

>:

Ove

rvie

w

•A

CImgList<T>r

epre

sent

san

arra

yof

CImg<T>.

•U

sefu

lto

hand

lea

sequ

ence

ora

colle

ctio

nof

imag

es.

•H

ere

also

,the

mem

ory

isno

tsha

red

byot

her

CImgList<T>o

rCImg<T>objec

ts.

•Lo

oks

like

a

std::ve tor<CImg<T>>,sp

ecia

lized

for

imag

epr

oces

sing

.

•C

anbe

used

asa

flexi

ble

and

orde

red

seto

fim

ages

.

Page 110: CImg Slides

Out

line

-PA

RT

IofI

I:C

Img

Libr

ary

Ove

rvie

w

•C

onte

xt:

Imag

eP

roce

ssin

gw

ithC

++

.

•A

iman

dta

rget

edau

dien

ce.

•W

hyco

nsid

erin

gT

heC

Img

Libr

ary

?

•C

Img<

T>

:A

clas

sfo

rim

age

man

ipul

atio

n.

•Im

age

cons

truc

tion,

data

acce

ss,m

ath

oper

ator

s.

•B

asic

imag

etr

ansf

orm

atio

ns.

•D

raw

ing

thin

gson

imag

es.

•C

ImgL

ist<

T>

:Im

age

colle

ctio

nm

anip

ulat

ion.

⇒B

asic

man

ipul

atio

nfu

nctio

ns.

•C

ImgD

ispl

ay:

Imag

edi

spla

yan

dus

erin

tera

ctio

n.

•D

ispl

ayin

gim

ages

inw

indo

ws.

Page 111: CImg Slides

CIm

gLis

t<T

>:

Mai

nfu

nctio

ns

//Createalistof20 olorimages100x100.

CImgList<float>list(20,100,100,1,3);

//Inserttwoimagesattheendofthelist.

list.insert(CImg<float>(50,50));

list.insert(CImg<unsigned har>(``milla.ppm''));

//Removethese ondimagefromthelist.

list.remove(1);

//Resizethe5thimageofthelist.

CImg<float>&ref=list[4;

ref.resize(50,50);

•Li

sts

can

besa

ved

(and

load

ed)

as.c

img

files

(sim

ple

bina

ryfo

rmat

with

asci

ihe

ader

).

Page 112: CImg Slides

CIm

gLis

t<T

>:

. imgfile

s

•F

unct

ions

CImgList<T>::load img()

and

CImgList<T>::save img()

allo

wto

load

/sav

epo

rtio

nsof

. imgim

age

files

.

•S

ingl

eim

ages

(CImg<T> lass)can

beal

solo

aded

/sav

edin

to. imgfi

les.

•U

sefu

lto

wor

kw

ithbi

gim

age

files

,vid

eose

quen

ces

orim

age

colle

ctio

ns.

Page 113: CImg Slides

Out

line

-PA

RT

IofI

I:C

Img

Libr

ary

Ove

rvie

w

•C

onte

xt:

Imag

eP

roce

ssin

gw

ithC

++

.

•A

iman

dta

rget

edau

dien

ce.

•W

hyco

nsid

erin

gT

heC

Img

Libr

ary

?

•C

Img<

T>

:A

clas

sfo

rim

age

man

ipul

atio

n.

•Im

age

cons

truc

tion,

data

acce

ss,m

ath

oper

ator

s.

•B

asic

imag

etr

ansf

orm

atio

ns.

•D

raw

ing

thin

gson

imag

es.

•C

ImgL

ist<

T>

:Im

age

colle

ctio

nm

anip

ulat

ion.

•B

asic

man

ipul

atio

nfu

nctio

ns.

⇒C

ImgD

ispl

ay:

Imag

edi

spla

yan

dus

erin

tera

ctio

n.

•D

ispl

ayin

gim

ages

inw

indo

ws.

Page 114: CImg Slides

Out

line

-PA

RT

IofI

I:C

Img

Libr

ary

Ove

rvie

w

•C

onte

xt:

Imag

eP

roce

ssin

gw

ithC

++

.

•A

iman

dta

rget

edau

dien

ce.

•W

hyco

nsid

erin

gT

heC

Img

Libr

ary

?

•C

Img<

T>

:A

clas

sfo

rim

age

man

ipul

atio

n.

•Im

age

cons

truc

tion,

data

acce

ss,m

ath

oper

ator

s.

•B

asic

imag

etr

ansf

orm

atio

ns.

•D

raw

ing

thin

gson

imag

es.

•C

ImgL

ist<

T>

:Im

age

colle

ctio

nm

anip

ulat

ion.

•B

asic

man

ipul

atio

nfu

nctio

ns.

•C

ImgD

ispl

ay:

Imag

edi

spla

yan

dus

erin

tera

ctio

n.

⇒D

ispl

ayin

gim

ages

inw

indo

ws.

Page 115: CImg Slides

CIm

gDis

play

:O

verv

iew

•A

CImgDisplaya

llow

sto

disp

lay

CImg<T>orCImgl<T>

inst

ance

sin

aw

indo

w,

and

can

hand

leus

erev

ents

that

may

happ

enin

this

win

dow

(mou

se,k

eybo

ard,

...)

Page 116: CImg Slides

CIm

gDis

play

:O

verv

iew

•A

CImgDisplaya

llow

sto

disp

lay

CImg<T>orCImgl<T>

inst

ance

sin

aw

indo

w,

and

can

hand

leus

erev

ents

that

may

happ

enin

this

win

dow

(mou

se,k

eybo

ard,

...)

•T

heco

nstr

uctio

nof

a

CImgDisplayo

pens

aw

indo

w.

Page 117: CImg Slides

CIm

gDis

play

:O

verv

iew

•A

CImgDisplaya

llow

sto

disp

lay

CImg<T>orCImgl<T>

inst

ance

sin

aw

indo

w,

and

can

hand

leus

erev

ents

that

may

happ

enin

this

win

dow

(mou

se,k

eybo

ard,

...)

•T

heco

nstr

uctio

nof

a

CImgDisplayo

pens

aw

indo

w.

•T

hede

stru

ctio

nof

a

CImgDisplayc

lose

sth

eco

rres

pond

ing

win

dow

.

Page 118: CImg Slides

CIm

gDis

play

:O

verv

iew

•A

CImgDisplaya

llow

sto

disp

lay

CImg<T>orCImgl<T>

inst

ance

sin

aw

indo

w,

and

can

hand

leus

erev

ents

that

may

happ

enin

this

win

dow

(mou

se,k

eybo

ard,

...)

•T

heco

nstr

uctio

nof

a

CImgDisplayo

pens

aw

indo

w.

•T

hede

stru

ctio

nof

a

CImgDisplayc

lose

sth

eco

rres

pond

ing

win

dow

.

•T

hedi

spla

yof

anim

age

ina

CImgDisplay

isdo

neby

aca

llto

the

CImgDisplay::display()fu

nctio

n.

Page 119: CImg Slides

CIm

gDis

play

:O

verv

iew

•A

CImgDisplaya

llow

sto

disp

lay

CImg<T>orCImgl<T>

inst

ance

sin

aw

indo

w,

and

can

hand

leus

erev

ents

that

may

happ

enin

this

win

dow

(mou

se,k

eybo

ard,

...)

•T

heco

nstr

uctio

nof

a

CImgDisplayo

pens

aw

indo

w.

•T

hede

stru

ctio

nof

a

CImgDisplayc

lose

sth

eco

rres

pond

ing

win

dow

.

•T

hedi

spla

yof

anim

age

ina

CImgDisplay

isdo

neby

aca

llto

the

CImgDisplay::display()fu

nctio

n.

•A

CImgDisplayh

asits

own

pixe

lbu

ffer.

Itdo

esno

tst

ore

any

refe

renc

esto

the

CImg<T>orCImgList<T>pas

sed

atth

ela

stca

llto

CImgDisplay::display().

Page 120: CImg Slides

CIm

gDis

play

:H

andl

ing

even

ts

•W

hen

open

ing

the

win

dow

,an

even

t-ha

ndlin

gth

read

iscr

eate

d.

•T

his

thre

adau

tom

atic

ally

upda

tes

volatilefield

sof

the

CImgDisplayi

nsta

nce,

whe

nev

ents

occu

rin

the

corr

espo

ndin

gw

indo

w:

–M

ouse

even

ts:

mousex,mouseyand

buttonfie

lds

are

upda

ted.

–K

eybo

ard

even

t:

keyand

keys[

are

upda

ted.

–W

indo

wev

ents

:

isresized,is losedandismovedare

upda

ted.

•O

nly

one

thre

adis

used

toha

ndle

disp

lay

even

tsof

allo

pene

d

CImgDisplay.

•T

his

thre

adis

kille

dw

hen

the

last

disp

lay

win

dow

isde

stro

yed.

•T

he

CImgDisplayc

lass

isfu

llyco

ded

both

for

GD

I32

and

X11

grap

hics

libra

ries.

•D

ispl

ayau

tom

atic

ally

hand

les

imag

eno

rmal

izat

ion

todi

spla

yflo

at-v

alue

dim

ages

corr

ectly

.

Page 121: CImg Slides

CIm

gDis

play

:U

sefu

lfun

ctio

ns

•C

onst

ruct

ion

:

CImgDisplaydisp1(img,``Myfirstdisplay'');

CImgDisplaydisp2(640,400,''Myse onddisplay'');

•D

ispl

ay/R

efre

shim

age:

img.display(disp);

disp.display(img);

•H

andl

eev

ents

:

if(disp.key== img::keyQ)...

if(disp.is_resized)disp.resize();

if(disp.mouse_x>20&&disp.mouse_y<40)...

disp.wait();

•Te

mpo

rize

(for

anim

atio

ns)

:

disp.wait(20);

Page 122: CImg Slides

CIm

gDis

play

:E

xam

ple

ofus

ing

CImgDisplay

#in lude"CImg.h"

usingnamespa e img_library;

intmain() CImgDi

splaydisp(256,256,"MyDisplay");

while(!disp.is_ losed)

if(disp.button&1)

onstintx=disp.mouse_x,y=disp.mouse_y;

CImg<unsigned har>img(disp.dimx(),disp.dimy());

unsigned har ol[1=255;

img.fill(0).draw_ ir le(x,y,40, ol).display(disp);

if(disp.button&2)disp.resize(-90,-90);

if(disp.is_resized)disp.resize();

disp.wait();

return0;

Page 123: CImg Slides

Am

ore

com

plet

eex

ampl

eof

usin

g

CImg<T>(14C

++lin

es)

CImg<>img=CImg<>("img/milla.ppm").normalize(0,1);

CImgl<unsigned har>visu(img*255,CImg<unsigned har>(512,300,1,3,0));

onstunsigned haryellow[3=255,255,0,blue[3=0,155,255,blue2[3=0,0,255,blue3[3=0,0,155,

white[3=255,255,255;

CImgDisplaydisp(visu,"ImageandHistogram(Mouse li ktosettheGamma orre tion)",0);

for(doublegamma=1;!disp. losed&&disp.key!= img::keyQ&&disp.key!= img::keyESC;)

img_forXYZV(visu[0,x,y,z,k)visu[0(x,y,z,k)=(unsigned har)(pow((double)img(x,y,z,k),1.0/gamma)*256);

onstCImg<>hist=visu[0.get_histogram(50,0,255);

visu[1.fill(0).draw_text(50,5,white,NULL,1,"Gamma=%g",gamma).

draw_graph(hist,yellow,1,20000,0).draw_graph(hist,white,2,20000,0);

onstintxb=(int)(50+gamma*150);

visu[1.draw_re tangle(51,21,xb-1,29,blue2).draw_re tangle(50,20,xb,20,blue).draw_re tangle(xb,20,xb,30,blue);

visu[1.draw_re tangle(xb,30,50,29,blue3).draw_re tangle(50,20,51,30,blue3);

if(disp.button&&disp.mouse_x>=img.dimx()+50&&disp.mouse_x<=img.dimx()+450)gamma=(disp.mouse_x-img.dimx()-50)/150.0;

disp.resize(disp).display(visu).wait();

Res

ult:

His

togr

amm

anip

ulat

ion

and

gam

ma

corr

ectio

n(e

xam

ple

from

exam

ple

file

CImgdemo. pp)

Page 124: CImg Slides

PAR

TII

ofII

Page 125: CImg Slides

Out

line

-PA

RT

IIof

II:M

ore

insi

ghts

⇒Im

age

Filt

erin

g:

Goa

land

prin

cipl

e.

•C

onvo

lutio

n-

Cor

rela

tion.

•M

orph

omat

hs-

Med

ian

Filt

er.

•A

niso

trop

icsm

ooth

ing.

•O

ther

rela

ted

func

tions

.

•Im

age

Loop

s:

Usi

ngpr

edefi

ned

mac

ros.

•S

impl

elo

ops.

•N

eigh

borh

ood

loop

s.

•T

hepl

ug-in

mec

hani

sm.

•D

ealin

gw

ith3D

obje

cts.

•S

hare

dim

ages

.

Page 126: CImg Slides

Con

text

:Im

age

Filt

erin

g

•Im

age

filte

ring

ison

eof

the

mos

tcom

mon

oper

atio

nsdo

neon

imag

esin

orde

rto

retr

ieve

info

rmat

ions

.

Page 127: CImg Slides

Con

text

:Im

age

Filt

erin

g

•Im

age

filte

ring

ison

eof

the

mos

tcom

mon

oper

atio

nsdo

neon

imag

esin

orde

rto

retr

ieve

info

rmat

ions

.

•F

ilter

ing

isne

eded

inth

efo

llow

ing

case

s:

–C

ompu

teim

age

deriv

ativ

es(g

radi

ent)∇

I=(

∂I

∂x

∂I

∂x

)

T.

–N

oise

rem

oval

:G

auss

ian

orM

edia

nfil

terin

g.–

Edg

een

hanc

emen

t&D

econ

volu

tion

:S

harp

enm

asks

,Fou

rier

Tran

sfor

m.

–S

hape

anal

ysis

:M

orph

omat

hfil

ters

(ero

sion

,dila

tatio

n,..)

–...

Page 128: CImg Slides

Con

text

:Im

age

Filt

erin

g

•Im

age

filte

ring

ison

eof

the

mos

tcom

mon

oper

atio

nsdo

neon

imag

esin

orde

rto

retr

ieve

info

rmat

ions

.

•F

ilter

ing

isne

eded

inth

efo

llow

ing

case

s:

–C

ompu

teim

age

deriv

ativ

es(g

radi

ent)∇

I=(

∂I

∂x

∂I

∂x

)

T.

–N

oise

rem

oval

:G

auss

ian

orM

edia

nfil

terin

g.–

Edg

een

hanc

emen

t&D

econ

volu

tion

:S

harp

enm

asks

,Fou

rier

Tran

sfor

m.

–S

hape

anal

ysis

:M

orph

omat

hfil

ters

(ero

sion

,dila

tatio

n,..)

–...

•A

filte

ring

proc

ess

gene

rally

need

sth

eim

age

and

am

ask

(a.k

.ake

rnel

orst

ruct

urin

gel

emen

t).

Page 129: CImg Slides

How

filte

ring

wor

ks?

•F

orea

chpo

intp

∈Ω

ofth

eim

age

I,c

onsi

deri

tsne

ighb

orho

odN

I(p

)an

dco

mbi

neit

with

aus

er-d

efine

dm

ask

M.

−2

3..

.7

1

1. .

.. . .

. ..

−3

. . .. . .

. . .. . .

. . .−

4. .

.. . .

. ..

6

1−

2..

.8

−5

•N

eigh

borh

oodN

I(p

)an

dm

ask

Mha

veth

esa

me

size

.

•T

heop

erat

or•

may

belin

ear,

butn

otne

cess

arily

.

•T

here

sult

ofth

efil

terin

gop

erat

ion

isth

ene

wva

lue

atp

:

∀p∈

Ω,

J(p

)=

NI(p

)•M

Page 130: CImg Slides

Filt

erin

gex

ampl

es

(a)

Orig

inal

imag

e(b

)D

eriv

ativ

eal

ong

x(c

)E

rosi

on

•D

eriv

ativ

eob

tain

edw

ith•

=∗

and

M=

[0.5

0−

0.5]

•E

rosi

onob

tain

edw

ith•=

min

().

Page 131: CImg Slides

Out

line

-PA

RT

IIof

II:M

ore

insi

ghts

•Im

age

Filt

erin

g:

Goa

land

prin

cipl

e.

⇒C

onvo

lutio

n-

Cor

rela

tion.

•M

orph

omat

hs-

Med

ian

Filt

er.

•A

niso

trop

icsm

ooth

ing.

•O

ther

rela

ted

func

tions

.

•Im

age

Loop

s:

Usi

ngpr

edefi

ned

mac

ros.

•S

impl

elo

ops.

•N

eigh

borh

ood

loop

s.

•T

hepl

ug-in

mec

hani

sm.

•D

ealin

gw

ith3D

obje

cts.

•S

hare

dim

ages

.

Page 132: CImg Slides

Line

arfil

terin

g

•C

onvo

lutio

nan

dC

orre

latio

nim

plem

ents

linea

rfil

terin

g(•

=∗)

Con

volu

tion

:J(x

,y)

=∑

i

j

I(x

−i,

y−

j)M

(i,j

)

Cor

rela

tion

:J(x

,y)

=∑

i

j

I(x

+i,

y+

j)

M(i

,j)

CImg<T>::get_ onvolve(),CImg<T>:: onvolve()and

CImg<T>::get_ orrelate(),CImg<T>:: orrelate().

•C

ompu

teim

age

deriv

ativ

eal

ong

the

X-a

xis

:

CImg<>img(``toto.jpg'');

CImg<>mask=CImg<>(3,1).fill(0.5,0,-0.5);

img. onvolve(mask);

Page 133: CImg Slides

Line

arfil

terin

g(2

)

•Yo

uca

nse

tthe

bord

erco

nditi

onin

onvolve()an

d

orrelate()

•C

omm

onlin

ear

filte

rsar

eal

read

yim

plem

ente

d:

–G

auss

ian

kern

elfo

rim

age

smoo

thin

g:

CImg<T>::getblur()

and

CImg<T>::blur().

–Im

age

deriv

ativ

es:

CImg<T>::getgradientXY()

and

CImg<T>::getgradientXYZ().

⇒M

ore

fast

erve

rsio

nsth

anus

ing

the

CImg<T>:: onvolve()funct

ion

!

Blu

ran

imag

ew

itha

Gau

ssia

nke

rnel

with

σ=

10

.

Usi

ng

CImg<T>:: onvolve():1

129

ms.

Usi

ng

CImg<T>::blur():7ms

.

Page 134: CImg Slides

Line

arfil

terin

g(3

)

•W

hen

mas

ksi

zeis

big,

you

can

effic

ient

lyco

nvol

veth

eim

age

bya

mul

tiplic

atio

nin

the

Fou

rier

dom

ain.

CImg<T>::getFFT()ret

urns

a

CImgList<T>w

ithth

ere

alan

dim

agin

ary

part

ofth

eF

T.

CImg<T>::getFFT(true)ret

urns

a

CImgList<T>w

ithth

ere

alan

dim

agin

ary

part

ofth

ein

vers

eF

T.

Page 135: CImg Slides

Out

line

-PA

RT

IIof

II:M

ore

insi

ghts

•Im

age

Filt

erin

g:

Goa

land

prin

cipl

e.

•C

onvo

lutio

n-

Cor

rela

tion.

⇒M

orph

omat

hs-

Med

ian

Filt

er.

•A

niso

trop

icsm

ooth

ing.

•O

ther

rela

ted

func

tions

.

•Im

age

Loop

s:

Usi

ngpr

edefi

ned

mac

ros.

•S

impl

elo

ops.

•N

eigh

borh

ood

loop

s.

•T

hepl

ug-in

mec

hani

sm.

•D

ealin

gw

ith3D

obje

cts.

•S

hare

dim

ages

.

Page 136: CImg Slides

Mor

phom

aths

•N

onlin

ear

filte

rs.

•E

rosi

on:

Kee

pth

em

inin

umva

lue

inth

eim

age

neig

hbor

hood

havi

ngth

esa

me

shap

eth

anth

est

ruct

urin

gel

emen

tmas

k.

CImg<T>::erode()an

d

CImg<T>::geterode().

•D

ilata

tion

:K

eep

the

max

imum

valu

ein

the

imag

ene

ighb

orho

odha

ving

the

sam

esh

ape

than

the

stru

ctur

ing

elem

entm

ask.

CImg<T>::dilate()a

nd

CImg<T>::getdilate().

(a)

Orig

inal

imag

e(b

)E

rosi

onby

a10×

10

kern

el(b

)D

ilata

tion

bya

10×

10

kern

el

Page 137: CImg Slides

Mor

phom

aths

(2)

•O

peni

ng:

Ero

de,t

hen

dila

te:

img.erode(10).dilate(10);

•C

losi

ng:

Dila

te,t

hen

erod

e:

img.dilate(10).erode(10);.

(a)

Orig

inal

imag

e(b

)O

peni

ngby

a10×

10

kern

el(b

)C

losi

ngby

a10×

10

kern

el

Page 138: CImg Slides

Med

ian

filte

ring

•N

onlin

ear

filte

r:

Kee

pth

em

edia

nva

lue

inth

eim

age

neig

hbor

hood

havi

ngth

esa

me

shap

eth

anth

em

ask.

•F

unct

ions

CImg<T>::getblurmedian()andCImg<T>::blurmedian().

•N

ear

optim

alto

rem

ove

Sal

t&P

eppe

rno

ise.

Page 139: CImg Slides

Out

line

-PA

RT

IIof

II:M

ore

insi

ghts

•Im

age

Filt

erin

g:

Goa

land

prin

cipl

e.

•C

onvo

lutio

n-

Cor

rela

tion.

•M

orph

omat

hs-

Med

ian

Filt

er.

⇒A

niso

tropi

csm

ooth

ing.

•O

ther

rela

ted

func

tions

.

•Im

age

Loop

s:

Usi

ngpr

edefi

ned

mac

ros.

•S

impl

elo

ops.

•N

eigh

borh

ood

loop

s.

•T

hepl

ug-in

mec

hani

sm.

•D

ealin

gw

ith3D

obje

cts.

•S

hare

dim

ages

.

Page 140: CImg Slides

Ani

sotro

pic

smoo

thin

g

•N

on-li

near

edge

-dire

cted

diffu

sion

,ver

yop

timiz

edP

DE

-bas

edal

gorit

hm.

•V

ery

effic

ient

inre

mov

ing

Gau

ssia

nno

ise,

orot

her

addi

tive

nois

e.

•A

ble

tow

ork

on2D

and

3Dim

ages

.

•F

unct

ion

CImg<T>::bluranisotropi ().

•A

loto

fapp

licat

ions

:Im

age

deno

isin

g,re

cons

truc

tion,

resi

zing

.

Page 141: CImg Slides

Ani

sotro

pic

smoo

thin

g

CImg<T>::bluranisotropi ()imp

lem

ents

the

follo

win

gdi

ffusi

onP

DE

:

∀i=

1,..

.,n,

∂I i ∂t

=tr

ace(

TH

i)+

2 π∇

IT i

π

α=

0

J√

Ta

α

√T

whe

reJ

w=

∂u

∂x

∂u

∂y

∂v

∂x

∂v

∂y

an

dH

i=

∂2Ii

∂x

2∂

2Ii

∂x∂y

∂2Ii

∂x∂y

∂2Ii

∂y2

.

•Im

age

smoo

thin

gw

hile

pres

ervi

ngdi

scon

tinui

ties

(edg

es).

•O

neof

the

adva

nced

filte

ring

tool

inth

eC

Img

Libr

ary.

Page 142: CImg Slides

App

licat

ion

of

CImg<T>::bluranisotropi ()

“Bab

ouin

”(d

étai

l)-

512x

512

-(1

iter.,

19s)

Page 143: CImg Slides

App

licat

ion

of

CImg<T>::bluranisotropi ()

“Tun

isie

”-

555x

367

Page 144: CImg Slides

App

licat

ion

of

CImg<T>::bluranisotropi ()

“Tun

isie

”-

555x

367

-(1

iter.,

11s)

Page 145: CImg Slides

App

licat

ion

of

CImg<T>::bluranisotropi ()

“Tun

isie

”-

555x

367

-(1

iter.,

11s)

Page 146: CImg Slides

App

licat

ion

of

CImg<T>::bluranisotropi ()

“Béb

é”-

400x

375

Page 147: CImg Slides

App

licat

ion

of

CImg<T>::bluranisotropi ()

“Béb

é”-

400x

375

-(2

iter,

5.8s

)

Page 148: CImg Slides

App

licat

ion

of

CImg<T>::bluranisotropi ()

“Béb

é”-

400x

375

-(2

iter,

5.8s

)

Page 149: CImg Slides

App

licat

ion

of

CImg<T>::bluranisotropi ()

“Van

Gog

h”

Page 150: CImg Slides

App

licat

ion

of

CImg<T>::bluranisotropi ()

“Van

Gog

h”-

(1ite

r,5.

122s

).

Page 151: CImg Slides

App

licat

ion

of

CImg<T>::bluranisotropi ()

“Fle

urs”

(JP

EG

,10%

qual

ity).

Page 152: CImg Slides

App

licat

ion

of

CImg<T>::bluranisotropi ()

“Cor

ail”

(1ite

r.)

Page 153: CImg Slides

App

licat

ion

:Im

age

Inpa

intin

g

“Bird

”,or

igin

alco

lor

imag

e.

Page 154: CImg Slides

App

licat

ion

:Im

age

Inpa

intin

g “Bird

”,in

pain

ting

mas

kde

finiti

on.

Page 155: CImg Slides

App

licat

ion

:Im

age

Inpa

intin

g “Bird

”,in

pain

ted

with

our

PD

E.

Page 156: CImg Slides

App

licat

ion

:Im

age

Inpa

intin

g

“Chl

oéau

zoo”

,orig

inal

colo

rim

age.

Page 157: CImg Slides

App

licat

ion

:Im

age

Inpa

intin

g

“Chl

oéau

zoo”

,inp

aint

ing

mas

kde

finiti

on.

Page 158: CImg Slides

App

licat

ion

:Im

age

Inpa

intin

g

“Chl

oéau

zoo”

,inp

aint

edw

ithou

rP

DE

.

Page 159: CImg Slides

App

licat

ion

:Im

age

Inpa

intin

gan

dR

econ

stru

ctio

n

“Par

rot”

500x

500

(200

iter.,

4m11

s)

“Ow

l”

320x

246

(10

iter.,

1m01

s)

Page 160: CImg Slides

App

licat

ion

:Im

age

Res

izin

g

(c)

Det

ails

from

the

imag

ere

size

dby

bicu

bic

inte

rpol

atio

n.

(d)

Det

ails

from

the

imag

ere

size

dby

ano

n-lin

ear

regu

lariz

atio

nP

DE

.

Page 161: CImg Slides

App

licat

ion

:Im

age

Res

izin

g

(a)

Orig

inal

colo

rim

age

(b)

Blo

cIn

terp

olat

ion

(c)

Line

arIn

terp

olat

ion

(d)

Bic

ubic

Inte

rpol

atio

n(e

)P

DE

/LIC

Inte

rpol

atio

n

Page 162: CImg Slides

Out

line

-PA

RT

IIof

II:M

ore

insi

ghts

•Im

age

Filt

erin

g:

Goa

land

prin

cipl

e.

•C

onvo

lutio

n-

Cor

rela

tion.

•M

orph

omat

hs-

Med

ian

Filt

er.

•A

niso

trop

icsm

ooth

ing.

⇒O

ther

rela

ted

func

tions

.

•Im

age

Loop

s:

Usi

ngpr

edefi

ned

mac

ros.

•S

impl

elo

ops.

•N

eigh

borh

ood

loop

s.

•T

hepl

ug-in

mec

hani

sm.

•D

ealin

gw

ith3D

obje

cts.

•S

hare

dim

ages

.

Page 163: CImg Slides

Add

ing

nois

eto

imag

es

CImg<T>::noise()an

d

CImg<T>::getnoise().

•C

anad

ddi

ffere

ntki

ndof

nois

eto

the

imag

ew

ithsp

ecifi

eddi

strib

utio

n:

Uni

form

,G

auss

ian,

Poi

sson

,Sal

t&P

eppe

r .

•O

nepa

ram

eter

that

sett

heam

ount

ofno

ise

adde

d.

Page 164: CImg Slides

Ret

rievi

ngim

age

sim

ilarit

y

•Tw

oin

dice

sde

fined

tom

easu

re“d

ista

nce”

betw

een

two

imag

esI1

and

I2

:M

SE

and

PS

NR

.

•M

SE

,Mea

nS

quar

edE

rror

:

CImg<T>::MSE(img1,img2).

MS

E(I

1,I2)

=

p∈

Ω(I

1 (p)−

I2 (

p))

2

card

(Ω)

The

low

estt

heM

SE

is,t

hecl

oses

tthe

imag

esI1

and

I2

are.

•P

SN

R,P

eak

Sig

nalt

oN

oise

Rat

io:

CImg<T>::PSNR(img1,img2)

.

PS

NR

(I1,

I2)

=20

log10

(

M√

MS

E(I

1,I2)

)

whe

reM

isth

em

axim

umva

lue

ofI1

and

I2.

Page 165: CImg Slides

Filt

erin

gin

CIm

g:

Con

clus

ions

•A

loto

fuse

fulf

unct

ions

that

does

the

com

mon

imag

efil

terin

gta

sks.

•Li

near

and

Non

linea

rfil

ters

.

•B

utw

hati

fwe

wan

tto

defin

eto

follo

win

gfil

ter

???

∀p∈

Ω,

J(x

,y)

=∑

i,j

mod

(I(x

−i,

y−

j),

M(i

,j))

⇒T

here

are

smar

tw

ays

tode

fine

your

own

nonl

inea

rfil

ters

,us

ing

neig

hbor

hood

loop

s.

Page 166: CImg Slides

Out

line

-PA

RT

IIof

II:M

ore

insi

ghts

•Im

age

Filt

erin

g:

Goa

land

prin

cipl

e.

•C

onvo

lutio

n-

Cor

rela

tion.

•M

orph

omat

hs-

Med

ian

Filt

er.

•A

niso

trop

icsm

ooth

ing.

•O

ther

rela

ted

func

tions

.

⇒Im

age

Loop

s:

Usi

ngpr

edefi

ned

mac

ros.

•S

impl

elo

ops.

•N

eigh

borh

ood

loop

s.

•T

hepl

ug-in

mec

hani

sm.

•D

ealin

gw

ith3D

obje

cts.

•S

hare

dim

ages

.

Page 167: CImg Slides

Out

line

-PA

RT

IIof

II:M

ore

insi

ghts

•Im

age

Filt

erin

g:

Goa

land

prin

cipl

e.

•C

onvo

lutio

n-

Cor

rela

tion.

•M

orph

omat

hs-

Med

ian

Filt

er.

•A

niso

trop

icsm

ooth

ing.

•O

ther

rela

ted

func

tions

.

•Im

age

Loop

s:

Usi

ngpr

edefi

ned

mac

ros.

⇒S

impl

elo

ops.

•N

eigh

borh

ood

loop

s.

•T

hepl

ug-in

mec

hani

sm.

•D

ealin

gw

ith3D

obje

cts.

•S

hare

dim

ages

.

Page 168: CImg Slides

Sim

ple

loop

s

•Im

age

loop

sar

eve

ryus

eful

inim

age

proc

essi

ng,t

osc

anpi

xelv

alue

site

rativ

ely.

•C

Img

defin

em

acro

sth

atre

plac

eth

eco

rres

pond

ing

for(..;..;..)instru

ctio

ns.

img_forX(img,x)

for(intx=0;x<img.dimx();x++)

img_forY(img,y)

for(inty=0;y<img.dimy();y++)

img_forZ(img,z)

for(intz=0;z<img.dimz();z++)

img_forV(img,v)

for(intv=0;v<img.dimv();v++)

Page 169: CImg Slides

Sim

ple

loop

s

•Im

age

loop

sar

eve

ryus

eful

inim

age

proc

essi

ng,t

osc

anpi

xelv

alue

site

rativ

ely.

•C

Img

defin

em

acro

sth

atre

plac

eth

eco

rres

pond

ing

for(..;..;..)instru

ctio

ns.

img_forX(img,x)

for(intx=0;x<img.dimx();x++)

img_forY(img,y)

for(inty=0;y<img.dimy();y++)

img_forZ(img,z)

for(intz=0;z<img.dimz();z++)

img_forV(img,v)

for(intv=0;v<img.dimv();v++)

•C

Img

also

defin

es:

img_forXY(img,x,y)⇔ img_forY(img,y) img_forX(img,x)

img_forXYZ(img,x,y,z)⇔ img_forZ(img,z) img_forXY(img,x,y)

img_forXYZV(img,x,y,z,v) ⇔ img_forV(img,v) img_forXYZ(img,x,y,z)

Page 170: CImg Slides

Sim

ple

loop

s(2

)

•T

hese

loop

sle

adto

natu

ralc

ode

for

fillin

gan

imag

ew

ithva

lues

:

CImg<unsigned har>img(256,256);

img_forXY(img,x,y)img(x,y)=(x*y)%256;

Page 171: CImg Slides

Sim

ple

loop

s(2

)

•T

hese

loop

sle

adto

natu

ralc

ode

for

fillin

gan

imag

ew

ithva

lues

:

CImg<unsigned har>img(256,256);

img_forXY(img,x,y)img(x,y)=(x*y)%256;

Page 172: CImg Slides

Inte

rior

and

Bor

der

loop

s

•S

light

varia

nts

ofth

epr

evio

uslo

ops,

allo

win

gto

cons

ider

only

inte

rior

orim

age

bord

ers.

•A

nex

tra

para

met

ern

telli

ngab

outt

hesi

zeof

the

imag

ebo

rder

.

imgforinsideXY(img,x,y,n)an

d

imgforborderXY(img,x,y,n)(s

ame

for

3Dvo

lum

etric

imag

es).

CImg<unsigned har>img(256,256);

img forinsideXY(img,x,y,64)img(x,y)=x+y;

imgforborderXY(img,x,y,64)img(x,y)=x-y;

Page 173: CImg Slides

Out

line

-PA

RT

IIof

II:M

ore

insi

ghts

•Im

age

Filt

erin

g:

Goa

land

prin

cipl

e.

•C

onvo

lutio

n-

Cor

rela

tion.

•M

orph

omat

hs-

Med

ian

Filt

er.

•A

niso

trop

icsm

ooth

ing.

•O

ther

rela

ted

func

tions

.

•Im

age

Loop

s:

Usi

ngpr

edefi

ned

mac

ros.

•S

impl

elo

ops.

⇒N

eigh

borh

ood

loop

s.

•T

hepl

ug-in

mec

hani

sm.

•D

ealin

gw

ith3D

obje

cts.

•S

hare

dim

ages

.

Page 174: CImg Slides

Nei

ghbo

rhoo

d-ba

sed

loop

s

•V

ery

pow

erfu

lloo

ps,a

llow

tolo

opan

entir

ene

ighb

orho

odov

eran

imag

e.

•Fr

om2×

2to

5fo

r2D

neig

hbor

hood

.

•Fr

om2×

2to

3fo

r3D

neig

hbor

hood

.

•B

orde

rco

nditi

on:

Nea

rest

-nei

ghbo

r.

•N

eed

anex

tern

alne

ighb

orho

odva

riabl

ede

clar

atio

n.

•A

llow

tow

rite

very

smal

l,cl

ear

and

optim

ized

code

.

Page 175: CImg Slides

Nei

ghbo

rhoo

d-ba

sed

loop

s:

3ex

ampl

e

•N

eigh

borh

ood

decl

arat

ion

:

CImg_3x3(I,float).

Page 176: CImg Slides

Nei

ghbo

rhoo

d-ba

sed

loop

s:

3ex

ampl

e

•N

eigh

borh

ood

decl

arat

ion

:

CImg_3x3(I,float).

•A

ctua

lly,t

helin

eab

ove

defin

es9

diffe

rent

varia

bles

,nam

ed:

IppI pInp

Ip I In

IpnI nInn

whe

rep

=pr

evio

us,c

=cu

rren

t,n

=ne

xt.

Page 177: CImg Slides

Nei

ghbo

rhoo

d-ba

sed

loop

s:

3ex

ampl

e

•N

eigh

borh

ood

decl

arat

ion

:

CImg_3x3(I,float).

•A

ctua

lly,t

helin

eab

ove

defin

es9

diffe

rent

varia

bles

,nam

ed:

IppI pInp

Ip I In

IpnI nInn

whe

rep

=pr

evio

us,c

=cu

rren

t,n

=ne

xt.

•U

sing

a

img_for3x3()autom

atic

ally

upda

tes

the

neig

hbor

hood

with

the

corr

ect

valu

es. img_f

or3x3(img,x,y,0,0,I)

..Here,Ipp,I p,...I n,Innarea essible...

Page 178: CImg Slides

Nei

ghbo

rhoo

d-ba

sed

loop

s

•E

xam

ple

ofus

e:

Com

pute

the

grad

ient

norm

with

one

loop

.

CImg<float>img(``milla.jpg''),dest(img);

CImg_3x3(I,float);

img_forV(img,v) img_for3x3(img,x,y,0,v,I)

onstfloatix=(In -Ip )/2,iy=(I n-I p)/2;

dest(x,y)=std::sqrt(ix*ix+iy*iy);

Page 179: CImg Slides

Exa

mpl

e:

Mod

ulo

Filt

erin

g

•W

hati

fwe

wan

tto

defin

eto

follo

win

gfil

ter

???

∀p∈

Ω,

J(x

,y)

=∑

i,j

mod

(I(x

−i,

y−

j),

M(i

,j))

Page 180: CImg Slides

Exa

mpl

e:

Mod

ulo

Filt

erin

g

•W

hati

fwe

wan

tto

defin

eto

follo

win

gfil

ter

???

∀p∈

Ω,

J(x

,y)

=∑

i,j

mod

(I(x

−i,

y−

j),

M(i

,j))

•S

impl

eso

lutio

n,us

ing

a3x

3m

ask

:

CImg<unsigned har>img(``milla.jpg''),mask(3,3);

CImg<>dest(img);

CImg_3x3(I,float);

img_forV(img,v) img_for3x3(img,x,y,0,v,I)

dest(x,y)=mask(0,0)%Ipp+mask(1,0)%I p+mask(2,0)%Inp

+mask(0,1)%Ip +mask(1,1)%I +mask(2,1)%In

+mask(0,2)%Ipn+mask(1,2)%I n+mask(2,2)%Inn;

Page 181: CImg Slides

Out

line

-PA

RT

IIof

II:M

ore

insi

ghts

•Im

age

Filt

erin

g:

Goa

land

prin

cipl

e.

•C

onvo

lutio

n-

Cor

rela

tion.

•M

orph

omat

hs-

Med

ian

Filt

er.

•A

niso

trop

icsm

ooth

ing.

•O

ther

rela

ted

func

tions

.

•Im

age

Loop

s:

Usi

ngpr

edefi

ned

mac

ros.

•S

impl

elo

ops.

•N

eigh

borh

ood

loop

s.

⇒T

hepl

ug-in

mec

hani

sm.

•D

ealin

gw

ith3D

obje

cts.

•S

hare

dim

ages

.

Page 182: CImg Slides

CIm

gpl

ugin

s

•S

omet

imes

anus

erne

eds

orde

fines

spec

ific

func

tions

,eith

erve

rysp

ecia

lized

orno

tgen

eric

enou

gh.

•N

otsu

itabl

eto

bein

tegr

ated

inth

eC

Img

Libr

ary,

buti

nter

estin

gto

shar

ean

yway

.

Page 183: CImg Slides

CIm

gpl

ugin

s

•S

omet

imes

anus

erne

eds

orde

fines

spec

ific

func

tions

,eith

erve

rysp

ecia

lized

orno

tgen

eric

enou

gh.

•N

otsu

itabl

eto

bein

tegr

ated

inth

eC

Img

Libr

ary,

buti

nter

estin

gto

shar

ean

yway

.

⇒In

tegr

atio

npo

ssib

lein

CIm

gvi

ath

epl

ug-in

sm

echa

nism

.

#define img_plugin``my_plugin.h''

#in lude``CImg.h''

usingnamespa e img_library;

intmain() CImg<>

img(``milla.jpg'');

img.my_wonderful_fun tion();

return0;

Page 184: CImg Slides

CIm

gpl

ugin

s

•P

lugi

nfu

nctio

nsar

edi

rect

lyad

ded

asm

embe

rfu

nctio

nsof

the

CIm

gcl

ass.

//File``my_plugin.h''

//---------------------

CImg<T>my_wonderful_fun tion()

(*this)=(T)3.14f;

return*this;

Page 185: CImg Slides

CIm

gpl

ugin

s

•P

lugi

nfu

nctio

nsar

edi

rect

lyad

ded

asm

embe

rfu

nctio

nsof

the

CIm

gcl

ass.

//File``my_plugin.h''

//---------------------

CImg<T>my_wonderful_fun tion()

(*this)=(T)3.14f;

return*this;

•V

ery

flexi

ble

syst

em,i

mpl

emen

ted

asea

sily

as:

lassCImg<T>

... #ifdef img_plugin

#in lude img_plugin

#endif ;

Page 186: CImg Slides

CIm

gpl

ugin

s

•A

dvan

tage

s:

–A

llow

crea

tions

orm

odifi

catio

nsof

exis

ting

func

tions

byth

eus

er,

with

out

mod

ifyin

gth

elib

rary

sour

ceco

de.

Page 187: CImg Slides

CIm

gpl

ugin

s

•A

dvan

tage

s:

–A

llow

crea

tions

orm

odifi

catio

nsof

exis

ting

func

tions

byth

eus

er,

with

out

mod

ifyin

gth

elib

rary

sour

ceco

de.

–A

llow

tosp

ecia

lize

the

libra

ryac

cord

ing

toth

eus

er’s

wor

k.

Page 188: CImg Slides

CIm

gpl

ugin

s

•A

dvan

tage

s:

–A

llow

crea

tions

orm

odifi

catio

nsof

exis

ting

func

tions

byth

eus

er,

with

out

mod

ifyin

gth

elib

rary

sour

ceco

de.

–A

llow

tosp

ecia

lize

the

libra

ryac

cord

ing

toth

eus

er’s

wor

k.–

Allo

wan

easy

redi

strib

utio

nof

usef

ulfu

nctio

nsas

open

sour

ceco

mpo

nent

s.⇒

Ave

rygo

odw

ayto

cont

ribut

eto

the

libra

ry.

Page 189: CImg Slides

CIm

gpl

ugin

s

•A

dvan

tage

s:

–A

llow

crea

tions

orm

odifi

catio

nsof

exis

ting

func

tions

byth

eus

er,

with

out

mod

ifyin

gth

elib

rary

sour

ceco

de.

–A

llow

tosp

ecia

lize

the

libra

ryac

cord

ing

toth

eus

er’s

wor

k.–

Allo

wan

easy

redi

strib

utio

nof

usef

ulfu

nctio

nsas

open

sour

ceco

mpo

nent

s.⇒

Ave

rygo

odw

ayto

cont

ribut

eto

the

libra

ry.

•E

xist

ing

plug

ins

inth

ede

faul

tCIm

gpa

ckag

e:

–Lo

cate

din

the

dire

ctor

y

CImg/plugins/

img_matlab.h:Prov

ide

code

inte

rfac

ebe

twee

nC

Img

and

Mat

lab

imag

es.

nlmeans.h:Im

plem

enta

tion

ofN

on-L

ocal

Mea

nF

ilter

(Bua

des

etal

).–

noise_analysis.h:A

dvan

ced

stat

istic

sfo

rno

ise

estim

atio

n.–

toolbox3d.h:

Fun

ctio

nsto

cons

truc

tcla

ssic

al3D

mes

hes

(cub

es,s

pher

e,...

)

Page 190: CImg Slides

CIm

gpl

ugin

s

•P

lug-

ins

varia

bles

:

#define img_plugin:Add

func

tions

toth

e

CImg<T>class

.–

#define imglist_plugin:

Add

func

tions

toth

e

CImgList<T>c

lass

.

•U

sing

seve

ralp

lug-

ins

ispo

ssib

le:

#define img_plugin``all_plugins.h''.

//file``all_plugins.h''

#in lude``plugin1.h''

#in lude``plugin2.h''

#in lude``plugin3.h''

⇒W

ithth

epl

ugin

mec

hani

sm,C

Img

isa

very

open

fram

ewor

kfo

rim

age

proc

essi

ng.

Page 191: CImg Slides

Out

line

-PA

RT

IIof

II:M

ore

insi

ghts

•Im

age

Filt

erin

g:

Goa

land

prin

cipl

e.

•C

onvo

lutio

n-

Cor

rela

tion.

•M

orph

omat

hs-

Med

ian

Filt

er.

•A

niso

trop

icsm

ooth

ing.

•O

ther

rela

ted

func

tions

.

•Im

age

Loop

s:

Usi

ngpr

edefi

ned

mac

ros.

•S

impl

elo

ops.

•N

eigh

borh

ood

loop

s.

•T

hepl

ug-in

mec

hani

sm.

⇒D

ealin

gw

ith3D

obje

cts.

•S

hare

dim

ages

.

Page 192: CImg Slides

3DO

bjec

tVis

ualiz

atio

n:

Con

text

•In

alo

tof

imag

epr

oces

sing

prob

lem

s,on

ene

eds

tore

cons

truc

t3D

mod

els

from

raw

imag

eda

tase

ts.

–3D

from

ster

eoim

ages

/mul

tiple

cam

eras

.–

3Dsu

rfac

ere

cons

truc

tion

from

volu

met

ricM

RIi

mag

es.

–3D

surf

ace

reco

nstr

uctio

nfr

ompo

ints

clou

ds(3

Dsc

anne

r).

Page 193: CImg Slides

3DO

bjec

tVis

ualiz

atio

n:

Con

text

⇒B

asic

and

inte

rgra

ted

3Dm

eshe

svi

sual

izat

ion

capa

bilit

ies

may

beus

eful

inan

yim

age

proc

essi

nglib

rary

.

•...

but

we

don’

tw

ant

tore

plac

eco

mpl

ete

3Dre

nder

ing

libra

ries

(ope

nGL,

Dire

ct3D

,VT

K,.

..).

•C

Img

allo

ws

tovi

sual

ize

3Dob

ject

sfo

rpu

nctu

als

need

s.

–C

andi

spla

ysa

seto

f3D

prim

itive

s(p

oint

s,lin

es,t

riang

les)

with

give

nop

acity

.–

Can

rend

erob

ject

sw

ithfla

t,go

urau

dor

phon

g-lik

elig

htm

odel

s.–

Con

tain

san

inte

ract

ive

disp

lay

func

tion

tovi

ewth

e3D

obje

ct.

–Te

xtur

em

appi

ngsu

ppor

ted.

–N

om

ultip

lelig

hts

allo

wed

.–

No

GP

Uac

cele

ratio

n.

Page 194: CImg Slides

3DO

bjec

tVis

ualiz

atio

n:

Live

Dem

o

•M

ean

Cur

vatu

reF

low

.

•Im

age

asa

surf

ace.

•To

olbo

x3D

.

Page 195: CImg Slides

3DO

bjec

tVis

ualiz

atio

n:

How

does

itw

orks

?

•C

Img

has

a

CImg<T>::draw_*()f

unct

ion

that

can

draw

apr

ojec

tion

ofa

3Dob

ject

into

a2D

imag

e:

CImg<T>::drawobje t3d()

Page 196: CImg Slides

3DO

bjec

tVis

ualiz

atio

n:

How

does

itw

orks

?

•C

Img

has

a

CImg<T>::draw_*()f

unct

ion

that

can

draw

apr

ojec

tion

ofa

3Dob

ject

into

a2D

imag

e:

CImg<T>::drawobje t3d()

•H

igh-

leve

lint

erac

tive

3Dob

ject

disp

lay

:

CImg<T>::displayobje t3d()

⇒A

ll3D

visu

aliz

atio

nca

pabi

litie

sof

CIm

gar

eba

sed

onth

ese

two

func

tions

.

Page 197: CImg Slides

3DO

bjec

tVis

ualiz

atio

n:

How

does

itw

orks

?

•C

Img

has

a

CImg<T>::draw_*()f

unct

ion

that

can

draw

apr

ojec

tion

ofa

3Dob

ject

into

a2D

imag

e:

CImg<T>::drawobje t3d()

•H

igh-

leve

lint

erac

tive

3Dob

ject

disp

lay

:

CImg<T>::displayobje t3d()

⇒A

ll3D

visu

aliz

atio

nca

pabi

litie

sof

CIm

gar

eba

sed

onth

ese

two

func

tions

.

•N

eede

dpa

ram

eter

s:

–A

CImgList<tp>

of3D

poin

tsco

ordi

nate

s(s

ize

M).

–A

CImgList<tf>

ofpr

imiti

ves

(siz

eN

).–

A

CImgList<T>o

fcol

ors/

text

ures

(siz

eN

).–

A

CImgList<to>

ofop

aciti

es(s

ize

N)

(opt

iona

lpar

amet

er).

Page 198: CImg Slides

Dis

play

aho

use

:bu

ildin

gpo

intl

ist

CImgList<float>points(9,1,3,1,1,

-50,-50,-50,//Point0

50,-50,-50,//Point1

50,50,-50,//Point2

-50,50,-50,//Point3

-50,-50,50,//Point4

50,-50,50,//Point5

50,50,50,//Point6

-50,50,50,//Point7

0,-100,0);//Point8

⇒Li

stof

9ve

ctor

s(im

ages

1x3)

with

spec

ified

coor

dina

tes.

Page 199: CImg Slides

Dis

play

aho

use

:bu

ildin

gpr

imiti

ves

list

CImgList<unsignedint>primitives(6,1,4,1,1,

0,1,5,4,//Fa e0

3,7,6,2,//Fa e1

1,2,6,5,//Fa e2

0,4,7,3,//Fa e3

0,3,2,1,//Fa e4

4,5,6,7);//Fa e5

primitives.insert(CImgList<unsignedint>(4,1,2,1,1,

0,8,//Segment6

1,8,//Segment7

5,8,//Segment8

4,8));//Segment9

⇒Li

stof

10ve

ctor

s:

6re

ctan

gle

+4

segm

ents

.

Page 200: CImg Slides

Dis

play

aho

use

:bu

ildin

gco

lors

CImgList<unsigned har> olors;

olors.insert(6,CImg<unsigned har>::ve tor(255,0,255));

olors.insert(4,CImg<unsigned har>::ve tor(255,255,255));

•T

hen,

....

visu

aliz

e.

CImg<unsigned har>(800,600,1,3).fill(0).

display_obje t3d(points,primitives, olors);

Page 201: CImg Slides

Dis

play

atr

ansp

aren

thou

se:

setti

ngpr

imiti

veop

aciti

es

CImgList<float>opa ities;

opa ities.insert(6,CImg<>::ve tor(0.5f));

opa ities.insert(4,CImg<>::ve tor(1.0f));

•T

hen,

....

visu

aliz

e.

CImg<unsigned har>(800,600,1,3).fill(0).

display_obje t3d(points,primitives, olors,opa ities);

•O

ther

para

met

ers

ofth

e3D

func

tions

allo

wto

set:

•Li

ghtp

ositi

on,a

ndam

bian

tlig

htin

tens

ity.

•C

amer

apo

sitio

nan

dfo

cale

.•

Ren

derin

gty

pe(G

oura

ud,F

lat,

...)

•D

oubl

e/S

ingl

efa

ces.

Page 202: CImg Slides

How

toco

nstr

uct3

Dm

eshe

s?

•P

lugi

n:

CImg/plugins/primitives.hconta

ins

usef

ulfu

nctio

nsto

retr

ieve

clas

sica

lm

eshe

s.

CImg<T>:: ube(),CImg<T>::sphere(),CImg<T>:: ylinder(),

...

•Li

brar

yfu

nctio

ns:

CImg<T>::mar hing_ ubes()andCImg<T>::mar hing_squares().

⇒C

reat

em

eshe

sfr

omim

plic

itfu

nctio

ns.

Page 203: CImg Slides

Exa

mpl

e:

Seg

men

tatio

nof

the

whi

tem

atte

rfro

mM

RIi

mag

es

CImg<>img(``volumeMRI.inr'');

CImg<>region;

floatbla k[1=0;

img.draw_fill(X0,Y0,Z0,bla k,region,10.0f);

(region*=-1).blur(1.0f).normalize(-1,1);

CImgList<>points,fa es;

region.mar hing_ ubes(0,points,fa es);

CImgList<unsigned har> olors;

olors.insert(fa es.size,CImg<unsigned har>::ve tor(200,100,20));

CImg<unsigned har>(800,600,1,3).fill(0).

display_obje t3d(points,fa es, olors);

Page 204: CImg Slides

Exa

mpl

e:

Seg

men

tatio

nof

the

whi

tem

atte

rfro

mM

RIi

mag

es

Page 205: CImg Slides

Exa

mpl

e:

Isop

hote

sw

ithm

arch

ing

squa

res

Page 206: CImg Slides

Out

line

-PA

RT

IIof

II:M

ore

insi

ghts

•Im

age

Filt

erin

g:

Goa

land

prin

cipl

e.

•C

onvo

lutio

n-

Cor

rela

tion.

•M

orph

omat

hs-

Med

ian

Filt

er.

•A

niso

trop

icsm

ooth

ing.

•O

ther

rela

ted

func

tions

.

•Im

age

Loop

s:

Usi

ngpr

edefi

ned

mac

ros.

•S

impl

elo

ops.

•N

eigh

borh

ood

loop

s.

•T

hepl

ug-in

mec

hani

sm.

•D

ealin

gw

ith3D

obje

cts.

⇒S

hare

dim

ages

.

Page 207: CImg Slides

Sha

red

imag

es:

Con

text

•Tw

ofr

eque

ntca

ses

with

unde

sire

dim

age

copi

es:

1.S

omet

imes

,we

wan

tto

pass

cont

iguo

uspa

rts

ofan

imag

e(b

utno

tall

the

imag

e)to

afu

nctio

n: onst

CImg<>img(``milla.jpg'');

CImgList<>RG=img.get_ hannels(0,1).get_split('v');

Page 208: CImg Slides

Sha

red

imag

es:

Con

text

•Tw

ofr

eque

ntca

ses

with

unde

sire

dim

age

copi

es:

1.S

omet

imes

,we

wan

tto

pass

cont

iguo

uspa

rts

ofan

imag

e(b

utno

tall

the

imag

e)to

afu

nctio

n: onst

CImg<>img(``milla.jpg'');

CImgList<>RG=img.get_ hannels(0,1).get_split('v');

2...O

r,w

ew

antt

om

odify

cont

iguo

uspa

rts

ofan

imag

e(b

utno

tall

the

imag

e):

CImg<>img(``milla.jpg'');

img.draw_image(img.get_ hannel(1).blur(3),0,0,0,1);

Page 209: CImg Slides

Sha

red

imag

es:

Con

text

•Tw

ofr

eque

ntca

ses

with

unde

sire

dim

age

copi

es:

1.S

omet

imes

,we

wan

tto

pass

cont

iguo

uspa

rts

ofan

imag

e(b

utno

tall

the

imag

e)to

afu

nctio

n: onst

CImg<>img(``milla.jpg'');

CImgList<>RG=img.get_ hannels(0,1).get_split('v');

2...O

r,w

ew

antt

om

odify

cont

iguo

uspa

rts

ofan

imag

e(b

utno

tall

the

imag

e):

CImg<>img(``milla.jpg'');

img.draw_image(img.get_ hannel(1).blur(3),0,0,0,1);

⇒...

But

we

also

wan

tto

avoi

dim

age

copi

esfo

rbe

tter

perf

orm

ance

...

Page 210: CImg Slides

Sha

red

imag

es

•S

olut

ion

:U

sesh

ared

imag

es:

1.R

epla

ce: onst

CImg<>img(``milla.jpg'');

CImgList<>RG=img.get_ hannels(0,1).get_split('v');

by

onstCImg<>img(``milla.jpg'');

CImgList<>RG=img.get_shared_ hannels(0,1).get_split('v');

Page 211: CImg Slides

Sha

red

imag

es

•S

olut

ion

:U

sing

shar

edim

ages

:

2.R

epla

ce: CImg<>

img(``milla.jpg'');

img.draw_image(img.get_ hannel(1).blur(3),0,0,0,1);

by

CImg<>img(``milla.jpg'');

img.get_shared_ hannel(1).blur(3);

Page 212: CImg Slides

Sha

red

imag

es

•R

egio

nsco

mpo

sed

ofco

ntig

uous

pixe

lsin

mem

ory

are

cand

idat

esfo

rbe

ing

shar

edim

ages

:

CImg<T>::get_shared_point[s()

CImg<T>::get_shared_line[s()

CImg<T>::get_shared_plane[s()

CImg<T>::get_shared_ hannel[s()

CImg<T>::get_shared()

•Im

age

attr

ibut

e

CImg<T>::is_shared

tells

abou

tthe

shar

edst

ate

ofan

imag

e.

•S

hare

dim

age

dest

ruct

ordo

esno

thin

g(n

om

emor

yfr

eed)

.

⇒W

arni

ng:

Nev

erde

stro

yan

imag

ebe

fore

itssh

ared

vers

ion

!!

Page 213: CImg Slides

Sha

red

imag

esan

dC

ImgL

ist<

T>

•In

sert

ing

ash

ared

imag

eC

Img<

T>

into

aC

ImgL

ist<

T>

mak

esa

copy

:

CImgList<>list;

CImg<>shared=img.get_shared_ hannel(0);

list.insert(shared);

shared.assign();//OK,'list'notmodified.

•F

unct

ion

CImgList<T>::insert()can

beus

edin

aw

ayth

atit

forc

esth

ein

sert

ion

ofa

shar

edim

age

into

alis

t.

CImgList<unsigned har> olors;

CImg<unsigned har> olor=CImg<unsigned har>::ve tor(255,0,255);

list.insert(1000, olors,list.size,true);

olor.fill(0);//'list'willbealsomodified.

Page 214: CImg Slides

Con

clus

ion

Page 215: CImg Slides

Con

clus

ion

and

Link

s

•T

heC

Img

Libr

ary

ease

sth

eco

ding

ofim

age

proc

essi

ngal

gorit

hms.

•F

orm

ore

deta

ils,p

leas

ego

toth

eof

ficia

lCIm

gsi

te!

http:// img.sour eforge.net/

•A

’com

plet

e’in

line

refe

renc

edo

cum

enta

tion

isav

aila

ble

(gen

erat

edw

ith

doxygen).

•A

lot

ofsi

mpl

eex

ampl

esar

epr

ovid

edin

the

CIm

gpa

ckag

e,co

verin

ga

lot

ofco

mm

onim

age

proc

essi

ngta

sks.

Itis

the

best

info

rmat

ion

sour

ceto

unde

rsta

ndho

wC

Img

can

beus

edat

afir

stgl

ance

.

•F

inal

ly,

ques

tions

abou

tC

Img

can

bepo

sted

inits

activ

eS

ourc

efor

gefo

rum

:(A

vaila

ble

from

the

mai

npa

ge).

Page 216: CImg Slides

Con

clus

ion

and

Link

s

•N

ow,y

oukn

owal

mos

teve

ryth

ing

toha

ndle

com

plex

imag

epr

oces

sing

task

sw

ithth

eC

Img

Libr

ary.

⇒Yo

uca

nco

ntrib

ute

toth

isop

enso

urce

proj

ect:

–S

ubm

itbu

gre

port

san

dpa

tche

s.–

Pro

pose

new

exam

ples

orpl

ug-in

s.

Page 217: CImg Slides

Use

din

real

wor

ld:

“GR

EY

Cst

orat

ion”

•T

his

anis

otro

pic

smoo

thin

gfu

nctio

nha

sbe

enem

bedd

edin

anop

en-s

ourc

eso

ftwar

e:

GR

EY

Cst

orat

ion

.

⇒D

istr

ibut

edas

afr

eeco

mm

and

line

prog

ram

ora

plug

-info

rG

IMP.

http://www.grey .ensi aen.fr/dts hump/grey storation/

Page 218: CImg Slides

Use

din

real

wor

ld:

DT-

MR

IVis

ualiz

atio

nan

dF

iber

Trac

king

•D

TM

RI

data

set

visu

aliz

atio

nan

dfib

ertr

acki

ngco

deis

dist

ribut

edin

the

CIm

gpa

ckag

e(F

ileex

ampl

es/d

tmri

view

.cpp

,823

lines

).

Cor

pus

Cal

losu

mF

iber

Trac

king

Page 219: CImg Slides

The

end

Tha

nkyo

ufo

ryo

urat

tent

ion.

Tim

efo

rad

ditio

nalq

uest

ions

ifan

y..