OpenCL Heterogenenous Program For Image Processing - ColorSpace Conversion BGR-HSV, HSV-BGR, BGR-GRAY
OpenCL Heterogenenous Program For Image Processing - ColorSpace Conversion BGR-HSV, HSV-BGR, BGR-GRAY
Pi19404
January 20, 2013
Contents
Contents
OpenCL Parallel Programming for Color Conversion
0.1 Introduction . . . . . . . 0.2 Color Space Conversion 0.3 OPENCL Program . . . 0.4 Code . . . . . . . . . . . References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2
2 3 4 5 6
Data parallelism is one of ways to achieve parallelism wherein data is distributed across various computation units. In a multiprocessor system executing a single set of instructions (SIMD), data parallelism is achieved when each processor performs the same task on different pieces of distributed data. The Color Conversion is a pixel level operation.The task or set of operations to be performed for color conversion on each pixel is the same.Thus data parallelism can be achieved for color conversion by assigning each pixel to a computation unit and same task is performed by each computation unit. OpenCLTM is the rst open, royalty-free standard for cross-platform, parallel programming of modern processors found in personal computers, servers and handheld/embedded devices. Open Computing Language (OpenCL) is a framework for writing programs that execute across heterogeneous platforms consisting of central processing units (CPUs), graphics processing units (GPUs), DSPs and other processors. OpenCL includes a language (based on C99) for writing kernels (functions that execute on OpenCL devices), plus application programming interfaces (APIs) that are used to dene and then control the platforms. OpenCL provides parallel computing using task-based and data-based parallelism. In the present document we describe the details of OpenCL APIs but how OpenCL is
2|7
A color model is an abstract mathematical model describing the way colors can be represented as tuples of numbers. RGB is a example of color model wherein each color is uniquely represented by a tuple 3 numbers ( R, G, B). Another example of color model is HSV(Hue,Saturation,Value) . HSV color model is hexacone representation of points in an RGB color model. Let (X,Y,Z) represent the axis of right handed co-ordinate system and axis of heacone lie about the Z axis. The angle around the Z axis corresponds to Hue.The radial distance of point on the from the axis corresponds to saturation and distance along the Z axis from the origin corresponds to Value. HSV color model can be obtained by transformation from RGB color space. Each unique RGB tuple has unique mapping to point in HSV color space and numerically each HSV tuple describe a unique color in RGB color space. HSV exhibits cylindrical geometry with hue, their angular dimension, starting at the red primary at 0, passing through the green primary at 120 and the blue primary at 240, and then wrapping back to red at 360. Chroma is relative distance of point from origin wrt to maximum distance. M = max( R, G, B) m = min( R, G, B) C = Mm Hue is the angular distance where the point lies and can be expressed as undened, if C = 0 GB mod 6, if M = R C H = B R if M = G C + 2, R G if M = B C + 4, H = 60 H Value is the largest component of color V=M (1) (2) (3)
(4)
(5)
3|7
if C = 0 otherwise
(6) (7)
The Transformation of HSV to BGR can be expressed as Given a color with hue H [0, 360), saturation S [0, 1], and value V [0, 1], The chroma is calculated as. C = V S HSV H 60 X = C (1 | H mod 2 1|)
H =
(8) (9)
( R1 , G1 , B1 ) =
(0, 0, 0) (C, X, 0) ( X, C, 0)
if H is undened if 0 H < 1 if 1 H < 2 if 2 H < 3 if 3 H < 4 if 4 H < 5 if 5 H < 6 (11) (12) (10)
m = VC
( R, G, B) = ( R1 + m, G1 + m, B1 + m)
The BGR to GRAY Conversion can be expressed as G = 0.30 R + 0.59 G + 0.11 B
All these operations are pixel level operations and can be parallelized. each computation unit(thread) will operate on one pixel and implement the desirable conversion.
0.3 OPENCL Program
The parallel program consists of two parts the host code and kernel code. The host code is executed on standard CPU device while kernel code is executed on a parallel computing device (SIMD processor). The parallel device may CPUs,GPUs,DSPs etc (processor which supports SIMD architecture) The job of the host application is to submit work to device. A work item is a basic unit of execution of device usually executed by a thread. The kernel is the code to
4|7
The code consits of two parts the host code and the device code. Host side code uses OpenCv APIs to read the image from video le and demonstrates the calling of the kernel code for BGR-HSV,HSV-BGR and BGR-GRAY. Code is available in repository https://code.google.com/p/m19404/source/browse/ OpenCL-Image-Processing/ColorConversion/
5|7
Bibliography
Bibliography
[1] OpenCL. url: http://www.khronos.org/opencl/. [2] OpenCV color conversion. url: http://www.shervinemami.info/colorConversion. html.
6|7
Bibliography
Bibliography
[1] OpenCL. url: http://www.khronos.org/opencl/. [2] OpenCV color conversion. url: http://www.shervinemami.info/colorConversion. html.
7|7