0

can someone help me with how to loop through a CUDA kernel to average the corner pixels, border pixels and/or middle pixels of a Mat image?

I know that for the middle pixels I should do this:

                                            (src[threadIdx.x][ threadIdx.y] + 
                    src[threadIdx.x -1][ threadIdx.y -1]+
                    src[threadIdx.x -1][ threadIdx.y]+
                    src[threadIdx.x -1][ threadIdx.y + 1]+
                     src[threadIdx.x][ threadIdx.y - 1]+
                    src[threadIdx.x][ threadIdx.y + 1]+
                    src[threadIdx.x +1][ threadIdx.y - 1]+
                    src[threadIdx.x + 1][ threadIdx.y]+
                    src[threadIdx.x+ 1][ threadIdx.y +1])/9.0;

right? what about the corner or the border pixels? How can you take care of the boundaries?

Roman
  • 1
  • 2
  • 1
    You may get some ideas by poking around perhaps on questions tagged with both CUDA and OpenCV, such as [this question/answer](http://stackoverflow.com/questions/22315903/cuda-median-filter-implementation-does-not-produce-desired-results) – Robert Crovella Apr 02 '14 at 02:26
  • 1
    In addition, you could find interesting http://stackoverflow.com/questions/5715220/what-is-usually-done-with-the-boundary-pixels-of-the-image (by a quick search in SO). – pQB Apr 02 '14 at 07:46

1 Answers1

1

The texturing hardware is excellent at dealing with corners and boundaries, if the addressing modes meet your requirements.

Shared memory is very good for facilitating reuse of the pixels in the stencil - look at the sobelFilter sample program in the SDK, and replace the Sobel computation with your computation.

ArchaeaSoftware
  • 4,332
  • 16
  • 21