Ask Your Question
2

Bilinear sampling from a GpuMat

asked 2012-07-23 03:57:42 -0600

tsc gravatar image

updated 2012-07-23 04:04:02 -0600

Hi everyone,

I'm writing a GPU-based shape/appearance model, for which I have to crop patches centered on given key points. The patches are square but not necessarily aligned with the image axes, so I cannot just use a rowRange/colRange. My plan is to create a fixed matrix of coordinate offsets, O:

O = [x1, x2, ..., xn; 
     y2, y2, ..., yn;
     1,  1,  ..., 1]

In Homogeneous coordinates. I will store this matrix on the GPU. When I want to sample a patch around X = [x, y, 1]^T, I simply transform the coordinates by a similarity transformation matrix M (which performs translation, rotation and scaling).

P = M * O

So P will again have the same layout as O, but with transformed coordinates.

Now for the question: Given a matrix P of coordinates, how can I sample an image f(x,y) at the coordinates in P in an efficient manner? The output should be a vector or matrix with the pixel values at the coordinates in P. I want to use bilinear sampling, which is a built in operation on the GPU (so it should be efficient). I suppose I could write a custom kernel for this, but I would think this is already in opencv somewhere. I searched the documentation but didn't find anything.

Alternatively, I could rotate/scale the whole image and then crop an axis-aligned patch, but this seems less efficient.

Thanks in advance

edit retag flag offensive close merge delete

Comments

"Alternatively, I could rotate/scale the whole image and then crop an axis-aligned patch, but this seems less efficient." - This exactly what I'm doing in my project, it might not be the most efficient way to do it, but it takes less than 2 millisecond to execute on my computer while image being 640x480.

XCoder gravatar imageXCoder ( 2012-07-23 04:14:37 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
3

answered 2012-07-23 09:40:03 -0600

tsc gravatar image

updated 2012-07-23 09:40:29 -0600

I've found the solution:

gpu::buildWarpAffineMaps - to build matrices of x and y coordinates containing the lookup coordinates

gpu::remap - to sample the image given the lookup coordinates

edit flag offensive delete link more

Comments

You could also accept your answer. :)

Philipp Wagner gravatar imagePhilipp Wagner ( 2012-07-23 13:43:41 -0600 )edit

It says I need >50 points to accept my answer. I'm new here :)

tsc gravatar imagetsc ( 2012-07-24 08:58:22 -0600 )edit

Ah didn't know it. Sorry! :)

Philipp Wagner gravatar imagePhilipp Wagner ( 2012-07-24 12:43:11 -0600 )edit

Question Tools

Stats

Asked: 2012-07-23 03:57:42 -0600

Seen: 803 times

Last updated: Jul 23 '12