Reputation: 8889
In the Nvidia Performance Primitives (NPP) image processing examples in the CUDA SDK distribution, images are typically stored on the CPU as ImageCPU
objects, and images are stored on the GPU as ImageNPP
objects.
boxFilterNPP.cpp is an example from the CUDA SDK that uses these ImageCPU
and ImageNPP
objects.
When using a filter (convolution) function like nppiFilter
, it makes sense to define a filter as an ImageCPU
object. However, I see no clear way setting the values of an ImageCPU
object.
npp::ImageCPU_32f_C1 hostKernel(3,3); //allocate space for 3x3 convolution kernel
//want to set hostKernel to [-1 0 1; -1 0 1; -1 0 1]
hostKernel[0][0] = -1; //this doesn't compile
hostKernel(0,0) = -1; //this doesn't compile
hostKernel.at(0,0) = -1; //this doesn't compile
How can I manually put values into an ImageCPU
object?
Notes:
nppiFilter
in the code snippet; I'm just mentioning nppiFilter
as a motivating example for writing values into an ImageCPU
object.ImageCPU
object, because nppiFilterBox
is a special case of nppiFilter
that uses a built-in gaussian smoothing filter (probably something like [1 1 1; 1 1 1; 1 1 1]).Upvotes: 3
Views: 1210
Reputation: 8889
For 1-channel (e.g. 32f_C1
), this approach works:
hostKernel.pixels(0,0) = -1;
Upvotes: 0
Reputation: 11
You're saying: "When using a filter (convolution) function like nppiFilter, it makes sense to define a filter as an ImageCPU object."
This is false and a bad idea. Image data is usually stored in "line-padded" format and the image classes shipped with the CUDA SDK samples for NPP do use specialized 2D memory allocators that add padding bytes to the end of each line. That way the first pixel each line lands on a 64-byte aligned address. This is done for performance reasons (on CPUs and GPUs alike).
The kernel arrays used for primitives like nppiFilter on the other hand need to be tightly packed. Which is why the code shown will not work.
Upvotes: 1
Reputation: 644
To assign values to the pixel/matrix:
hostKernel.pixels(0,0)[0].x = -1;
Upvotes: 1