Lab 8: Bilateral Image Filtering with Threads (5 Points)
Chris Tralie
Table of Contents
Overview / Logistics
The purpose of this lab is to get you practice using threads to speed up parallelizable code. You can obtain the starter code here:
git clone --recursive https://github.com/ursinus-cs174-s2022/Lab8_ImageThreads.git
The code layout is similar to that of the class exercise we did on image filters, except there is only one filter: the bilateral filter (explained more below). But it currently only runs on one thread, and it is very slow, so your job will be to put threads around it to speed it up.
When you are finished, upload a .zip file of your code to canvas, which should include the input and output images for your art contest, and a brief title and pseudonym for the art contest.
Learning Objectives
- Split up a parallelizable problem into sub-batches
- Use threads in C++ to speed up computation
Background: Bilateral Filter
A bilateral filter is an image filter designed to blur image features without blurring edges of the image. You can read more about it at this link from my graphics class (it's a great example of using GPU hardware to parallelize to a huge degree). For example, let's suppose we start with the following image, which has been provided with your code:
![](Lab8_ImageThreads/RockyMountain.png)
And let's suppose we issue the following command to blur by a spatial factor of (--s 5
; a larger number is more blurring)
Then we get this image, where everything is uniformly blurrier:
![](RockyMountainBlur.png)
On the other hand, if we specify some edge-based limitations with the parameter --b 0.05
(lower number is more preservation of edges), we get the following:
![](RockyMountainBilateralBlur.png)
Notice how the fine texture details of the mountain, road, and trees is lost, but we can still see very sharply the edge between the road and its surroundings and the edges between the mountain and the trees.
In fact, if we apply this filter multiple times, we can get a cartoon effect. Below is the result of blurring an image of Dr. Scoville three times in succession
![](drscoville_blurred.png)
And here's the succession of bilateral blurs that gave rise to that
![](drscoville_blurred_progressive.gif)
Here's another example with my brother's cats
![](cats_blurred.png)
And here's the succession of bilateral blurs that gave rise to that. Notice how the fine details of the fur go away, but the spots, eyes, and outlines of the heads are preserved
![](cats_blurred_progressive.gif)
Your Tasks
Below is what you have to do in this lab
Task 1: Parallelize with Threads (3 Points)
Speed up the code using threads. The program has been setup to take the number of threads as a command line parameter. If this is working properly, you should see an overall speedup. For example, on my computer, running
Takes 37693ms seconds, while running
takes 18956ms, for a speedup factor of about 2x, while running
only takes 6011ms, for a speedup factor of over 6x. Of course, to rigorously assess this, you would need to do many experiments and create a scatterplot since this is a random process, but it's fine just to run it a few times to get the gist.
Depending on how many corse you have on your computer, you may see a lesser speedup, but you should have at least two cores
NOTE: You won't have to use a mutex here, because you'll never be writing to the same pixels in parallel. Filtering images like this is an example of an embarrassingly parallelizable problem.
Task 2: Mandatory Art Contest (2 Points)
Use this program to make something creative. We will have a class wide art gallery, much like we did for homework 1. You can use a pseudonym if you're not comfortable using your real name. The winner will get 1 point of extra credit towards labs