C ++ AMP Gradient calculation using texture on a 16-bit image

I work with depth images obtained from kinect, which are 16 bits. I found some difficulties in creating my own filters due to the index or size of the images. I work with Textures because it allows me to work with any bit size of an image.

So, I am trying to calculate a light gradient to understand what is wrong, or why it does not work, as I expected.

You can see that something is wrong when I use y dir.

For x: Adqadok.png

For y: zn5MPfI.png

What is my code:

typedef concurrency::graphics::texture<unsigned int, 2> TextureData;
typedef concurrency::graphics::texture_view<unsigned int, 2> Texture

cv::Mat image = cv::imread("Depth247.tiff", CV_LOAD_IMAGE_ANYDEPTH);

//just a copy from another image
cv::Mat image2(image.clone() );


concurrency::extent<2> imageSize(640, 480);
int bits = 16;

const unsigned int nBytes = imageSize.size() * 2; // 614400


{
    uchar* data = image.data;

    // Result data
    TextureData texDataD(imageSize, bits);
    Texture texR(texDataD);


    parallel_for_each(
        imageSize,
        [=](concurrency::index<2> idx) restrict(amp)
    {
        int x = idx[0];
        int y = idx[1];

        // 65535 is the maxium value that can take a pixel with 16 bits (2^16 - 1)
        int valX = (x / (float)imageSize[0]) * 65535;
        int valY = (y / (float)imageSize[1]) * 65535;

        texR.set(idx, valX);
    });
    //concurrency::graphics::copy(texR, image2.data, imageSize.size() *(bits / 8u));
    concurrency::graphics::copy_async(texR, image2.data, imageSize.size() *(bits) );

    cv::imshow("result", image2);
    cv::waitKey(50);
}

Any help would be greatly appreciated.

+2
source share
1 answer

Your indices are swapped in two places.

int x = idx[0];
int y = idx[1];

, ++ AMP . , idx[0] , y. , "For x", , texR.set(idx, valY).

, .

int valX = (x / (float)imageSize[0]) * 65535;
int valY = (y / (float)imageSize[1]) * 65535;

imageSize[0] ( y), .

OpenCV, , cv::Mat. y 0, 0 , . Kinect , , .

, , , , index extent, .

+3

Source: https://habr.com/ru/post/1538651/


All Articles