c omputational a spects of
play

C OMPUTATIONAL A SPECTS OF C OMPUTATIONAL D IGITAL P HOTOGRAPHY P - PowerPoint PPT Presentation

CS 89.15/189.5, Fall 2015 C OMPUTATIONAL A SPECTS OF C OMPUTATIONAL D IGITAL P HOTOGRAPHY P HOTOGRAPHY Filtering & convolution Wojciech Jarosz wojciech.k.jarosz@dartmouth.edu Your Spanish castle illusions CS 89/189: Computational


  1. Nice and smooth: Gaussian After a slide by Frédo Durand ⊗ CS 89/189: Computational Photography, Fall 2015 59

  2. Gaussian formula http://en.wikipedia.org/wiki/Gaussian_function ae − r 2 2 σ 2 r is the distance to the center a is a normalization constant After a slide by Frédo Durand - I usually just normalize my kernels 
 after the fact σ is the standard deviation and controls the width of the Gaussian CS 89/189: Computational Photography, Fall 2015 60

  3. Gaussian formula http://en.wikipedia.org/wiki/Gaussian_function ae − r 2 2 σ 2 Gaussians have infinite support - >0 everywhere After a slide by Frédo Durand but are often truncated - consider Gaussian to be zero beyond e.g. 3σ - for computational tractability/efficiency CS 89/189: Computational Photography, Fall 2015 61

  4. Sharpening

  5. How can we sharpen? Blurring was easy Sharpening is not as obvious After a slide by Frédo Durand CS 89/189: Computational Photography, Fall 2015 63

  6. How can we sharpen? Blurring was easy Sharpening is not as obvious Idea: amplify the stuff not in the blurry image After a slide by Frédo Durand output = input + k*(input-blur(input)) CS 89/189: Computational Photography, Fall 2015 64

  7. Sharpening input blurred - = high pass After a slide by Frédo Durand input high pass sharpened +k* = image CS 89/189: Computational Photography, Fall 2015 65

  8. Sharpening: kernel view Recall f 0 = f + k ⇤ ( f � f ⌦ g ) f is the input f’ is a sharpened image After a slide by Frédo Durand g is a blurring kernel k is a scalar controlling the strength of sharpening CS 89/189: Computational Photography, Fall 2015 66

  9. Sharpening: kernel view Recall f 0 = f + k ⇤ ( f � f ⌦ g ) Denote δ the Dirac kernel (pure impulse) f = f ⊗ δ After a slide by Frédo Durand CS 89/189: Computational Photography, Fall 2015 67

  10. Sharpening: kernel view Recall f 0 = f + k ⇤ ( f � f ⌦ g ) f 0 = f ⌦ δ + k ⇤ ( f ⌦ δ � f ⌦ g ) f 0 = f ⌦ (( k + 1 ) δ � g ) After a slide by Frédo Durand Sharpening is also a convolution CS 89/189: Computational Photography, Fall 2015 68

  11. Sharpening kernel Note: many other sharpening kernels exist 
 (just like we saw multiple blurring kernels) Amplify the difference between a pixel and its neighbors f 0 = f ⌦ (( k + 1 ) δ � g ) After a slide by Frédo Durand blue: positive 
 red: negative CS 89/189: Computational Photography, Fall 2015 69

  12. Alternate interpretation out = input + k*(input-blur(input)) out = (1 + k)*input - k*blur(input) out = lerp(blur(input), input, 1+k) - linearly extrapolate from the blurred image “past” the original input image CS 89/189: Computational Photography, Fall 2015 70

  13. Questions? - = +k* = CS 89/189: Computational Photography, Fall 2015 71

  14. Unsharp mask

  15. Unsharp mask http://www.tech-diy.com/UnsharpMasks.htm Sharpening is often called “unsharp mask” because photographers used to sandwich a negative with a blurry positive film in order to sharpen After a slide by Frédo Durand CS 89/189: Computational Photography, Fall 2015 73

  16. After a slide by Frédo Durand CS 89/189: Computational Photography, Fall 2015 74 http://www.tech-diy.com/images/unsharp2.jpg

  17. Unsharp mask http://en.wikipedia.org/wiki/Unsharp_masking http://www.largeformatphotography.info/unsharp/ http://www.tech-diy.com/UnsharpMasks.htm http://www.cambridgeincolour.com/tutorials/unsharp-mask.htm After a slide by Frédo Durand CS 89/189: Computational Photography, Fall 2015 75

  18. Sharpening++

  19. Problem with excess Haloes around strong edges After a slide by Frédo Durand CS 89/189: Computational Photography, Fall 2015 77

  20. Oversharpening 1.7 11.2 8 8 coefficient After a slide by Frédo Durand -0.25 -0.3 original Sharpened (differences are accentuated; constant areas are left untouched). CS 89/189: Computational Photography, Fall 2015 78

  21. Bells and whistles Apply mostly on luminance Old Clarity in Lightroom/Adobe Camera Raw - As far as I understand, apply only for mid-tones - Avoids haloes around black and white points After a slide by Frédo Durand Only apply at edges - To avoid the amplification of noise Sharpening chrominance as well - But with very large blur CS 89/189: Computational Photography, Fall 2015 79

  22. Lightroom demo CS 89/189: Computational Photography, Fall 2015 80

  23. Oriented filters

  24. Gradient: finite difference horizontal gradient [[-1, 1]] vertical gradient: [[-1], [1]] After a slide by Frédo Durand CS 89/189: Computational Photography, Fall 2015 82

  25. Gradient: finite difference horizontal gradient [[-1, 1]] vertical gradient: [[-1], [1]] After a slide by Frédo Durand Horizontal gradient Vertical gradient Gradient magnitude (absolute value) (absolute value) CS 89/189: Computational Photography, Fall 2015 83

  26. Gradient e.g. Sobel [http://en.wikipedia.org/wiki/Sobel_operator]     − 1 0 + 1 − 1 − 2 − 1  ⊗ A  ⊗ A − 2 0 + 2 0 0 0 and G x = G y =   − 1 0 + 1 + 1 + 2 + 1 Horizontal gradient Vertical gradient After a slide by Frédo Durand Magnitude CS 89/189: Computational Photography, Fall 2015 84

  27. Cost

  28. Convolution cost? set output image to zero for all pixels (x,y) in output image for all (x’,y’) in kernel out(x,y) += input(x+x’,y+y’)*kernel(x’,y’) Cost? After a slide by Frédo Durand - O(input.width * input.height * kernel.width * kernel.height) CS 89/189: Computational Photography, Fall 2015 86

  29. Separable filters

  30. Separability Sometimes the 2D kernel can be decomposed into the convolution of a horizontal and a vertical filter. Example: box - g(x) = const if (-k ≤ x ≤ k) , 0 otherwise - g(x,y) = g(x) ⨂ g(y) After a slide by Frédo Durand - (separability doesn’t require the two 1D kernels to be the same, but it’s the case here) = ⨂ CS 89/189: Computational Photography, Fall 2015 88

  31. Separable box blur First blur horizontally using g(x) Then blur vertically using g(y) After a slide by Frédo Durand ⊗ ⊗ CS 89/189: Computational Photography, Fall 2015 89

  32. Separable convolution cost? for all pixels (x,y) in output image for all x’ in kernel outX(x,y) += input(x+x’,y)*kernel(x’) for all pixels (x,y) in output image for all y’ in kernel out(x,y) += outX(x,y+y’)*kernel(y’) After a slide by Frédo Durand Horizontal cost? O (input.width * input.height * kernel.width) Vertical cost? O (input.width * input.height * kernel.height) Total: O (input.width * input.height * (kernel.height + kernel.width)) Instead of: O (input.width * input.height * (kernel.height * kernel.width)) CS 89/189: Computational Photography, Fall 2015 90

  33. Good news Gaussians are separable too See Assignment 4! CS 89/189: Computational Photography, Fall 2015 91

  34. Box blur: Can we do even better? Can we get even better asymptotic complexity? Very large kernel sizes? CS 89/189: Computational Photography, Fall 2015 92

  35. Box blur: Can we do even better? pixel i Since 2D box is separable, let’s focus 
 on the 1D case The neighborhoods of pixel i and 
 neighborhood(i) pixel i+1 are very similar In fact, they only differ by 2 pixels, so: neighborhood(i+1) out(i+1) = out(i) + (in(i+k+1) – in(i-k+1))/(2k+1) Asymptotically independent of kernel size, depends only on image size! CS 89/189: Computational Photography, Fall 2015 93

  36. Box blur cost? Naïve: O (input.width * input.height * (kernel.height * kernel.width)) Separable: O (input.width * input.height * (kernel.height + kernel.width)) Incremental: O (input.width * input.height + (kernel.height + kernel.width)) O (input.width * input.height) After a slide by Frédo Durand CS 89/189: Computational Photography, Fall 2015 94

  37. Repeated convolution CS 89/189: Computational Photography, Fall 2015 95

  38. Repeated convolution CS 89/189: Computational Photography, Fall 2015 96

  39. Repeated convolution CS 89/189: Computational Photography, Fall 2015 97

  40. Repeated convolution CS 89/189: Computational Photography, Fall 2015 98

  41. Repeated convolution Convolution of two box kernels yields a tent kernel CS 89/189: Computational Photography, Fall 2015 99

  42. Repeated convolution Yet another convolution with a box yields piecewise quadratic CS 89/189: Computational Photography, Fall 2015 100

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend