1.6K views

Uploaded by pi194043

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

save

You are on page 1of 7

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

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 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

used 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

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 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

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 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

- OpenCL 2D Convolution Using Separable Filters -Box FilterUploaded bypi194043
- Fast 3D Extension of Fast Feature Detection for SpatioTemporal Corner DetectionUploaded bypi194043
- Feature Detection - Overview of Harris Corner Feature DetectionUploaded bypi194043
- polynomial approximation of a 2D signalUploaded bypi194043
- Polynomial Approximation of 1D signalUploaded bypi194043
- SubPixel Corner Localization AlgorithmUploaded bypi194043
- Single Passs Connected Component LabellingUploaded bypi194043
- OpenCL Image Convolution Filter - Box FilterUploaded bypi194043
- Fast Asymmetric Learning for Cascade Face Detection Training/Testing UtilityUploaded bypi194043
- A linear channel filterUploaded bypi194043
- Control Limited Adaptive Histogram Equalization for Image EnhancementUploaded bypi194043
- Fast 2D Separable Symmetric/Anti-Symmmetric ConvolutionUploaded bypi194043
- OpenCL Heterogeneous parallel program for Gaussian FilterUploaded bypi194043
- Introduction to OpenCL Programming (201005)Uploaded bykydya
- Normalized convolution for image interpolationUploaded bypi194043
- Gesture Recognition using Hidden Markov ModeUploaded bypi194043
- temporal filtersUploaded bypi194043
- Android OpenCV Face detectionUploaded bypi194043
- shape classification using Histogram of oriented gradientsUploaded bypi194043
- OpenCL_ProgrammingUploaded bywhitepearl91
- AMD Accelerated Parallel Processing OpenCL Programming GuideUploaded byJuliano Correa
- Modified Canny Edge DetectionUploaded bypi194043
- Noise Models in Image processingUploaded bypi194043
- Image enhancement using FusionUploaded bypi194043
- A simple color balance algorithmUploaded bypi194043
- Region Growing Algorithm For UnderWater Image SegmentationUploaded bypi194043
- Adaptive Skin Color DetectorUploaded bypi194043
- Spatio Temporal Feature extraction using harris 3d corner detectorUploaded bypi194043
- Dense optical flow expansion based on polynomial basis approximationUploaded bypi194043
- A detailed descriptions and results for different color constancy algorithmsUploaded bypi194043

- Modified Canny Edge DetectionUploaded bypi194043
- Polynomial Approximation of 2D image patch -Part 2Uploaded bypi194043
- Compiling Native C/C++ library for AndroidUploaded bypi194043
- Multi Class Logistic Regression Training and TestingUploaded bypi194043
- Gaussian Multivariate Distribution -Part 1Uploaded bypi194043
- ARM Neon Optimization for image interleaving and deinterleavingUploaded bypi194043
- A linear channel filterUploaded bypi194043
- Adaptive Skin Color DetectorUploaded bypi194043
- OpenVision Library Gaussian Mixture Model ImplementationUploaded bypi194043
- Fast 2D Separable Symmetric/Anti-Symmmetric ConvolutionUploaded bypi194043
- Continuous Emission Hidden Markov Model for sequence classificationUploaded bypi194043
- Dense optical flow expansion based on polynomial basis approximationUploaded bypi194043
- Implementation of discrete hidden markov model for sequence classification in C++ using EigenUploaded bypi194043
- Markov chain implementation in C++ using EigenUploaded bypi194043
- C++ InheritanceUploaded bypi194043
- Local Binary PatternUploaded bypi194043
- Mean Shift AlgorithmUploaded bypi194043
- C++ Const,Volatile Type QualifiersUploaded bypi194043
- Random Ferns for Patch DescriptionUploaded bypi194043
- Integral Image for Computation of Mean And VarianceUploaded bypi194043
- Embedded Systems Programming with ARM on Linux - Blinking LEDUploaded bypi194043
- C++ virtual functions and abstract classUploaded bypi194043
- C++ static members and functionUploaded bypi194043
- Uniform Local Binary Pattern and Spatial Histogram ComputationUploaded bypi194043
- Tan and Triggs Illumination normalizationUploaded bypi194043
- Normalized convolution for image interpolationUploaded bypi194043

- EAD Assignment 1Uploaded byNasmy Ayyash
- VB .NET Unit-3Uploaded byYashas Jain
- Tutorial Implementing a Service Provider.pdfUploaded byJORGE
- Magic Draw Data SheetUploaded bybasnetmilan
- Web Content Mining Using K-means AlgorithmUploaded byseunnuga93
- COBOL650Uploaded byanup_acharya007
- Modulo 2 - Clase 3.ppsxUploaded byArmando Cajahuaringa
- How to Use Script LogicUploaded byCarlos Eduardo Luminatti
- Java Jdeveloper for BeginnersUploaded byrajak_khan786
- Jairus Taka1Uploaded byJAirus Takay
- Event Handling in VBScriptUploaded byAjay Aj
- 3 1 4 vex whileifelseloopsUploaded byapi-325609547
- APEX4 Through the Eyes of Dimitri GielisUploaded byvasubbuscribd
- MSDN Magazine February 2011Uploaded byChiTownIT
- GPUsUploaded byeuardop
- SUM SP12 ProcessesUploaded byelsargan
- DES Avec JavaUploaded bymassi2962
- se-ct-1-answerUploaded byMary Joy Paclibar Bustamante
- Lexical and Syntax AnalysisUploaded byrtarak
- Chapter 1 QAUploaded byanupam20099
- Six Important .NET ConceptsUploaded byAnonymous 4UMGyEjTP
- QQUploaded byspris
- It 430 Mega File by Afaaq & FaizaUploaded byzahidwahla1
- Co RoutinesUploaded byMm
- Oracle PLSQL LabbookUploaded byshankar kumar
- Lecture 3 Problem SolvingUploaded byAhmed Abd El-Aziz Marzouk
- Aspire Quizzes With AnswersUploaded bymanziltakforme
- Resume Nitin Iit MadrasUploaded byJayaganesh Kalyanasundaram
- Paypal Website Payments Standard and IPN IntegrationUploaded byRahul Singh
- FTP in C#Uploaded bySatyabrota Das