## Are you sure?

This action might not be possible to undo. Are you sure you want to continue?

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

**OpenCL Parallel Programming for Color Conversion
**

0.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 deﬁne 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 API’s but how OpenCL is

2|7

**OpenCL Parallel Programming for Color Conversion
**

used efﬁciently 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 = M−m Hue is the angular distance where the point lies and can be expressed as undeﬁned, if C = 0 G−B 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 Conversion
**

Saturation 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 undeﬁned 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 = V−C

( 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 CPU’s,GPU’s,DSP’s 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 Conversion
**

be 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 CPU’s 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 type’s 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 API’s 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

- Polynomial Approximation of 1D signal
- Modified Canny Edge Detection
- polynomial approximation of a 2D signal
- OpenCL_Programming
- OpenCL 2D Convolution Using Separable Filters -Box Filter
- Single Passs Connected Component Labelling
- OpenCL Image Convolution Filter - Box Filter
- SubPixel Corner Localization Algorithm
- OpenCL Heterogeneous parallel program for Gaussian Filter
- Fast 2D Separable Symmetric/Anti-Symmmetric Convolution
- Android OpenCV First Application
- Android OpenCV Simple Face Tracker
- A linear channel filter
- Normalized convolution for image interpolation
- Introduction to OpenCL Programming (201005)
- Noise Models in Image processing
- Feature Detection - Overview of Harris Corner Feature Detection
- Android
- shape classification using Histogram of oriented gradients
- Android OpenCV Face detection
- Gesture Recognition using Hidden Markov Mode
- temporal filters
- Region Growing Algorithm For UnderWater Image Segmentation
- A simple color balance algorithm
- Uniform Color Quantization
- Image enhancement using Fusion
- Dense optical flow expansion based on polynomial basis approximation
- Control Limited Adaptive Histogram Equalization for Image Enhancement
- Spatio Temporal Feature extraction using harris 3d corner detector
- Adaptive Skin Color Detector

- Gaussian Multivariate Distribution -Part 1
- Multi Class Logistic Regression Training and Testing
- Compiling Native C/C++ library for Android
- Polynomial Approximation of 2D image patch -Part 2
- Dense optical flow expansion based on polynomial basis approximation
- Fast 2D Separable Symmetric/Anti-Symmmetric Convolution
- Continuous Emission Hidden Markov Model for sequence classification
- OpenVision Library Gaussian Mixture Model Implementation
- Adaptive Skin Color Detector
- ARM Neon Optimization for image interleaving and deinterleaving
- A linear channel filter
- Markov chain implementation in C++ using Eigen
- Implementation of discrete hidden markov model for sequence classification in C++ using Eigen
- C++ Const,Volatile Type Qualifiers
- Mean Shift Algorithm
- Local Binary Pattern
- C++ Inheritance
- Embedded Systems Programming with ARM on Linux - Blinking LED
- C++ Class Members and friends
- Integral Image for Computation of Mean And Variance
- Random Ferns for Patch Description
- C++ static members and function
- C++ virtual functions and abstract class
- Normalized convolution for image interpolation
- Tan and Triggs Illumination normalization
- Uniform Local Binary Pattern and Spatial Histogram Computation
- Mean Shift Tracking

Sign up to vote on this title

UsefulNot usefulClose Dialog## Are you sure?

This action might not be possible to undo. Are you sure you want to continue?

Loading