001    /*
002     * MedianFilter
003     * 
004     * Copyright (c) 2001, 2002 Marco Schmidt.
005     * All rights reserved.
006     */
007    
008    package net.sourceforge.jiu.filters;
009    
010    import net.sourceforge.jiu.filters.AreaFilterOperation;
011    import net.sourceforge.jiu.util.Median;
012    
013    /**
014     * Applies a Median filter that replaces each pixel by the median of
015     * itself and its neighbors.
016     * The number of neighbors can be defined with the setArea methods.
017     * <p>
018     * Can be used as despeckle filter, but the image will lose sharpness.
019     * The larger the area becomes, the less noise and the less sharpness will remain,
020     * and the longer it will take.
021     * <p>
022     * Uses {@link net.sourceforge.jiu.util.Median} to do the search for the median value.
023     * <h3>Usage example</h3>
024     * <pre>
025     * PixelImage image = ...; // some GrayIntegerImage or RGBIntegerImage
026     * MedianFilter filter = new MedianFilter();
027     * filter.setArea(5, 5);
028     * filter.setInputImage(image);
029     * filter.process();
030     * PixelImage filteredImage = filter.getOutputImage();
031     * </pre>
032     * @author Marco Schmidt
033     */
034    public class MedianFilter extends AreaFilterOperation
035    {
036            public final int computeSample(int[] samples, int numSamples)
037            {
038                    return Median.find(samples, 0, numSamples - 1);
039            }
040    }