RGBA to Gray image conversion with CUDA 5

In this article we will demonstrate a simple conversion from RGBA to grayscale image using CUDA 5, we will build on a previous example of a simple CUDA kernel. For example, the following RGB picture of flowers

flowers

will look like this after running the filter:

flowers_copy

and to execute the application we will call it like this:

This code will work with RGBA images where each channel (Red, Green, Blue, and Alpha) is represented by one byte (8-bits) and a range of values between 0 and 255 (2^8 – 1) for a total of 4-bytes per pixel.

Gray scale images are represented by a single intensity value per pixel where each pixel is only 1 byte, so after conversion we will have an image with only one channel and a pixel size of 1 byte.

Human eyes are more sensitive to green and least to blue. For that reason we will use weighted formula:

I = 0.2126 * R + 0.7152 * G + 0.0722 * B

Please read more here.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: