Difference between revisions of "Image I/O & Framework"

From CUVI Wiki
Line 136: Line 136:


==Using CUVI with C==
==Using CUVI with C==
In C interface structure named CuviMat which offers same members as CuviImage and equivalent C-functions for initialization and data transfer. Every function in C starts with preficx 'cuvi' for example cuvi::arithmeticLogical::NOT() in C++ has coressponsing C function '''cuviNOT()'''
In C interface structure named CuviMat which offers same members as CuviImage and equivalent C-functions for initialization and data transfer. Every function in C starts with prefix 'cuvi' for example '''cuvi::arithmeticLogical::NOT()''' in C++ has coressponsing C function '''cuviNOT()'''


====I/O using CuviMat====
====I/O using CuviMat====

Revision as of 15:51, 27 April 2012

CUVI sdlksljfdks;dlks kdsldks

Using CUVI with C++

CUVI C++ interface uses various features of C++ including classes, namespaces and default arguments to provide ease of use. User has the freedom to use C++ specifics as well as C features of CUVI while using C++ compiler however is restricted to C-only features if using a C compiler.

CuviImage

CuviImage is a C++ class to hold image data on the device. It has all the essential members to hold image information as well as methods to create and move image to and from device. All the C++ functions in CUVI take CuviImage as input/output image argument. CuviImage creates an image on the GPU so you do not need to cater for manually copying the image to the GPU and then back to the CPU, this is catered by CuviImage.

Members

Member name Type Description
data void* Data pointer containing the image pixel values on device
width Cuvi32u Image width in pixels
height Cuvi32u Image height in pixels
pitch size_t Image pitch/widthstep in bytes
depth Cuvi32u Defines the data container for the image. A depth of '8' creates CuviImage of type Cuvi8u
dataBits Cuvi32u No. of bits containing image information. By default dataBits is equal to the depth of the image
nChannels Cuvi32u Number of channels in image
isSigned bool Specifies if the image also contains negative values. (float is an exception)
isInitialized bool Specifies if the image has successfully been created on the device
channelSequence CuviChannelSeq Specifies the arrangement of image channels like RGB and BGR

CuviImage methods helps create, copy and show images. All methods return CuviStatus except constructors and destructor which throws an exception in case of failure.

Methods

Method Description
CuviImage() Default constructor. Initializes all members with 0
CuviImage(CuviSize size, Cuvi32u depth, Cuvi32u channels); Creates a CuviImage of specified size, depth and channels. Throws exception if memory allocation on device fails.
CuviImage(const CuviImage&); Creates a copy of existing CuviImage
CuviImage(const CuviMat&); Creates a copy of existing CuviMat
CuviStatus upload(void* pSrcHost, size_t srcPitch, CuviStream* stream = NULL); Copy image data from host memory to CuviImage. This function also supports async operation
CuviStatus download(void* pDstHost, size_t dstPitch, CuviStream* stream = NULL); Copy image data from CuviImage to host memory.
CuviStatus show(char* title = "CUVI Image",int milliseconds = 0); Render CuviImage on screen for a specified amount of time
~CuviImage(); CuviImage destructor. Throws an exception in case of failure

I/O using CuviImage

//We start by assuming that user has an image named 'img' allocated on host

//Size of the image	
CuviSize size = cuviSize(img->width,img->height);

//Creating two empty CuviImage objects on device to hold input and output images
CuviImage* gimg = new CuviImage(size,img->depth,img->nChannels);
CuviImage* gout = new CuviImage(size,img->depth,img->nChannels);

//Populate input device image using the host image data
gimg->upload(img->imageData,img->widthStep);

//Calling a CUVI function that takes negative of the input image
cuvi::arithmeticLogical::NOT(gimg,gout);

//Shows the result on screen without copying the data to the host
gout->show("Negative");

//Copy back the results to an host image named 'output'
gout->download(output->imageData,output->widthStep);

//Freeing GPU Memory
delete gimg;
delete gout;

Namespaces

CUVI is divided in image processing modules based on functionality. These modules use separate namespace in CUVI C++ interface to increase readability and ease of use. The current CUVI version has following namespaces:

  • cuvi
    • arithmeticLogical
    • colorOpertions
    • computerVision
    • dataExchange
    • geometryTransforms
    • imageFiltering
    • imageStatistics
    • imageTransforms


Using CUVI with C

In C interface structure named CuviMat which offers same members as CuviImage and equivalent C-functions for initialization and data transfer. Every function in C starts with prefix 'cuvi' for example cuvi::arithmeticLogical::NOT() in C++ has coressponsing C function cuviNOT()

I/O using CuviMat

//We start by assuming that user has an image named 'img' allocated on host

//declaring variables
CuviSize size;
CuviMat* gimg, *gout;

//Size of the image	
size = cuviSize(img->width,img->height);

//Creating two empty CuviMat objects on device to hold input and output images
cuviCreateMat(&gimg,size,img->depth,img->nChannels);
cuviCreateMat(&gimg,size,img->depth,img->nChannels);

//Populate input device image using the host image data
cuviUploadData(gimg,img->imageData,img->widthStep,0);

//Calling a CUVI function that takes negative of the input image
cuviNOT(gimg,gout,0);

//Shows the result on screen without copying the data to the host
cuviShowMat("Negative",gout,0);

//Copy back the results to an host image named 'output'
cuviDownloadData(gout,output->imageData,output->widthStep,0);

//Freeing GPU memory
cuviDestroyMat(&gimg);
cuviDestroyMat(&gout);