image warps and halftoning

Post on 12-Jan-2016

43 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

Image Warps and Halftoning. Image Warping. Scale Rotate Warp Basically, we have to move image pixels This is done by mapping the pixels from the source to the destination image (actually backwards) then resampling. warp. Source image. Destination image. Image Warping. Overview Mapping - PowerPoint PPT Presentation

TRANSCRIPT

Image Warps and Halftoning

Image Warping

Scale

Rotate

Warp

Basically, we have to move image pixels

This is done by mapping the pixels from the source to the destination image (actually backwards) then resampling

warpSource image

Destination image

Image Warping

Overview Mapping

Forward Inverse

Resampling Point sampling Triangle filter (bilinear interpolation) Gaussian filter

Mapping

Forward mapping: ),(),( yxvuM

),(),( 1 yxMvu Inverse mapping:

u

v

x

y

Mapping Examples

Scale (separately in horizontal and vertical)

u

v

yvSxuS vu *;*

x

y

5.0

9.0

v

u

S

S

Mapping Examples

Rotate counterclockwise θ degrees

u

v

yvuxvu )cos()sin(;)sin()cos(

x

y

o30

Mapping Examples

General functions of u and v:yvuf

xvuf

y

x

),(

),(

swirl rainfisheye

Forward Mapping

for (int u = 0; u < umax; u++) {for (int v = 0; v < vmax; v++) {

float x = fx(u,v);

float y = fy(u,v);

dst (x,y) = src(u,v);

}

}

f(u,v)

(x,y)

source image destination image

Forward Mapping

Rotate 30o

Multiple source pixels map to same destination

No source pixels map to destination

Need to resample destination Generate one sample for each pixel Complex to figure out where the nearest samples are for each pixel

Iterate over source image

Inverse Mapping

for (int x = 0; x < xmax; x++) {for (int y = 0; v < ymax; y++) {

float u = fx-1(x,y);

float v = fy-1(x,y);

dst (x,y) = src(u,v);

}

}

f-1(u,v)

(x,y)

source image destination image

Inverse Mapping

Rotate -30o

Need to resample source Generate source sample for each destination pixel May oversample source, but oversampling is simpler than in forward case

Iterate over destination image

Resampling

f-1(u,v)

(x,y)

source image destination image

Need to evaluate source image at arbitrary (u,v)(u,v) not generally integer coordinates3 methods Point sampling Triangle filtering Gaussian filtering

Point Sampling

Just find closest source pixel to each destination pixel

int iu = round(u);

int iv = round(v);dst(x,y) = src(iu, iv);

Simple, but causes aliasing

Rotate -30o

Triangle Filtering

Convolve four closest source pixels to desired (u,v) with triangle filter (bilinear interpolation)

Bilinear interpolation: a = lerp(src(u1,v2),src(u2,v2)) b = lerp(src(u1,v1),src(u2,v1)) dst(x,y) = lerp(a,b)

(u1,v1) (u2,v1)

(u1,v2) (u2,v2)

(u,v)

a

b

Gaussian Filtering

Compute weighted sum of pixel neighborhood

Weights are normalized values of Gaussian function

(u,v)

w

Filter Comparison

Tradeoffs Fast but aliased (point sampling) Slow and blurry (Gaussian)

Point sampling Bilinear (triangle) Gaussian

Image Warping Examples

Using reverse mapping and Gaussian filteringfor (int x = 0; x < xmax; x++) {

for (int y = 0; v < ymax; y++) {

float u = fx-1(x,y);

float v = fy-1(x,y);

dst (x,y) = resample_src(u,v,w);

}

}

f-1(x,y)

source image destination image

(u,v)

w

resample_src(u,v,w);

Scale

Scale(src,dst,sx,sy)float w = max(1/sx,1/sy);

for (int x = 0; x < xmax; x++) {

for (int y = 0; v < ymax; y++) {

float u = x/sx ;

float v = x/sy ;

dst (x,y) = resample_src(u,v,w);

}

}

Rotate

Rotate(src,dst,θ)for (int x = 0; x < xmax; x++) {

for (int y = 0; v < ymax; y++) {

float u = x*cos(-θ)- y*sin(-θ);

float v = x*sin(-θ)+ y*cos(-θ);

dst (x,y) = resample_src(u,v,w);

}

}

Swirl

Swirl(src,dst,θ,cx,cy)for (int x = 0; x < xmax; x++) {

for (int y = 0; v < ymax; y++)

float u =

(x-cx)*cos(-θ*|x-cx|)-

(y-cy)*sin(-θ*|y-cy|)+cx;

float v =

(x-cx)*sin(-θ*|x-cx|)+

(y-cy)*cos(-θ*|y-cy|)+cy;

dst (x,y) = resample_src(u,v,w);

}

}

Quantization Artifacts

Errors due to limited intensity resolution

Why? Frame buffers only have so many bits per channel Physical display devices have a limited dynamic range,

especially hard copy devices

Uniform Quantization

I

x

I(x)

P(x)

I(x)

P(x)

4 bits/pixel

Uniform Quantization

Images with increasing bits per pixel

1 bit 2 bits 4 bits 8 bits

Dealing with Quantization

Halftoning techniques Classical, or brute force halftoning Dithering methods Error Diffusion

Other techniques

Classical Halftoning

First Variant First, use dots of varying sizes to represent intensities Size of dot proportional to intensity

I(x) P(x)

Classical Halftoning

Newspaper imageNYT 9/21/99

Classical Halftoning

What if your display device can’t display produce multiple dot sizes? Use cluster of pixels Number of “on” pixels in cluster proportional to

intensity Trades spatial resolution for intensity resolution

Dithering

Algorithms to distribute errors among pixels Reduce objectionable regular artifacts Replace them with noise

Original – 8 bits/pixel Uniform quantization – 1 bit/pixel

Floyd-Steinberg error diffusion – 1 bit/pixel

Random Dither

Randomize quantization error Errors appear as noise

I

x

I(x)

P(x)

I

x

I(x)

P(x)

))()(()( xrandxIroundxP

Random Dither

Original – 8 bits/pixel Uniform quantization – 1 bit/pixel

Random dither – 1 bit/pixel

Ordered Dither

Patterned errors that try to minimize regular artifacts Recursively defined “Dither Matrix” stores pattern of thresholds

2/22/2/22/

2/22/2/22/

)2,2(4)1,2(4

)2,1(4)1,1(4

nnnn

nnnnn UDDUDD

UDDUDDD

20

132D

10280

614412

91113

513715

4D

Ordered Dither

;),(),(

),(),()),((

;),(),(

;mod

;mod

yxIyxPelse

yxIyxPthenjiDeif

yxIyxIe

nyj

nxi

Ordered Dither

Original – 8 bits/pixel Random dither – 1 bit/pixel

Ordered dither – 1 bit/pixel

Floyd-Steinberg Error Diffusion

Quantization errors are spread over neighboring pixels to the right and below

1

Floyd-Steinberg Error Diffusion

Original – 8 bits/pixel Random dither – 1 bit/pixel

Ordered dither – 1 bit/pixel

Floyd-Steinberg error diffusion – 1 bit/pixel

top related