Lesson 5 – Images PV227 – GPU Rendering Jiˇrí Chmelík, Jan ˇCejka Fakulta informatiky Masarykovy univerzity 27. 10. 2015 PV227 – GPU Rendering (FI MUNI) Lesson 5 – Images 27. 10. 2015 1 / 22 Outline 1 Introduction 2 Post-processing effects Gray Scale Negative Thresholding Blurring Convolution PV227 – GPU Rendering (FI MUNI) Lesson 5 – Images 27. 10. 2015 2 / 22 DevIL library for working with images, simplifies loading textures to OpenGL, download built SDK at http://openil.sourceforge.net/ (http://downloads.sourceforge.net/openil/ DevIL-SDK-x86-1.7.8.zip). PV227 – GPU Rendering (FI MUNI) Lesson 5 – Images 27. 10. 2015 3 / 22 DevIL (cont.) update VC++ Directories (taken care of ;-)), pass data from DevIL to OpenGL. PV227 – GPU Rendering (FI MUNI) Lesson 5 – Images 27. 10. 2015 4 / 22 Image Processing image effects applied to a texture, may be used as post-process on the framebuffer, gray scale, negative, thresholding, blurring, general convolution. PV227 – GPU Rendering (FI MUNI) Lesson 5 – Images 27. 10. 2015 5 / 22 Texture Setup same way as in fixed OpenGL, texture unit ID passed to the sampler in the shader, rendered using two triangles (quad), camera setup so that only the quad is seen. Figure: Rendered texture PV227 – GPU Rendering (FI MUNI) Lesson 5 – Images 27. 10. 2015 6 / 22 Texture Read gvec texture(gsampler sampler, vec texCoord); gvec is the texel type, gsampler is the sampler type, texCoord is in [0, 1] range (coordinates according to texture dimension). ivec textureSize(gsampler sampler, int lod); ivec is the integer size of the texture (coordinates according to texture dimension) , gsampler is the sampler type, lod is level-of-detail (usually 0). PV227 – GPU Rendering (FI MUNI) Lesson 5 – Images 27. 10. 2015 7 / 22 Outline 1 Introduction 2 Post-processing effects Gray Scale Negative Thresholding Blurring Convolution PV227 – GPU Rendering (FI MUNI) Lesson 5 – Images 27. 10. 2015 8 / 22 Gray Scale Figure: Taken from wikimedia.org linear combination of the RGB channels into luma (intensity), texel is multiplied component-wise (dot product) with the weights. PV227 – GPU Rendering (FI MUNI) Lesson 5 – Images 27. 10. 2015 9 / 22 Gray scale (cont.) several options for choosing the weights, NTSC weights: 0.299, 0.587, 0.114. Figure: Grayscale PV227 – GPU Rendering (FI MUNI) Lesson 5 – Images 27. 10. 2015 10 / 22 Outline 1 Introduction 2 Post-processing effects Gray Scale Negative Thresholding Blurring Convolution PV227 – GPU Rendering (FI MUNI) Lesson 5 – Images 27. 10. 2015 11 / 22 Negative Inversion of each color channel, alpha channel should not be inverted. Figure: Negative PV227 – GPU Rendering (FI MUNI) Lesson 5 – Images 27. 10. 2015 12 / 22 Texture Fetch in vec4 gl_FragCoord; available only in fragment shader contains the window-relative coordinates of the current fragment (x, y, z, 1/w). gvec texelFetch(gsampler sampler, ivec texCoord, int lod); perform a lookup of a single texel within a texture gvec is the texel type, gsampler is the sampler type, texCoord is in [0, textureSize] range (coordinates according to texture dimension), lod is level-of-detail (usually 0). PV227 – GPU Rendering (FI MUNI) Lesson 5 – Images 27. 10. 2015 13 / 22 Outline 1 Introduction 2 Post-processing effects Gray Scale Negative Thresholding Blurring Convolution PV227 – GPU Rendering (FI MUNI) Lesson 5 – Images 27. 10. 2015 14 / 22 Thresholding usually applied to gray scale images, assigns white to pixels above threshold, black otherwise. Figure: Thresholding PV227 – GPU Rendering (FI MUNI) Lesson 5 – Images 27. 10. 2015 15 / 22 Outline 1 Introduction 2 Post-processing effects Gray Scale Negative Thresholding Blurring Convolution PV227 – GPU Rendering (FI MUNI) Lesson 5 – Images 27. 10. 2015 16 / 22 Blurring averaging of the image, the amount of blur depends on the kernel size, blur type is controlled by the blurring weights, the weights must sum to 1. Figure: Gaussian 5x5 blur PV227 – GPU Rendering (FI MUNI) Lesson 5 – Images 27. 10. 2015 17 / 22 Outline 1 Introduction 2 Post-processing effects Gray Scale Negative Thresholding Blurring Convolution PV227 – GPU Rendering (FI MUNI) Lesson 5 – Images 27. 10. 2015 18 / 22 Convolution Figure: Taken from illinois.edu used to compute any linear filter, (f ∗ g)(t) ≡ ∞ −∞ f(τ)g(t − τ)dτ, (f ∗ g)(t) ≡ ∞ −∞ f(τ)g(t − τ). PV227 – GPU Rendering (FI MUNI) Lesson 5 – Images 27. 10. 2015 19 / 22 Sharpening inverse of blurring (subtraction of neighbourhood), the amount of sharpening depends on the kernel size, sharpen type is controlled by the convolution weights, the weights must sum to 1. Figure: Sharpening 3x3 PV227 – GPU Rendering (FI MUNI) Lesson 5 – Images 27. 10. 2015 20 / 22 Edge Detection detects changes in intensity, preferably blur the image before edge detection, detection type is controlled by the convolution kernel, the weights must sum to 0. Figure: Laplacian edge detection PV227 – GPU Rendering (FI MUNI) Lesson 5 – Images 27. 10. 2015 21 / 22 More PV131: Digital Image Processing, PA166: Advanced Methods of Digital Image Processing, PA170: Digital Geometry, PA171: Digital filtering, PA172: Image Acquisition Principles, PA173: Mathematical Morphology, . . . PV227 – GPU Rendering (FI MUNI) Lesson 5 – Images 27. 10. 2015 22 / 22