Welcome to Problem Set #1.
I'm Chin Hun and I'm your TA for the class.
Today I will be walking you through Problem Set #1.
And for Problem Set #1, our goal is convert an image from color to black and white.
To convert an image from color to black and white,
we first have to understand how colored digital images are represented.
The most common format is to specify how much red, green, and blue is presented at each pixel.
Each color is called a channel.
Zero means that a color is fully absent, whereas 255 means that color is fully saturated.
Therefore, if at a pixel all three channels—red, green, and blue—
are zero means that pixel is black, like such.
Or if all three channels—red, green, and blue—are 255 that pixel is fully white,
just like the background of this slide.
So how are pixels represented in CUDA?
In CUDA code each pixel is represented as an unsigned char4 struct.
This structure has four unsigned char components named x, y, z, and w.
X is your red channel, Y is your green channel, Z is your blue channel, and W is your alpha channel.
The fourth component, char W here, is reserved for the Alpha channel,
which carries the transparency information.
We will ignore this component throughout our homework,
as this does not pertain to transforming the image from color to greyscale.
How do we convert a color image to a black and white image?
One possibility was simply to take the average of all of the three color channels.
For example, add R to G to B—
the channels R stands for red, G stands for green, and B stands for blue—
and simply divide it by three.
But it turns out that our eyes don't respond to all colors equally.
We're more sensitive to the color green than red and more sensitive to the color red than to the color blue.
Taking into account our varying sensitivities to the different color channels,
we are going to use this following formula instead.
We are going to multiply the color channel red by 0.299,
we are going to multiply the color channel green by 0.587,
and we are going to multiply the color channel blue by 0.114.
So let's look at Problem Set #1,
and let's look at the code that you will actually have to write for this assignment.
For Problem Set #1, you have two jobs that you have to do.
For the first part, your job is to fill in this RGBA to greyscale function.
We will pass you in an array of uchar4 which represents the pixel in the color image,
and your job is to convert each pixel in this 2D array into an intensity value
that you will write back to this 1D array called greyImage.
You will follow the formula that we talked about in the previous slide, as seen here.
In part two, the kernel's already filled in for you but with incorrect dimensions and spot is empty.
So your job for part two is to fill in the body of the kernel
and to correct the dimension of block size and grid size.
We have included reference code that performs the same calculation of serial on the CPU for your reference,
and if you have any questions or if you run into any problems,
feel free to post on the forums, and I'll be there to help you.
Lastly, I would like to thank Eric Elson of Royal Caliber and Mike Roberts
for their fantastic job with writing the homeworks.
They have also written the script for this video today as well,
so thank you Eric and Mike.