

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A university assignment for a spring 2006 opengl course, focusing on writing cg shaders for various image processing filters. Students are required to create a program that loads an image, applies filters using cg shaders, and allows users to select filters through a menu. Filters include grayscale conversion, box filters, median filter, gaussian filter, sobel filter, and laplace filter.
Typology: Assignments
1 / 3
This page cannot be seen from the preview
Don't miss anything!


Due: Tuesday, March 28th at 11:59pm
Goal: Use Cg to write a number of simple shaders. Learn how to use multiple passes, where intermediate results are written to a texture that is used as input in later passes. The application is a simple image-processing program.
Problem 1 (50 points): Write a simple OpenGL program that loads an image from a PPM file (or any other standard file format) and displays it on screen. Using a menu, allow the user to either reload the image or apply one of the following filters to the currently displayed image. (Note: The “currently displayed” image may already have another filter applied, that is the user can select multiple filters to apply sequentially.) These filters should be applied using Cg shaders, though you may split more complex filters into multiple passes.
NOTE: Please include a README file describing the platform your program runs on as well how to compile your program. If you do not include all the models with your submission, tell me where the models must be for your program to find them.
NOTE: Post images from this assignment on your web page. Send me a link to your web page, if you have not already done so!
Median Filtering:
For a 3 × 3 median filter, the idea is to:
For this assignment, you may assume that the input is a grayscale image. If it is not, your program should return some plausible result (like picking just one RGB channel to order the pixels, or first applying a RGB to grayscale conversion).
Gaussian Filtering:
A Gaussian function centered at the origin has the form:
G(x) =
σ
2 π
e−x
(^2) / 2 σ 2 (1)
Typically, σ is selected so that only pixels inside the sampling region (i.e., the 5 × 5 filter) have a significant contribution, so a discrete 1D filter over inputs P (x − 2), P (x − 1), P (x), P (x + 1), and P (x + 2) approximates the filtered result F (x) by:
F (x) = 1 σ
2 π
x∑+
i=x− 2
P (i) e−(i−x)
(^2) / 2 σ 2 (2)
Since the Gaussian is a separable filter, it may be first applied in x, then independently in y. In other words, the first pass would compute a temporary value T (x, y) using a 1D filter over the pixels P (x − 2 , y), P (x − 1 , y), P (x, y), P (x + 1, y), and P (x + 2, y). Then the second pass would compute the final filtered result F (x, y) using a 1D filter over the pixels T (x, y − 2), T (x, y − 1), T (x, y), T (x, y + 1), and T (x, y + 2).
σ values less than 1. 5 would be appropriate for a 5 × 5 filter. I would suggest using σ = 1. Note that changing σ affects the blur in the final image.
Laplace Filtering:
For a 5 × 5 Laplace filter, you may choose one of two options:
f or(i,j) 6 =(x,y) −^1 P^ (i, j)
Notice that in both cases, the sum of the weights is 0. However, since the final result can be either positive or negative, you should add 0.5, so both positive and negative pixels will be visible.