35
Image Warps and Halftoning

Image Warps and Halftoning

  • Upload
    nida

  • View
    41

  • Download
    0

Embed Size (px)

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

Citation preview

Page 1: Image Warps and Halftoning

Image Warps and Halftoning

Page 2: 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

Page 3: Image Warps and Halftoning

Image Warping

Overview Mapping

Forward Inverse

Resampling Point sampling Triangle filter (bilinear interpolation) Gaussian filter

Page 4: Image Warps and Halftoning

Mapping

Forward mapping: ),(),( yxvuM

),(),( 1 yxMvu Inverse mapping:

u

v

x

y

Page 5: Image Warps and Halftoning

Mapping Examples

Scale (separately in horizontal and vertical)

u

v

yvSxuS vu *;*

x

y

5.0

9.0

v

u

S

S

Page 6: Image Warps and Halftoning

Mapping Examples

Rotate counterclockwise θ degrees

u

v

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

x

y

o30

Page 7: Image Warps and Halftoning

Mapping Examples

General functions of u and v:yvuf

xvuf

y

x

),(

),(

swirl rainfisheye

Page 8: Image Warps and Halftoning

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

Page 9: Image Warps and Halftoning

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

Page 10: Image Warps and Halftoning

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

Page 11: Image Warps and Halftoning

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

Page 12: Image Warps and Halftoning

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

Page 13: Image Warps and Halftoning

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

Page 14: Image Warps and Halftoning

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

Page 15: Image Warps and Halftoning

Gaussian Filtering

Compute weighted sum of pixel neighborhood

Weights are normalized values of Gaussian function

(u,v)

w

Page 16: Image Warps and Halftoning

Filter Comparison

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

Point sampling Bilinear (triangle) Gaussian

Page 17: Image Warps and Halftoning

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

Page 18: Image Warps and Halftoning

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

}

}

Page 19: Image Warps and Halftoning

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

}

}

Page 20: Image Warps and Halftoning

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

}

}

Page 21: Image Warps and Halftoning

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

Page 22: Image Warps and Halftoning

Uniform Quantization

I

x

I(x)

P(x)

I(x)

P(x)

4 bits/pixel

Page 23: Image Warps and Halftoning

Uniform Quantization

Images with increasing bits per pixel

1 bit 2 bits 4 bits 8 bits

Page 24: Image Warps and Halftoning

Dealing with Quantization

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

Other techniques

Page 25: Image Warps and Halftoning

Classical Halftoning

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

I(x) P(x)

Page 26: Image Warps and Halftoning

Classical Halftoning

Newspaper imageNYT 9/21/99

Page 27: Image Warps and Halftoning

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

Page 28: Image Warps and Halftoning

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

Page 29: Image Warps and Halftoning

Random Dither

Randomize quantization error Errors appear as noise

I

x

I(x)

P(x)

I

x

I(x)

P(x)

))()(()( xrandxIroundxP

Page 30: Image Warps and Halftoning

Random Dither

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

Random dither – 1 bit/pixel

Page 31: Image Warps and Halftoning

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

Page 32: Image Warps and Halftoning

Ordered Dither

;),(),(

),(),()),((

;),(),(

;mod

;mod

yxIyxPelse

yxIyxPthenjiDeif

yxIyxIe

nyj

nxi

Page 33: Image Warps and Halftoning

Ordered Dither

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

Ordered dither – 1 bit/pixel

Page 34: Image Warps and Halftoning

Floyd-Steinberg Error Diffusion

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

1

Page 35: Image Warps and Halftoning

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