Jetson Inference
DNN Vision Library

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

Classes

class  imageLoader
 Load an image or set of images from disk into GPU memory. More...
 
class  imageWriter
 Save an image or set of images to disk. More...
 

Functions

template<typename T >
bool loadImage (const char *filename, T **ptr, int *width, int *height)
 Load a color image from disk into CUDA memory, in uchar3/uchar4/float3/float4 formats with pixel values 0-255. More...
 
bool loadImage (const char *filename, void **output, int *width, int *height, imageFormat format)
 Load a color image from disk into CUDA memory, in uchar3/uchar4/float3/float4 formats with pixel values 0-255. More...
 
bool loadImageRGBA (const char *filename, float4 **ptr, int *width, int *height)
 Load a color image from disk into CUDA memory with alpha, in float4 RGBA format with pixel values 0-255. More...
 
bool loadImageRGBA (const char *filename, float4 **cpu, float4 **gpu, int *width, int *height)
 Load a color image from disk into CUDA memory with alpha, in float4 RGBA format with pixel values 0-255. More...
 
template<typename T >
bool saveImage (const char *filename, T *ptr, int width, int height, int quality=95, const float2 &pixel_range=make_float2(0, 255))
 Save an image in CPU/GPU shared memory to disk. More...
 
bool saveImage (const char *filename, void *ptr, int width, int height, imageFormat format, int quality=95, const float2 &pixel_range=make_float2(0, 255))
 Save an image in CPU/GPU shared memory to disk. More...
 
bool saveImageRGBA (const char *filename, float4 *ptr, int width, int height, float max_pixel=255.0f, int quality=100)
 Save a float4 image in CPU/GPU shared memory to disk. More...
 

Detailed Description

Loading and saving image files from disk.

Function Documentation

◆ loadImage() [1/2]

template<typename T >
bool loadImage ( const char *  filename,
T **  ptr,
int *  width,
int *  height 
)

Load a color image from disk into CUDA memory, in uchar3/uchar4/float3/float4 formats with pixel values 0-255.

Supported image file formats by loadImage() include:

  • JPG
  • 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]ptrReference to pointer that will be set to the shared CPU/GPU buffer containing the image that will be allocated. This buffer will be allocated by loadImage() 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.

◆ loadImage() [2/2]

bool loadImage ( const char *  filename,
void **  output,
int *  width,
int *  height,
imageFormat  format 
)

Load a color image from disk into CUDA memory, in uchar3/uchar4/float3/float4 formats with pixel values 0-255.

Supported image file formats by loadImage() include:

  • JPG
  • 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]ptrReference to pointer that will be set to the shared CPU/GPU buffer containing the image that will be allocated. This buffer will be allocated by loadImage() 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.

◆ loadImageRGBA() [1/2]

bool loadImageRGBA ( const char *  filename,
float4 **  ptr,
int *  width,
int *  height 
)

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

See also
loadImage() for more details about parameters and supported Image I/O formats.
Deprecated:
this overload of loadImageRGBA() is deprecated and provided for legacy compatbility. it is recommended to use loadImage() instead, which supports multiple image formats.

◆ loadImageRGBA() [2/2]

bool loadImageRGBA ( const char *  filename,
float4 **  cpu,
float4 **  gpu,
int *  width,
int *  height 
)

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

See also
loadImage() for more details about parameters and supported Image I/O formats.
Deprecated:
this overload of loadImageRGBA() is deprecated and provided for legacy compatbility. having separate CPU and GPU pointers for shared memory is no longer needed, as they are the same. it is recommended to use loadImage() instead, which supports multiple image formats.

◆ saveImage() [1/2]

template<typename T >
bool saveImage ( const char *  filename,
T *  ptr,
int  width,
int  height,
int  quality = 95,
const float2 &  pixel_range = make_float2(0,255) 
)

Save an image in CPU/GPU shared memory to disk.

Supported image file formats by saveImage() include:

  • JPG
  • PNG
  • TGA
  • BMP
Parameters
filenameDesired path of the image file to save to disk.
ptrPointer to the buffer containing the image in shared CPU/GPU zero-copy memory.
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 95 is used for high quality and moderate compression. Note that this quality parameter only applies to JPEG and PNG, other formats will ignore it.

◆ saveImage() [2/2]

bool saveImage ( const char *  filename,
void *  ptr,
int  width,
int  height,
imageFormat  format,
int  quality = 95,
const float2 &  pixel_range = make_float2(0, 255) 
)

Save an image in CPU/GPU shared memory to disk.

Supported image file formats by saveImage() include:

  • JPG
  • PNG
  • TGA
  • BMP
Parameters
filenameDesired path of the image file to save to disk.
ptrPointer to the buffer containing the image in shared CPU/GPU zero-copy memory.
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 95 is used for high quality and moderate compression. Note that this quality parameter only applies to JPEG and PNG, other formats will ignore it.

◆ saveImageRGBA()

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

Save a float4 image in CPU/GPU shared memory to disk.

See also
saveImage() for more details about parameters and supported Image I/O formats.
Deprecated:
saveImageRGBA() is deprecated and provided for legacy compatbility. it is recommended to use saveImage() instead, which supports multiple image formats.