Jetson Inference
DNN Vision Library

Loading and saving image files from disk. More...

Functions

bool loadImageRGBA (const char *filename, float4 **cpu, float4 **gpu, int *width, int *height, const float4 &mean_pixel=make_float4(0, 0, 0, 0))
 Load a color image from disk into CUDA memory with alpha, in float4 RGBA format with pixel values 0-255. More...
 
bool saveImageRGBA (const char *filename, float4 *cpu, int width, int height, float max_pixel=255.0f, int quality=100)
 Save a float4 RGBA image to disk. More...
 
bool loadImageRGB (const char *filename, float3 **cpu, float3 **gpu, int *width, int *height, const float3 &mean_pixel=make_float3(0, 0, 0))
 Load a color image from disk into CUDA memory, in float3 RGB format with pixel values 0-255. More...
 
bool loadImageBGR (const char *filename, float3 **cpu, float3 **gpu, int *width, int *height, const float3 &mean=make_float3(0, 0, 0))
 Load a color image from disk into CUDA memory, in float3 BGR format with pixel values 0-255. More...
 

Detailed Description

Loading and saving image files from disk.

Function Documentation

◆ loadImageBGR()

bool loadImageBGR ( const char *  filename,
float3 **  cpu,
float3 **  gpu,
int *  width,
int *  height,
const float3 &  mean = make_float3(0, 0, 0) 
)

Load a color image from disk into CUDA memory, in float3 BGR format with pixel values 0-255.

Supported image file formats by loadImageBGR() include:

  • JPEG
  • PNG
  • TGA
  • BMP
  • GIF
  • PSD
  • HDR
  • PIC
  • PNM (PPM/PGM binary)

This function loads the image into shared CPU/GPU memory, using the functions from cudaMappedMemory.h

Parameters
[in]filenamePath to the image file to load from disk.
[out]cpuReference to pointer that will be set to the CPU buffer containing the image that will be allocated. This buffer will be allocated by loadImageRGBA() in CUDA mapped memory, so it is shared between CPU/GPU. cpu will be the pointer to this shared buffer in the CPU's address space. There is physically one buffer in memory.
[out]gpuReference to pointer that will be set to the GPU buffer containing the image that will be allocated. This buffer will be allocated by loadImageRGBA() in CUDA mapped memory, so it is shared between CPU/GPU. gpu will be the pointer to this shared buffer in the GPU's address space. There is physically one buffer in memory.
[in,out]widthPointer to int variable that gets set to the width of the image in pixels. If the width variable contains a non-zero value when it's passed in, the image is resized to this desired width. Otherwise if the value of width is 0, the image will be loaded with it's dimensions from the file on disk.
[in,out]heightPointer to int variable that gets set to the height of the image in pixels. If the height variable contains a non-zero value when it's passed in, the image is resized to this desired height. Otherwise if the value of height is 0, the image will be loaded with it's dimensions from the file on disk.
[in]mean_pixelMean pixel subtraction is applied using this specified color (mean pixel subtraction is typically performed before processing an image with neural networks). By default the value is zero, so no mean pixel subtraction is done.

◆ loadImageRGB()

bool loadImageRGB ( const char *  filename,
float3 **  cpu,
float3 **  gpu,
int *  width,
int *  height,
const float3 &  mean_pixel = make_float3(0, 0, 0) 
)

Load a color image from disk into CUDA memory, in float3 RGB format with pixel values 0-255.

Supported image file formats by loadImageRGB include:

  • JPEG
  • PNG
  • TGA
  • BMP
  • GIF
  • PSD
  • HDR
  • PIC
  • PNM (PPM/PGM binary)

This function loads the image into shared CPU/GPU memory, using the functions from cudaMappedMemory.h

Parameters
[in]filenamePath to the image file to load from disk.
[out]cpuReference to pointer that will be set to the CPU buffer containing the image that will be allocated. This buffer will be allocated by loadImageRGBA() in CUDA mapped memory, so it is shared between CPU/GPU. cpu will be the pointer to this shared buffer in the CPU's address space. There is physically one buffer in memory.
[out]gpuReference to pointer that will be set to the GPU buffer containing the image that will be allocated. This buffer will be allocated by loadImageRGBA() in CUDA mapped memory, so it is shared between CPU/GPU. gpu will be the pointer to this shared buffer in the GPU's address space. There is physically one buffer in memory.
[in,out]widthPointer to int variable that gets set to the width of the image in pixels. If the width variable contains a non-zero value when it's passed in, the image is resized to this desired width. Otherwise if the value of width is 0, the image will be loaded with it's dimensions from the file on disk.
[in,out]heightPointer to int variable that gets set to the height of the image in pixels. If the height variable contains a non-zero value when it's passed in, the image is resized to this desired height. Otherwise if the value of height is 0, the image will be loaded with it's dimensions from the file on disk.
[in]mean_pixelMean pixel subtraction is applied using this specified color (mean pixel subtraction is typically performed before processing an image with neural networks). By default the value is zero, so no mean pixel subtraction is done.

◆ loadImageRGBA()

bool loadImageRGBA ( const char *  filename,
float4 **  cpu,
float4 **  gpu,
int *  width,
int *  height,
const float4 &  mean_pixel = make_float4(0, 0, 0, 0) 
)

Load a color image from disk into CUDA memory with alpha, in float4 RGBA format with pixel values 0-255.

Supported image file formats by loadImageRGBA() include:

  • JPEG
  • PNG
  • TGA
  • BMP
  • GIF
  • PSD
  • HDR
  • PIC
  • PNM (PPM/PGM binary)

This function loads the image into shared CPU/GPU memory, using the functions from cudaMappedMemory.h

Parameters
[in]filenamePath to the image file to load from disk.
[out]cpuReference to pointer that will be set to the CPU buffer containing the image that will be allocated. This buffer will be allocated by loadImageRGBA() in CUDA mapped memory, so it is shared between CPU/GPU. cpu will be the pointer to this shared buffer in the CPU's address space. There is physically one buffer in memory.
[out]gpuReference to pointer that will be set to the GPU buffer containing the image that will be allocated. This buffer will be allocated by loadImageRGBA() in CUDA mapped memory, so it is shared between CPU/GPU. gpu will be the pointer to this shared buffer in the GPU's address space. There is physically one buffer in memory.
[in,out]widthPointer to int variable that gets set to the width of the image in pixels. If the width variable contains a non-zero value when it's passed in, the image is resized to this desired width. Otherwise if the value of width is 0, the image will be loaded with it's dimensions from the file on disk.
[in,out]heightPointer to int variable that gets set to the height of the image in pixels. If the height variable contains a non-zero value when it's passed in, the image is resized to this desired height. Otherwise if the value of height is 0, the image will be loaded with it's dimensions from the file on disk.
[in]mean_pixelMean pixel subtraction is applied using this specified color (mean pixel subtraction is typically performed before processing an image with neural networks). By default the value is zero, so no mean pixel subtraction is done.

◆ saveImageRGBA()

bool saveImageRGBA ( const char *  filename,
float4 *  cpu,
int  width,
int  height,
float  max_pixel = 255.0f,
int  quality = 100 
)

Save a float4 RGBA image to disk.

Supported image file formats by saveImageRGBA() include:

  • JPEG
  • PNG
  • TGA
  • BMP
  • HDR
Parameters
filenameDesired path of the image file to save to disk.
cpuPointer to the buffer containing the image in CPU address space.
widthWidth of the image in pixels.
heightHeight of the image in pixels.
max_pixelThe maximum pixel value of this image, by default it's 255 for images in the range of 0-255. If your image is in the range of 0-1, pass 1.0 as this value. Then the pixel values of the image will be rescaled appropriately to be stored on disk (which expects a range of 0-255).
qualityIndicates the compression quality level (between 1 and 100) to be applied for JPEG and PNG images. A level of 1 correponds to reduced quality and maximum compression. A level of 100 corresponds to maximum quality and reduced compression. By default a level of 100 is used for maximum quality and reduced compression. Note that this quality parameter only applies to JPEG and PNG, other formats will ignore it.