1 / 35

Image Warps and Halftoning

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

nida
Download Presentation

Image Warps and Halftoning

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Image Warps and Halftoning

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

  3. Image Warping • Overview • Mapping • Forward • Inverse • Resampling • Point sampling • Triangle filter (bilinear interpolation) • Gaussian filter

  4. Mapping • Forward mapping: • Inverse mapping: v y u x

  5. v y u x Mapping Examples • Scale (separately in horizontal and vertical)

  6. v y u x Mapping Examples • Rotate counterclockwise θ degrees

  7. Mapping Examples • General functions of u and v: swirl fisheye rain

  8. 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); } } source image destination image (u,v) f (x,y)

  9. Multiple source pixels map to same destination No source pixels map to destination Forward Mapping • Iterate over source image • Need to resample destination • Generate one sample for each pixel • Complex to figure out where the nearest samples are for each pixel Rotate 30o

  10. 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); } } source image destination image (u,v) f-1 (x,y)

  11. Inverse Mapping • Iterate over destination image • Need to resample source • Generate source sample for each destination pixel • May oversample source, but oversampling is simpler than in forward case Rotate -30o

  12. Resampling • Need to evaluate source image at arbitrary (u,v) • (u,v) not generally integer coordinates • 3 methods • Point sampling • Triangle filtering • Gaussian filtering source image destination image (u,v) f-1 (x,y)

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

  14. (u1,v2) (u2,v2) a (u,v) b (u1,v1) (u2,v1) 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)

  15. Gaussian Filtering • Compute weighted sum of pixel neighborhood • Weights are normalized values of Gaussian function (u,v) w

  16. Filter Comparison • Tradeoffs • Fast but aliased (point sampling) • Slow and blurry (Gaussian) Point sampling Bilinear (triangle) Gaussian

  17. resample_src(u,v,w); w Image Warping Examples • Using reverse mapping and Gaussian filtering • 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) = resample_src(u,v,w); } } source image destination image (u,v) f-1 (x,y)

  18. 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); } }

  19. 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); } }

  20. 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); } }

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

  22. Uniform Quantization I(x) I I(x) P(x) x P(x) 4 bits/pixel

  23. Uniform Quantization • Images with increasing bits per pixel 1 bit 2 bits 4 bits 8 bits

  24. Dealing with Quantization • Halftoning techniques • Classical, or brute force halftoning • Dithering methods • Error Diffusion • Other techniques

  25. Classical Halftoning • First Variant • First, use dots of varying sizes to represent intensities • Size of dot proportional to intensity I(x) P(x)

  26. Classical Halftoning Newspaper image NYT 9/21/99

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

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

  29. I I(x) P(x) x Random Dither • Randomize quantization error • Errors appear as noise I I(x) P(x) x

  30. Random Dither Original – 8 bits/pixel Uniform quantization – 1 bit/pixel Random dither – 1 bit/pixel

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

  32. Ordered Dither

  33. Ordered Dither Original – 8 bits/pixel Random dither – 1 bit/pixel Ordered dither – 1 bit/pixel

  34. Floyd-Steinberg Error Diffusion • Quantization errors are spread over neighboring pixels to the right and below

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

More Related