Advanced OpenGL Rendering Assignment 2: Image Processing with Cg Shaders, Assignments of Computer Science

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

Pre 2010

Uploaded on 03/10/2009

koofers-user-duw
koofers-user-duw 🇺🇸

9 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Spring 2006
22C:196 Advanced OpenGL Rendering
Assignment 2
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.
Turn a color image into grayscale by computing the luminance, using the equation: 0.3R+ 0.59G+ 0.11 B
A3×3box filter, centered at the current pixel. (A simple average of 9 pixels)
A5×5box filter, centered at the current pixel. (A simple average of 25 pixels)
A7×7box filter, centered at the current pixel. (A simple average of 49 pixels)
A3×3median filter, centered at the current pixel. (See below)
A5×5Gaussian filter centered at the current pixel. (See below)
A3×3Sobel filter centered at the current pixel. (See below)
A5×5Laplace filter centered at the current pixel. (See below)
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!
pf3

Partial preview of the text

Download Advanced OpenGL Rendering Assignment 2: Image Processing with Cg Shaders and more Assignments Computer Science in PDF only on Docsity!

Spring 2006

22C:196 Advanced OpenGL Rendering

Assignment 2

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.

  • Turn a color image into grayscale by computing the luminance, using the equation: 0. 3 ∗R +0. 59 ∗G+0. 11 ∗B
  • A 3 × 3 box filter, centered at the current pixel. (A simple average of 9 pixels)
  • A 5 × 5 box filter, centered at the current pixel. (A simple average of 25 pixels)
  • A 7 × 7 box filter, centered at the current pixel. (A simple average of 49 pixels)
  • A 3 × 3 median filter, centered at the current pixel. (See below)
  • A 5 × 5 Gaussian filter centered at the current pixel. (See below)
  • A 3 × 3 Sobel filter centered at the current pixel. (See below)
  • A 5 × 5 Laplace filter centered at the current pixel. (See below)

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:

  • Order the 9 pixels from the 3 × 3 region from darkest to lightest
  • Return the median color (i.e., the 5th lightest or 5th darkest).

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 (x, y) = 24P (x, y) +

f or(i,j) 6 =(x,y) −^1 P^ (i, j)

  • Weight (x, y) by 16, weight (x ± 1 , y) and (x, y ± 1) by -2, weight (x ± 1 , y ± 1), (x ± 2 , y) and (x, y ± 2) by -1. Weight all other pixels in the 5 × 5 region by 0.

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.