23-02-2017
1
Imagens digitais
www.dee.isep.ipp.pt/~jml/intmu/slides/imagem.pdf
Sinal Analógico
0.5
1.0
2.0
2.5
1.5
-0.5
-1.0
-2.0
-2.5
-1.5
0.0
t
23-02-2017
2
Amostragem
0.5
1.0
2.0
2.5
1.5
-0.5
-1.0
-2.0
-2.5
-1.5
0.0
t Ta
Amostras
0.5
1.0
2.0
2.5
1.5
-0.5
-1.0
-2.0
-2.5
-1.5
0.0
t Ta
23-02-2017
3
Quantificação
0.5
1.0
2.0
2.5
1.5
-0.5
-1.0
-2.0
-2.5
-1.5
0.0
t
N4
N3
N2
N1
Erro de Quantificação
0.5
1.0
2.0
2.5
1.5
-0.5
-1.0
-2.0
-2.5
-1.5
0.0
t
N4
N3
N2
N1
23-02-2017
4
Codificação
0.5
1.0
2.0
2.5
1.5
-0.5
-1.0
-2.0
-2.5
-1.5
0.0
t
N4=11
N3=10
N2=01
N1=00
11 11 11 11 11
10
10 10
10
00 00 00
01
Sinal Digital: 11111110000010101111100100
Conversão D/A
0.5
1.0
2.0
2.5
1.5
-0.5
-1.0
-2.0
-2.5
-1.5
0.0
t
11 11 11 11 11
10
10 10
10
00 00 00
01
23-02-2017
5
Conversão D/A
0.5
1.0
2.0
2.5
1.5
-0.5
-1.0
-2.0
-2.5
-1.5
0.0
t
Vantagens da Digitalização
Um único tipo de dispositivo de armazenamento é suficiente para todos os tipos de dados.
A transmissão automática é simplificada porque apenas são necessárias redes capazes de transportar bits.
O sinal digital é mais robusto do que o analógico • é menos sensível ao ruído.
• pode sempre ser reconstituído.
• não há perda de qualidade na transmissão ou reprodução.
• são possíveis mecanismos de deteção e até correção de erros.
Facilidade de cifragem/decifragem para implementar segurança.
23-02-2017
6
Desvantagens da digitalização
O processo de digitalização introduz sempre distorções
• A largura de banda do sinal é limitada pelo número de amostras (NA)
• Erro de quantificação dependente do número de bits/amostra
Reduzir distorção implica aumentar NA*bits/amostra
A conversão sucessiva A/D e D/A não produz um sinal idêntico ao original.
Resolução: Nº de pixels
3x6 12x24 48x96 192x384
NPix = NC * NL NL linhas
NC colunas
23-02-2017
7
Resolução espacial
Píxeis por unidade de medida linear (densidade).
Pode ser diferente em x e em y.
Unidades habituais:
• DPI (dots per inch)
• PPP (pontos por polegada)
• PPM (pontos por metro)
Exemplos: • 300 DPI = Alta resolução, para impressão
• 72 DPI = Baixa resolução, para apresentação em monitores
Resolução espacial
Resx = NC / X
Resy = NL / Y
Resolução média:
Resm = (Resx + Resy ) / 2
Resolução diagonal
Pontos por unidade de área: ResA = (NL*NC) / (X*Y) = Resx * Resy [P/mm2] ou [DPI2]
NL linhas
X
Y
NC colunas
23-02-2017
8
Resolução: Exemplo
Fotografia de 4” x 6” ( 10 cm x 15 cm)
Digitalizada com 1200 x 1800 pixels
A resolução utilizada foi:
Resx = 300 DPI
Resy = 300 DPI
Res = 300 DPI !
Res = 300 DPI x 300 DPI
Res = 300 x 300 DPI
Res = 90 000 DPI
Res = 90 000 DPI2
- Correcto - Aceitável - Errado ! - Ambíguo se Resx!=Resy
Pixel Pitch
Distância entre pixels
Pitch = 1 / Res
pw = 1 / Resw = W / NC
ph = 1 / Resh = H / NL
Unidades:
• mm, mm / pix
• m, m / pix
• in, in / pix
NL linhas
W
pw
ph
H
NC colunas
23-02-2017
9
Profundidade de cor
Indica o nº de cores que um pixel pode ter.
Unidades
• cores
• bits
• n cores = 2b bits
• b bits = log2(n cores)
Pixel Size (PS)
• Normalmente: PS = b bits = log2(n cores)
Bits Cores
1 2
2 4
4 16
8 256
16 65 536
24 16 777 216
Color in Images and Video
Visible light is an electromagnetic wave in the 400 nm - 700 nm range.
18
Most light we see is not one wavelength, it's a combination of many wavelengths.
23-02-2017
10
The Human Retina The eye functions on the same principle as a camera.
Each neuron is either a rod or a cone.
The rods contain the elements that are sensitive to light intensities. Rods are not sensitive to color.
Cones come in 3 types: red, green and blue. Each responds differently to various frequencies of light.
19
Cones and Color
The cones provide humans with vision during the daylight and are believed to be separated into three types, where each type is more sensitive to a particular wavelength
The color signal to the brain comes from the response of the 3 cones to the spectra being observed. That is, the signal consists of 3 numbers:
20
where E is the light and S is the sensitivity function
23-02-2017
11
RGB
B
R
G
Cor pode ser representada pelo conjunto de 3 intensidades distintas (R,G,B).
PS = br + bg + bb
• Used in electrostatic and ink-jet plotters that deposit pigment on paper
• Cyan, magenta, and yellow are complements of red, green, and blue, respectively
• White (0, 0, 0), black (1, 1, 1)
B
G
R
Y
M
C
1
1
1
Magenta
Red
Yellow Green
Cyan
Blue
Black
(minus green)
(minus blue)
(minus red)
CMYK Model: K (black) is used
as a primary color to save ink
deposited on paper => dry quicker
- popularly used by printing press
CMY Models
23-02-2017
12
YUV
Y – luma, brightness, luminancia U, V – chrominance , crominância
Variantes: Y’UV, YCbCr, YPbPr
Ideia: Y = R + G + B -> imagem monocromática
U = Y-B V = Y-R R = Y-V B = Y-U G = Y-R-B
Vantagens: • Recetor monocromático pode usar apenas canal Y • Resolução dos Canais U e V pode ser reduzida ….
Y’UV
Y’ – gamma corrected Y
23-02-2017
13
Quantidade de informação
• Image Memory Size
• Image Byte Size
• [Image File Size]
Quantidade de memória necessária para armazenar a imagem sem compressão:
M = NPix * PS = NC * NL * PS
Ficheiro de Imagem
Cabeçalho pode conter: • Identificador de formato. • Número de linhas e de colunas. • Formato de píxel • Resolução (densidade de píxels) • Relação de Aspeto • Tipo de compressão • Data • Autor • …
Dimensão do ficheiro (FS):
header Pixel Array
FS = Header + M =
= Header + NPix * PS =
= Header + NC * NL * PS
23-02-2017
14
Múltiplos
Nome Símbolo Valor
kibi Ki 210 = 10241
mebi Mi 220 = 10242 = 1 048 576
gibi Gi 230 = 10243 = 1 073 741 824
tebi Ti 240 = 10244 ≈ 1 099 109
pebi Pi 250 = 10245 ≈ 1 125 1012
exbi Ei 260 = 10246 ≈ 1 152 1015
zebi Zi 270 = 10247 ≈ 1 180 1018
yobi Yi 280 = 10248 ≈ 1 208 1021
Nome Símbolo Valor
quilo k 103 = 10001
mega M 106 = 10002
giga G 109 = 10003
tera T 1012 = 10004
peta P 1015 = 10005
exa E 1018 = 10006
zetta Z 1021 = 10007
yotta Y 1024 = 10008
File Formats: GIF
GIF(GIF87a,GIF89a):
Graphics Interchange Format (GIF) devised by the UNISYS Corp. and Compuserve, initially for transmitting graphical images over phone lines via modems.
Uses the Lempel-Ziv Welch algorithm (compression).
Supports only 8-bit (256) color images.
Supports interlacing
GIF89a supports simple animation
28
23-02-2017
15
File Formats: JPEG
JPG or JPEG.
A standard for photographic image compression created by the Joint Photographics Experts Group
Takes advantage of limitations in the human vision system to achieve high rates of compression
Lossy compression which allows user to set the desired level of quality/compression
29
TIFF
TIFF: Tagged Image File Format
Stores many different types of images (e.g., monochrome, grayscale, 8-bit & 24-bit RGB, etc.)
Developed by the Aldus Corp. in the 1980's and later supported by Microsoft
TIFF is a lossless format (when not utilizing the new JPEG tag which allows for JPEG compression)
It does not provide any major advantages over JPEG and is not as user-controllable it appears to be declining in popularity
30
23-02-2017
16
BMP
BMP: Windows BitMap Picture:
A system standard graphics file format for Microsoft Windows.
It is capable of storing 1, 4, 8, 16, 24 or 32 bit/pixel.
Used in PC Paintbrush and many other programs.
31
XBM
XBM: X-windows BitMap
Primary graphics format for the X Window system
Supports 24-bit color bitmap
Many public domain graphic editors, e.g., xv
Used in X Windows for storing icons, pixmaps, backdrops, etc.
32
23-02-2017
17
PNG
PNG: Portable Network Graphics Designed to replace the older and simpler GIF format W3C recommendation and ISO standard Features:
• Main image types: o Truecolor: 24 or 48 bits/pixel (as TIFF). o Grayscale: 1, 2, 4, 8 or 16 bits/pixel. o Palette-based: 1, 2, 4, or 8 bits/pixel (similar to GIF).
• Alpha channels (variable transparency) • Gamma correction • Two-dimensional interlacing (for progressive display) • Lossless compression (5-25% better than GIF)
Shortcomings: • No Animation
33
Relação de Aspecto
• Display Aspect Ratio (DAR)
• Image Aspect Ratio (IAR)
Relação entre a dimensão horizontal e vertical de uma imagem ou de um dispositivo.
DAR = W:H
• Storage Aspect Ratio (SAR)
SAR = NC:NL
23-02-2017
18
Relação de Aspecto
Relação de Aspecto de pixel
• Pixel Aspect Ratio (PAR)
• Relação entre a dimensão horizontal e vertical de um pixel.
Normalmente: PAR 1 NLNC
HW
NCH
NLW
NLH
NCW
NL linhas
W
pw
ph
Y
NC colunas
H
H
W
p
pPAR
23-02-2017
19
PAR <-> DAR
Quando PAR = 1:1 => DAR = SAR = NC:NL
NL
NCPARDAR
NC
NLDAR
NLNC
DAR
NLNC
HWPAR
PAR = DAR / SAR
4:3 -> 16:9
23-02-2017
20
Resolução
http://en.wikipedia.org/wiki/Display_resolution
ImageMagick
Conjunto de ferramentas para edição não interactiva de imagens
• Código aberto
• Usável na maioria dos sistemas operativos
• API para maioria das linguagens de programação
• Suporta mais de 100 formatos (PPM, GIF, JPEG, PDF, PhotoCD, PNG, Postscript, SVG, TIFF, …)
www.imagemagick.org
23-02-2017
21
ImageMagick
Animate animate an image sequence on any X server.
Compare mathematically and visually annotate the difference between an image and its reconstruction.
Composite overlap one image over another.
Conjure interpret and execute scripts written in the Magick Scripting Language (MSL).
Convert convert between image formats as well as resize an image, blur, crop, despeckle, dither, draw on, flip, join,
re-sample, and much more.
Display display an image or image sequence on any X server.
Identify describe the format and characteristics of one or more image files.
Import save any visible window on an X server and outputs it as an image file. You can capture a single window,
the entire screen, or any rectangular portion of the screen.
Mogrify resize an image, blur, crop, despeckle, dither, draw on, flip, join, re-sample, and much more. Mogrify
overwrites the original image file, whereas, convert writes to a different image file.
Montage create a composite image by combining several separate images. The images are tiled on the composite
image optionally adorned with a border, frame, image name, and more.
Stream copies one or more pixel components of the image or portion of the image to your choice of storage
formats. It writes the pixel components as they are read from the input image a row at a time.
Transparency
- Blending colors
- Alpha Blending
- Transparency
23-02-2017
22
Chapter 12
Opaque drawing (overwriting)
Drawing a rectangle or image:
• Source: color of rectangle or image
• Destination: pixels in frame buffer
Source written into Destination
Source overwrites Destination
Blending vs. Over writing
Instead of over writing
• D S
Compute a new value for D
• based on current D and S
• D f (D Ad , S As)
23-02-2017
23
Blender Hardware
B
G
R
ALU
Buff
Frame Buffer (D) Blending Function
Source Color (S)
As :Source Blending Factor AD :Destination Blending Factor
AD
As
Blending Functions / Factors
Blending Functions
Add
Sub
-Sub
Copy Destination
Copy Source
Max
Min
Blending Factors
One
Zero
Constant
SrcAlpha
DestAlpha
1 - SrcAlpha
1 - DestAlpha
23-02-2017
24
Example: Simple blending
Draw a blue rectangle (no blending)
Define:
• Source blend factor:
• Destination blend factor:
• Blending function: Add
Draw a red rectangle:
As = (0.7, 0.7, 0.7)
Ad = (0.2, 0.2, 0.2)
D ← D 0.2 + S 0.7
Dr ← Dr 0.2 + Sr 0.7
Dg ← Dg 0.2 + Sg 0.7
Db ← Db 0.2 + Sb 0.7
Blending images
70% + 30% =
D ← P1 0.7 + P2 0.3
D ← P1
D ← D 0.7 + P2 0.3
P1 P2 D
23-02-2017
25
Blending and Alpha Channel
Store blending factor as part of color • Instead of Color = (r, g, b)
• Include a 4th channel: (r, g, b, α)
• Pixel called RGBA, RGBα or 32 bits RGB
α cannot affect pixel color directly • (r, g, b) changes pixel directly
• α used as o source blend factor (As)
o…
Blending colors using Alpha is called: • Alpha Blending
As = α RGB alpha
32 bit pixel values
Compositing with Alpha blending
+ =
X + Y = S
X1!=green X5
…
green
X2=green
green
X3!=green
green
X4=green
green
0000h FFFFh 0000h FFFFh
=? =? =? =?X1 X2 X3 X4
0000h FFFFh 0000h FFFFh
X1 0000h X3 0000h
pandn pandn pandn pandn
Y1 Y2 Y3 Y4
0000h FFFFh 0000h FFFFh
0000h Y2 0000h Y4
pand pand pand pand
α
α X (1-α) Y
S=α X + (1-α) Y
23-02-2017
26
Alpha as: Opacity
When: o Source Blend Factor oDestination Blend Factor
oBlend Function: Add
Alpha is opacity • Alpha = 1
oDestination is over-written
• Alpha = 0 o Source is completely invisible!
Transparency Example
Draw a normal blue rectangle • Pixel color (Destination)
o Dr Dg Db = (0.1, 0.1, 0.8)
Blending setting: • Source blend: As = Sα
• Destination blend: Ad = (1 - Sα)
• Blending Function: Add
Now, a red rectangle with • Source Color:
o Sr Sg Sb Sα = (0.9, 0.1, 0.1, 0.8)
23-02-2017
27
Transparency with Alpha Blending
bf rgbrgbrgb )1(
Solid back color
Transparent front color with opacity
Multiple Transparency
32122111
3222111
111
)1()1()1(
])1([)1(
)1(
rgbrgbrgbrgb
rgbrgbrgbrgb
brgrgbrgb
Solid back color
Transparent color (rgb1)with opacity 1
1
2
3
Transparent color (rgb2)with opacity 2
rgb'
23-02-2017
28
Blending Alphas
bff
bbfff rgbrgbrgb
)1(
)1(
Transparent back color with opacity b Transparent front color with opacity f
Process in either front to back or back to front order But can’t insert surface between them later. Requires alpha channel on the destination.
Alpha Buffer
A
B
G
R
ALU
Frame Buffer (D)
Blending Function
23-02-2017
29
Premultiply alpha
bff
bbfff rgbrgbrgb
)1(
)1(
Transparent back color with opacity b Transparent front color with opacity f
Notice - rgb always appears multiplied by it’s
Can store rgb’s as premultiplied by
Transparency in OpenGL
glEnable(GL_BLEND);
glBlendEquation(GL_FUNC_ADD);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
// Draw polygons with alpha values set
glDisable(GL_BLEND);
23-02-2017
30
alpha channel
Encodes transparency (or pixel coverage):
• Alpha = 1: opaque object (complete coverage)
• Alpha = 0: transparent object (no coverage)
• 0<Alpha<1: semi-transparent (partial coverage)
Example: alpha = 0.7
Partial coverage or semi-transparency
Compositing - example
23-02-2017
31
Alpha mask prodution
Problem Definition:
• The separation of an image C into
oA foreground object image Co,
o a background image Cb,
o and an alpha matte
• Co and can then be used to composite the foreground object into a different image
Hard problem
• Background subtraction unknown
• For movies/TV, manual segmentation of each frame is infeasible
Chroma Key
23-02-2017
32
Blue Screen
Blue Screen matting
Most common form of matting in TV studios & movies
Petros Vlahos invented blue screen matting in the 50s. His Ultimatte® is still the most popular equipment. He won an Oscar for lifetime achievement.
A form of background subtraction: • Need a known background • Compute alpha as SSD(C,Cb) > threshold
o Or use Vlahos’ formula: = 1-p1(B-p2G)
• Hope that foreground object doesn’t look like background o no blue ties!
• Why blue? • Why uniform?
23-02-2017
33
Chroma Key Equipment
The Ultimatte
p1 and p2
23-02-2017
34
Semi-transparent mattes
Requires true alpha matte, which involves semi-transparency • Alpha between 0 and 1
3D compositing
23-02-2017
35
Imagens com Alfa
Alguns formatos de armazenamento de imagens digitais podem incluir o Canal Alfa. Exemplo: PNG
1 píxel: RGBA 8 + 8 + 8 + 8 = 32 bits 16 milhões de cores * 256 níveis de transparência. O formato GIF suporta a identificação de uma cor transparente.
256 cores = 255 cores opacas + 1 transparente
Top Related