Starting from:

$30

CUDA-Homework 5 OpenCL Programming Solved

A histogram is a statistic that shows frequency of a certain occurrence within a data set. The histogram of an image provides a frequency distribution of pixel values in the image. If the image is a color image, the pixel value can be the luminosity value of each pixel or the individual red (R), green (G), and blue (B). More about image histogram can be found at http://en.wikipedia.org/wiki/Image histogram.

In this problem, you need to use OpenCL to parallelize the implementation of the image histogram. The input/output is a bitmap image format, which stores R/G/B values of each pixel. See the reference code for how to read/write a bitmap file.

Below shows a serial implementation of the image histogram. The complete implementation can be downloaded at http://people.cs.nctu.edu.tw/∼ypyou/courses/PP-f19/assignments/HW5/image-histogram. cpp.

void histogram(Image *img,uint32_t R[256],uint32_t G[256],uint32_t B

[256]){ std::fill(R, R+256, 0); std::fill(G, G+256, 0); std::fill(B, B+256, 0);

for (int i = 0; i < img-size; i++){ RGB &pixel = img-data[i];

R[pixel.R]++;

G[pixel.G]++;

B[pixel.B]++;

}

}
1         Input/Output
1.1        Input
The program takes at least one command argument, which indicates the input file name.

./histogram test1.bmp test2.bmp test3.bmp



Figure 1: A sample image

1.2        Output
You will need to output a processed file, named hist <input filename.bmp, for each input file. You can use the reference code to output histogram file(s) directly.



Figure 2: the histogram of sample image

More products