blur image

Hi all,

I have C++ Code:

void iplImage::blurImage 

                        ( 

      iplImage &blur_image,

                        double  blur_force,

                        int     blur_len 

      )

{

    blur_image.create (_width, _height, _bytes_per_pixel);

   if( _bytes_per_pixel > 1 ) return;

   _Timage* src = _image;

    _Timage* dst = blur_image.getPtr ();

    

    for( int j = 0; j < _height; ++j )

        for( int i = 0; i < _width; ++i )

        {

            int res   = 0;

            double count = 0.0;

            for( int j1 = j - blur_len; j1 <= j + blur_len; ++j1 )

                if( j1 >=0 && j1 < _height )

                {

                    src = _image + j1*_width;

                    for( int i1 = i - blur_len; i1 <= i + blur_len; ++i1 )

                        if( i1 >= 0 && i1 < _width )

                        {

                            // 0 - данная точка, 1.0 - на расстоянии blur_len

                            //dist = ((j1-j) + (i1-i))<<8 / blur_len;

                            double radius = sqrt (double((j1-j)*(j1-j) + (i1-i)*(i1-i)))/ (double)blur_len;

                            //double radius = ((j1-j) + (i1-i))/ (double)blur_len;

                            double force = 1 - pow (radius/2, blur_force);

                            res += int(*(src + i1) * force);

                            count += force;

                        }

                }

            *(dst + j*_width + i) = count ? int(res/count) : *(_image + j*_width + i);

        }

}

How I can do it in G80 ?

You can do this in a very similar way in CUDA, except each output pixel can be calculated by its own thread (in parallel), so you don’t need the outer two loops.

To get best performance you should copy tiles of the image to shared memory and operate on them there.

There will be an image convolution sample in the CUDA 1.0 SDK.

Thanks