Download Raster Image Processing - Lecture Slides | CS 418 and more Study notes Computer Graphics in PDF only on Docsity!
Raster Image Processing
Image Processing
Construction of an image B as a function of an image A
- point processing: function of corresponding pixel only example: B [ x,y ] = sqrt( A [ x,y ])
- filtering: function of local neighborhood example: B [ x,y ] = average of neighbors of A [ x,y ]
- largely based on signal processing theory Image processing is a key component in:
- retouching scanned photos (e.g., sharpening)
- automatic segmentation (e.g., foreground vs. background)
- image compression, particularly lossy schemes like JPEG
- and many others …
Simple Point Processing Examples
Invert image: f(p) = 1− p
- for grayscale images, maps black to white and white to black
- affect on RGB images is a little less obvious Grayscale Inversion RGB Inversion
Simple Point Processing Examples
Power law transformation: f(p) = pk
- brightens if k < 1
- identity if k = 1
- darkens if k > 1 pk, k > 1 0 1 pk, k < 1 1 k = 2.8 k = 0.
Filtering Images
Naturally, we never want to sum over all the data
- want filter function f to be non-zero over a small area
- this area is the support of the filter It is common practice to represent filters with block templates
- an array of weights applied to local neighborhood
- it looks like a matrix but it’s not Here’s an example: a 3x3 grid, each cell having value 1/
- it replaces a pixel by the equally weighted average of its 3x neighborhood
- applying this will blur the image 1 1 1 1 1 1 1 1 1
Using Filter Templates
To compute the pixel at location (x,y) of the output image
- find corresponding (x,y) location of input image
- pick up local neighborhood matching filter template size
- weight each value of the input according to the value in the template
- add all the weighted values together 0.8 1.0 1. 1. 0.20.4 0. 0.4 1.0 (^) 0. 1 1 1 1 1 1 1 1 1
Blurring Filter Example
3x3 5x5 9x
Blurring Filter Example: A Closer Look
3x3 5x5 9x
Where Do Jaggies Come From?
Our primitives don’t evenly cover all the pixels they touch
- higher resolution helps because the pixels are smaller
- and the amount of fractional coverage is smaller What pixels do we fill in?
- all that are completely covered — artificially shrinks object
- all that are touched — artificially expands object
Getting Rid of Jaggies
The key idea is to use area-weighted sampling
- instead of simply filling in a pixel or not
- compute how much of the pixel is covered by the object
- and fill in with an appropriately scaled color
- e.g., 35% coverage = RGB (0.35, 0.35, 0.35) for a black object
- sounds familiar — a lot like alpha values
Getting Rid of Jaggies
When we introduce area-weighted sampling
- we transition from solid color jagged objects
- to more smoothly colored objects with multiple tones
- when viewed from a proper distance is hopefully smoother
Another Kind of Aliasing
Aliasing also arises when we try to sample small objects
- typically, pixels reflect samples taken at their centers
- when pixels are much smaller than objects, this matters little Objects may be smaller than pixels
- very small fragments
- very thin slivers Area sampling can fix this
- but we need to know what pixels they hit
- this will be a problem later with ray tracing
Antialiasing in Action
A Closer Comparison
Antialiasing with Ray Tracing
This is particularly convenient to accomplish in ray tracing
- we can supersample every pixel
- instead of shooting 1 ray through the center of each pixel
- we can shoot k rays through different parts of the same pixel Typically, we subdivide every pixel into a uniform grid
- and shoot a ray through each sub-pixel
- for better results, we typically jitter every sub-pixel sample
- rather than shooting ray through the center of the sub-pixel
- add a random offset away from the center
- this helps reduce aliasing by adding noise to the result
Applying Supersampling
3x3 supersampling 3x3 supersampling with jitter 1 sample/pixel 3x3= samples/pixel (without jitter)
Temporal Antialiasing
Our approach to spatial antialiasing is supersampling
- shoot multiple rays through a single pixel
- average all of the results together Recall that we can also see the results of temporal aliasing
- spoked wheel that rotates 7/8 around in 1 second
- snapshot every second — appears to be going backwards We can deal with this via supersampling as well
- shoot multiple rays for each pixel; average returned colors
- but distribute them through time rather than over space
- if the current frame is at time t
- shoot at rays at time t ± δ for various values of δ
- the result of this process is motion blur
Adaptive Supersampling
We don’t need to supersample at every pixel equally
- really only needed where there are sub-pixel discontinuities
- regions of smoothly changing color require no supersampling Best to supersample adaptively
- initially trace few rays
- say 1 or 4 per pixel
- compare color variation
- if low, stop shooting
- else, sample with more rays per pixel
- supersample resolution adapts to features of image
Texture Aliasing
Texture Aliasing
Recall the simple texture application method we discussed
- at each pixel we interpolate the correct texture coordinate
- and we retrieve the corresponding texel
- can lead to nasty aliasing Why is this? Consider mapping of pixel to texture
- may be mapped to several (fractional) texels
- but we’re only selecting one of them to use in the pixel
- this kind of point sampling results in aliasing Pixel Texture
Antialiasing with Image Pyramids
Image pyramids let us efficiently average large regions
- each texel in upper levels covers many base texels
- at level k they are the average of 2 k x 2 k^ texels
- can quickly assemble appropriate texels for averaging Fortunately, OpenGL can take care of most details
- gluBuild2DMipmaps() — automatically generate pyramid from base image
- control behavior with glTexParameter()
- OpenGL handles all filtering details during rasterization