View Raw SPL
/*****************************************************************************
*                                                                            *
*   MINFILT.SPL  Copyright (C) 2011 DSP Development Corporation              *
*                               All Rights Reserved                          *
*                                                                            *
*   Author:      Randy Race                                                  *
*                                                                            *
*   Synopsis:    Min filter a standard or RGB image                          *
*                                                                            *
*   Revisions:    6 Mar 2011  RRR  Creation                                  *
*                                                                            *
*****************************************************************************/

#include 

#if @HELP_MINFILT

    MINFILT

    Purpose: Performs 2D minimum filtering on an image.

    Syntax:  minfilt(image, ksize)

              image - An array, the input image
              ksize - Optional. An integer, the filter kernel size. Must
                      be odd, defaults to 3 (3x3 kernel).

    Returns: An array, the filtered image

    Example:
             W1: density(ravel(readb("baboon.dat", ubyte), 128));gray
             W2: minfilt(w1)

             W1 reads and shapes a 128x256 raw binary image.
             W2 contains the 3x3 minimum filtered output.

    Example:
             W1: readimage(gethome + "data\mandrill.bmp")
             W2: minfilt(w1, 5)

             W1 reads a 250x240 bitmap image.  The result is a 24 bit
             RGB image. W2 contains the 5x5 minimum filtered output.

    Remarks:
             For 24 bit RGB images, MINFILT automatically performs filtering
             on each R, G, B component.

             If the filter kernel is even, the size is incremented to
             make it odd.

    See Also:
             Conv2d
             Iminterp
             Medfilt
             Minfilt
             Nonlin2d
#endif


/* 2D minimum filtering */
minfilt(img, ksize)
{
        if (argc < 2)
        {
                if (argc < 1) error("minfilt - input series required");
                
                ksize = 3;
        }

        /* core function */
        img = rgbnonlin2d(img, ksize, 1);
        
        return(img);
}