kunzmi / managedCuda

ManagedCUDA aims an easy integration of NVidia's CUDA in .net applications written in C#, Visual Basic or any other .net language.
Other
440 stars 79 forks source link

FilterMedian failure #83

Open serjl opened 4 years ago

serjl commented 4 years ago

Hi @kunzmi, I try to write a function using nppi tools that takes NPPImage_8uC1 sourceBuffer and calculates median values over its columns. My idea is to use the FilterMedian nppi function. I set the roi on the sourceBuffer as the zeroth row, set a kernel window = oMaskSize as a rectangle of width = 1 and height = sourceBuffer.Height, set the pivot element = oAnchor as the zeroth element of oMaskSize , i.e. (0,0).

                public NPPImage_8uC1 MedianFilter(NPPImage_8uC1 sourceBuffer)
                {
                       sourceBuffer.SetRoi(new NppiRect(0, 0, sourceBuffer.Width, 1));
                       NPPImage_8uC1 dst = new NPPImage_8uC1(sourceBuffer.Width, 1);
                       NppiSize oMaskSize = new NppiSize(1, sourceBuffer.Height);
                       NppiPoint oAnchor = new NppiPoint(0, 0);
                       int bufferHostSize = ptrn.FilterMedianGetBufferHostSize(oMaskSize); //(!!!!)
                       CudaDeviceVariable<byte> buffer = new CudaDeviceVariable<byte>(bufferHostSize);
                       sourceBuffer.FilterMedian(dst, oMaskSize, oAnchor, buffer );
                       return dst;
                }

I get at line (!!!!) bufferHostSize = 0 and the next throws exception. If i change oMaskSize.Width = 1 in NppiSize oMaskSize = new NppiSize(1, sourceBuffer.Height); to a number >1 it then passes throw smoothly.

Is there a limit of oMaskSize.Width/Height >1 in the cuda C nppiFilterMedian_8u_C1R ?