solvingPuzzles
solvingPuzzles

Reputation: 8889

Setting pixel values in Nvidia NPP ImageCPU objects?

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:

Upvotes: 3

Views: 1210

Answers (3)

solvingPuzzles
solvingPuzzles

Reputation: 8889

For 1-channel (e.g. 32f_C1), this approach works:

hostKernel.pixels(0,0) = -1;

Upvotes: 0

Frank Jargstorff
Frank Jargstorff

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

Steenstrup
Steenstrup

Reputation: 644

To assign values to the pixel/matrix:

hostKernel.pixels(0,0)[0].x = -1;

Upvotes: 1

Related Questions