如何在CUDA C中获取图像像素值以及图像高度和宽度? [英] How to get image pixel value and image height and width in CUDA C?

查看:71
本文介绍了如何在CUDA C中获取图像像素值以及图像高度和宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习CUDA,但我不知道如何在CUDA中获得图像属性.就像如何在CUDA中获取图像像素值或图像高度.我读了很多教程,它们都使用变量,宽度和高度指定了图像处理功能,但是我不知道如何获得图像的宽度和高度?

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?

推荐答案

宽度和高度从输入图像中获取.您需要一个从磁盘加载图像文件的功能(NVIDIA的一些示例将图像创建为头文件中的数组).

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).

在CUDA SDK中,您具有加载PGM图像文件的功能,即以无符号字符作为数据元素类型,即灰度图像.在示例中,您可以使用:

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);

然后,将数据复制到GPU全局内存或将图像绑定为纹理以与内核函数中的像素一起使用.

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

我建议您看一下CUDA SDK的 simpleTexture示例.

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

这篇关于如何在CUDA C中获取图像像素值以及图像高度和宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆