View Raw SPL
/* core nonlin2d filtering function for RGB images */
rgbnonlin2d(img, ksize, type)
{
        local r, g, b;

        if (argc < 3)
        {
                if (argc < 2)
                {
                        if (argc < 1) img = {};
                        
                        ksize = 3;
                }
                
                type = 0;
        }

        if (length(img) == 0) error("rgbnonlin2d - input image required");

        /* make kernal size odd */
        if (ksize % 2 == 0) ksize++;

        if (rgbimage(img))
        {
                /* separate components */
                (r, g, b) = getrgb(img);

                /* filter each component */
                r = nonlin2d(r, type, ksize);
                g = nonlin2d(g, type, ksize);
                b = nonlin2d(b, type, ksize);

                /* reconstruct */
                img = rgbimage(r, g, b);
        }
        else
        {
                /* standard processing */
                img = nonlin2d(img, type, ksize);
        }
        
        return(img);
}