1

I am learning CUDA but I dont know how to get image properties in CUDA. Like how to get image pixel value or image Height in CUDA. I read a lot of tutorials and they all specify the function for image processing using the variable, width and height but I am not getting how they get the width and height of an image?

Prince John Wesley
  • 62,492
  • 12
  • 87
  • 94
coolarcs
  • 11
  • 2

1 Answers1

1

Width and Height are getting from the input image. You need a function to load your image file from disk (some examples from NVIDIA create the image as an array in a header file).

In the CUDA SDK you have functions to load PGM image files, i.e. with unsigned char as data element type., that is, a gray scale image. In example you can use:

// file handlers
char *image_filename = "image.pgm";
// images properties
unsigned int width;
unsigned int height;
// image array in CPU.
unsigned char* h_image = NULL;
// load PGM gray scale image file from disk
cutLoadPGMub(image_filename, &h_image, &width, &height);

Then, copy data to GPU Global Memory or bind the image as a texture to work with pixels in the kernel function.

I recommend you take a look at the simpleTexture example of the CUDA SDK.

pQB
  • 3,077
  • 3
  • 23
  • 49