OpenCL Heterogenenous program for Image Processing - ColorSpace conversion BGR-HSV,HSV-BGR,BGR-GRAY

Download OpenCL Heterogenenous program for Image Processing - ColorSpace conversion BGR-HSV,HSV-BGR,BGR-GRAY

Post on 07-Aug-2015

1.137 views

Category:

Documents

3 download

DESCRIPTION

OpenCL program for color space conversion and comparison with OpenCv code on CPU

TRANSCRIPT

Heterogeneous Parallel Programming Color Space Conversion For Image Processing Using OpenCLPi19404January 20, 2013

Contents

ContentsOpenCL Parallel Programming for Color Conversion0.1 Introduction . . . . . . . 0.2 Color Space Conversion 0.3 OPENCL Program . . . 0.4 Code . . . . . . . . . . . References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

22 3 4 5 6

OpenCL Parallel Programming for Color Conversion0.1 Introduction

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

OpenCL Parallel Programming for Color Conversionused efciently to attain the desired task. We will look at Color Space conversion BGR-HSV,HSV-BGR and BGR-GRAY for Image processing applications.0.2 Color Space Conversion

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

OpenCL Parallel Programming for Color ConversionSaturation is essential same as chroma scaled for values from 0 to 1. It is obtained by dividing chroma by maximum chroma for that value. S HSV = 0,C V,

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)

(0, C, X ) (0, X, C ) ( X, 0, C ) (C, 0, X )

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

OpenCL Parallel Programming for Color Conversionbe executed by work item/thread. A work group is a collection of work items and is executed on a compute units. A compute unit may be the number of cores on the CPUs and several work groups can reside on single compute units . The application runs on the host ,it job is to read data to and from device and submit the kernel to be executed,set the parameters of kernel etc In the present implementation we work on 320x240 images ,each work group is of size 16x16. Each thread of work group execute the kernel function for respective conversion. The execution asynchronous but is pipelined. The parallel algorithm on a 4 core CPU give at an average 3X 4X improvement over standard color conversion routines provided by OpenCv.It would be even higher improvement on a GPU device. This is a motivation to cast different types of image processing code in a parallel fashion to achieve higher throughput.0.4 Code

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