TIOVX User Guide
vx_tutorial_image_extract_channel.c
Go to the documentation of this file.
1 /*
2 *
3 * Copyright (c) 2017 Texas Instruments Incorporated
4 *
5 * All rights reserved not granted herein.
6 *
7 * Limited License.
8 *
9 * Texas Instruments Incorporated grants a world-wide, royalty-free, non-exclusive
10 * license under copyrights and patents it now or hereafter owns or controls to make,
11 * have made, use, import, offer to sell and sell ("Utilize") this software subject to the
12 * terms herein. With respect to the foregoing patent license, such license is granted
13 * solely to the extent that any such patent is necessary to Utilize the software alone.
14 * The patent license shall not apply to any combinations which include this software,
15 * other than combinations with devices manufactured by or for TI ("TI Devices").
16 * No hardware patent is licensed hereunder.
17 *
18 * Redistributions must preserve existing copyright notices and reproduce this license
19 * (including the above copyright notice and the disclaimer and (if applicable) source
20 * code license limitations below) in the documentation and/or other materials provided
21 * with the distribution
22 *
23 * Redistribution and use in binary form, without modification, are permitted provided
24 * that the following conditions are met:
25 *
26 * * No reverse engineering, decompilation, or disassembly of this software is
27 * permitted with respect to any software provided in binary form.
28 *
29 * * any redistribution and use are licensed by TI for use only with TI Devices.
30 *
31 * * Nothing shall obligate TI to provide you with source code for the software
32 * licensed and provided to you in object code.
33 *
34 * If software source code is provided to you, modification and redistribution of the
35 * source code are permitted provided that the following conditions are met:
36 *
37 * * any redistribution and use of the source code, including any resulting derivative
38 * works, are licensed by TI for use only with TI Devices.
39 *
40 * * any redistribution and use of any object code compiled from the source code
41 * and any resulting derivative works, are licensed by TI for use only with TI Devices.
42 *
43 * Neither the name of Texas Instruments Incorporated nor the names of its suppliers
44 *
45 * may be used to endorse or promote products derived from this software without
46 * specific prior written permission.
47 *
48 * DISCLAIMER.
49 *
50 * THIS SOFTWARE IS PROVIDED BY TI AND TI'S LICENSORS "AS IS" AND ANY EXPRESS
51 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
52 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
53 * IN NO EVENT SHALL TI AND TI'S LICENSORS BE LIABLE FOR ANY DIRECT, INDIRECT,
54 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
55 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
56 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
57 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
58 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
59 * OF THE POSSIBILITY OF SUCH DAMAGE.
60 *
61 */
62 
63 
64 
94 #include <stdio.h>
95 #include <VX/vx.h>
96 #include <VX/vxu.h>
97 #include <utility.h>
98 
100 #define IN_FILE_NAME "${VX_TEST_DATA_PATH}/colors.bmp"
101 
103 #define OUT_FILE_NAME "${VX_TEST_DATA_PATH}/vx_tutorial_image_extract_channel_out.bmp"
104 
109 {
117  vx_context context;
118  vx_image in_image = NULL;
119  vx_image r_channel = NULL;
120  vx_image g_channel = NULL;
121  vx_image b_channel = NULL;
122  vx_image out_image = NULL;
124  vx_uint32 width, height;
125 
126  printf(" vx_tutorial_image_extract_channel: Tutorial Started !!! \n");
127 
135  context = vxCreateContext();
138  printf(" Loading file %s ...\n", IN_FILE_NAME);
139 
150  vxSetReferenceName((vx_reference)in_image, "INPUT");
158  show_image_attributes(in_image);
161  vxQueryImage(in_image, (vx_enum)VX_IMAGE_WIDTH, &width, sizeof(vx_uint32));
162  vxQueryImage(in_image, (vx_enum)VX_IMAGE_HEIGHT, &height, sizeof(vx_uint32));
163 
171  r_channel = vxCreateImage(context, width, height, (vx_df_image)VX_DF_IMAGE_U8);
174  vxSetReferenceName((vx_reference)r_channel, "R_CHANNEL");
175 
183  show_image_attributes(r_channel);
193  g_channel = vxCreateImage(context, width, height, (vx_df_image)VX_DF_IMAGE_U8);
196  vxSetReferenceName((vx_reference)g_channel, "G_CHANNEL");
197  show_image_attributes(g_channel);
198 
206  b_channel = vxCreateImage(context, width, height, (vx_df_image)VX_DF_IMAGE_U8);
209  vxSetReferenceName((vx_reference)b_channel, "B_CHANNEL");
210 
218  show_image_attributes(b_channel);
228  out_image = vxCreateImage(context, width, height, (vx_df_image)VX_DF_IMAGE_RGB);
231  vxSetReferenceName((vx_reference)out_image, "OUTPUT");
232 
240  show_image_attributes(out_image);
251  vxuChannelExtract(context, in_image, (vx_enum)VX_CHANNEL_R, r_channel);
252  vxuChannelExtract(context, in_image, (vx_enum)VX_CHANNEL_G, g_channel);
253  vxuChannelExtract(context, in_image, (vx_enum)VX_CHANNEL_B, b_channel);
263  vxuChannelCombine(context, b_channel, g_channel, r_channel, NULL, out_image);
266  printf(" Saving to file %s ...\n", OUT_FILE_NAME);
267 
285  vxReleaseImage(&in_image);
286  vxReleaseImage(&r_channel);
287  vxReleaseImage(&g_channel);
288  vxReleaseImage(&b_channel);
289  vxReleaseImage(&out_image);
300  vxReleaseContext(&context);
303  printf(" vx_tutorial_image_extract_channel: Tutorial Done !!! \n");
304  printf(" \n");
305 }
struct _vx_image * vx_image
vx_bool
vx_false_e
vx_status VX_API_CALL vxQueryImage(vx_image image, vx_enum attribute, void *ptr, vx_size size)
int32_t vx_enum
VX_DF_IMAGE_U8
vx_status VX_API_CALL vxReleaseContext(vx_context *context)
VX_CHANNEL_B
struct _vx_context * vx_context
struct _vx_reference * vx_reference
uint32_t vx_df_image
VX_DF_IMAGE_RGB
VX_IMAGE_WIDTH
vx_image VX_API_CALL vxCreateImage(vx_context context, vx_uint32 width, vx_uint32 height, vx_df_image color)
vx_status VX_API_CALL vxSetReferenceName(vx_reference ref, const vx_char *name)
#define IN_FILE_NAME
Input file name.
vx_status VX_API_CALL vxuChannelCombine(vx_context context, vx_image plane0, vx_image plane1, vx_image plane2, vx_image plane3, vx_image output)
vx_status VX_API_CALL vxuChannelExtract(vx_context context, vx_image input, vx_enum channel, vx_image output)
void show_image_attributes(vx_image image)
Show attributes of previously created image.
vx_image tivx_utils_create_vximage_from_bmpfile(vx_context context, const char *filename, vx_bool convert_to_gray_scale)
Create a image data object given BMP filename as input.
uint32_t vx_uint32
#define OUT_FILE_NAME
Output file name.
vx_context VX_API_CALL vxCreateContext()
VX_CHANNEL_G
vx_status tivx_utils_save_vximage_to_bmpfile(const char *filename, vx_image image)
Save data from image object to PNG file.
vx_status VX_API_CALL vxReleaseImage(vx_image *image)
void vx_tutorial_image_extract_channel()
Tutorial Entry Point.
VX_IMAGE_HEIGHT
VX_CHANNEL_R