TIOVX User Guide
vx_tutorial_image_histogram.c File Reference
#include <stdio.h>
#include <VX/vx.h>
#include <TI/tivx.h>
#include <utility.h>

Go to the source code of this file.

Macros

#define IN_FILE_NAME   "${VX_TEST_DATA_PATH}/colors.bmp"
 Input file name.
 
#define OUT_FILE_NAME   "${VX_TEST_DATA_PATH}/vx_tutorial_image_histogram_out.bmp"
 Output file name.
 

Functions

vx_image convert_distribution_to_image (vx_distribution distribution, uint32_t width, uint32_t height)
 Convert distribution given as input to image. More...
 
void vx_tutorial_image_histogram ()
 Tutorial Entry Point. More...
 

Detailed Description

Create a distribution from an image then convert the to an image.

In this tutorial we learn the below concepts,

  • How to create OpenVX context, OpenVX image data object and OpenVX distribution data object
  • How to read a BMP file and load the pixel values into the image data object
  • How to query the image data object for attributes like width, height
  • How to create OpenVX node and associate it with previously created graph
  • How to schedule OpenVX graph for execution then execute the graph
  • How to query the node data object for attributes like width, height
  • How to query the graph data object for attributes like number of nodes and parameters
  • How to read pixel values from an image data object and save it as a BMP file
  • How to cleanup all created resources and exit the OpenVX application

To include OpenVX interfaces include below file

#include <VX/vx.h>

To include TI OpenVX extensions include below file

#include <TI/tivx.h>

Follow the comments in the function vx_tutorial_image_histogram() to understand this tutorial

As part of this tutorial, we create few utility functions as listed below. These functions will be used in subsequent tutorials to display node and graph attributes.

Utility function Description
convert_distribution_to_image() Converts a distribution data object to an image data object

Definition in file vx_tutorial_image_histogram.c.

Function Documentation

◆ convert_distribution_to_image()

vx_image convert_distribution_to_image ( vx_distribution  distribution,
uint32_t  width,
uint32_t  height 
)

Convert distribution given as input to image.

Parameters
distribution[in] Distribution to be converted to image
width[in] Width of distribution
height[in] Height of distribution
Returns
Image data object converted from distribution.







- Create OpenVX image object.

Creates an OpenVX image object of 'width' x 'height' and having data format 'df'.

/
image = vxCreateImage(context, width, height, (vx_df_image)VX_DF_IMAGE_U8);


- Query distribution attributes.

Queries distribution for number of bins
/
status = vxQueryDistribution(distribution, (vx_enum)VX_DISTRIBUTION_BINS, &num_bins, sizeof(vx_size));


- Copy distribution.

Copy distribution to array
/
vxCopyDistribution(distribution,
(void**)&histogram_data[0],


- Map image patch.

Allows direct access to rectangular patch of image object plane
/
status = vxMapImagePatch(image,
&rect,
0,
&map_id,
&image_addr,
(void**)&data_ptr,


- Unmap image patch.
/
vxUnmapImagePatch(image, map_id);


- Release image object.

Since we are done with using this image object, release it
/

Definition at line 396 of file vx_tutorial_image_histogram.c.

◆ vx_tutorial_image_histogram()

void vx_tutorial_image_histogram ( )

Tutorial Entry Point.
























- Define objects that we wish to create in the OpenVX application.

A vx_context object is defined which is used as input parameter for all subesquent OpenVX object create APIs

/
vx_context context;
vx_image in_image = NULL, out_image = NULL;
vx_distribution histogram = NULL;













































- Create OpenVX context.

This MUST be done first before any OpenVX API call. The context that is returned is used as input for subsequent OpenVX APIs

/
context = vxCreateContext();











































- Create OpenVX graph.

/
graph = vxCreateGraph(context);









































- Create image object.

Follow the comments in tivx_utils_create_vximage_from_bmpfile() to see how a vx_image object is created and filled with RGB data from BMP file IN_FILE_NAME







































- Show image attributes.

Follow the comments in show_image_attributes() to see how image attributes are queried and displayed.





































- Create OpenVX distribution.

Creates distribution with parameters num_bins (256), offset (0) and range (256)

/
histogram = vxCreateDistribution(context, num_bins, 0, 256);



































Below is equivalent of doing node0 = vxHistogramNode(graph, in_image, histogram);

/
refs, sizeof(refs)/sizeof(refs[0])
);

































- Verify graph object.

Verifies that all parameters of graph object are valid.

/
status = vxVerifyGraph(graph);


export graph to dot file, which can be coverted to jpg using dot tool
/
tivxExportGraphToDot(graph, ".", "vx_tutorial_image_histogram");





























- Show graph attributes.

Follow the comments in show_graph_attributes() to see how graph attributes are queried and displayed.



























- Show node attributes.

Follow the comments in show_node_attributes() to see how node attributes are queried and displayed.

























- Schedule graph.

Schedules graph for future execution. vxVerifyGraph must return VX_SUCCESS before this function will pass.

/























- Wait graph.

Waits for graph to complete.

/
vxWaitGraph(graph);





















- Show graph attributes.

Follow the comments in show_graph_attributes() to see how graph attributes are queried and displayed.



















- Show node attributes.

Follow the comments in show_node_attributes() to see how node attributes are queried and displayed.

















- Show image attributes.

Follow the comments in show_image_attributes() to see how image attributes are queried and displayed.

/















- Save image object to bitmap file OUT_FILE_NAME.

Follow the comments in tivx_utils_save_vximage_to_bmpfile() to see how data in vx_image object is accessed to store pixel values from the image object to BMP file OUT_FILE_NAME













- Release image object.

Since we are done with using this image object, release it

/
vxReleaseImage(&out_image);











- Release image object.

Since we are done with using this image object, release it

/
vxReleaseImage(&in_image);









- Release distribution object.

Since we are done with using this distribution object, release it

/







- Release node object.

Since we are done with using this node object, release it

/
vxReleaseNode(&node0);





- Release graph object.

Since we are done with using this graph object, release it

/



- Release context object.

Since we are done using OpenVX context, release it. No further OpenVX API calls should be done, until a context is again created using vxCreateContext()

/
vxReleaseContext(&context);

Definition at line 127 of file vx_tutorial_image_histogram.c.