Median Filtering for Image Restoration in R.

DOI : 10.17577/IJERTCONV6IS15071

Download Full-Text PDF Cite this Publication

Text Only Version

Median Filtering for Image Restoration in R.

Median Filtering for Image Restoration in R.

Vishwanath Gouda R Malipatil VP Dr PGHCET Bijapur Assistant Professor

E&CE Dept

Dr. G. M. Patil


JSS Academy of Technical Education Noida


E&CE Student

VP Dr PGHCET Bijapur

Abstract:- In this paper, we use R tool for restoration of images corrupted by impulse noise. The median filter is called as optimum likelihood estimator for impulse noise suppression. This paper implements fast median filter in R for impulse noise suppression in images.

General Terms:- Image Processing.

Keywords:- Image Restoration, Impulse Noise , Median Filter.


    R is a programming language and open source software for statistical computing and graphics. R was created by Ross Ihaka and Robert Gentlemen at University of Auckland, New Zealand during August 1993.The initial version of R was available in 1995. However, a stable beta version was released during 2000. The Rs data structures include vectors, matrices, arrays and data frames.

    R community is noted for its active contributions in terms of packages. The R incorporates user submitted packages for specific functions or specific areas of study. The packages are developed primarily in R and some in Java, C, C++ and Fortran. The R supports core and over 11,000 additional packages (as of July 2017). The additional packages are available at the Comprehensive R Archive Network (CRAN), Bioconductor, Omegahat, GitHub and other repositories. The R uses specific packages like EBImage, Magick, Imager, Octave-Forge Image package, biops, LIRA, and ripa for image processing and analysis.

    EBImage is an R package distributed as a part of Bioconductor project. To install this package, start R and enter source ( and biocLite(EBImage) in R console. After the installation, the package can be loaded with the command library (EBImage). The EBImage package is designed to read, write and display an image. Images are read using the function readImage either from filers or URLs using the commands shown in table 1. The EBImage currently supports jpeg, png and tiff file formats. The images can be saved to files using the function writeImage. Further, an image from one file can be converted to another. The table 1 shows R commands to read, write and display an image.

    Table 1: R commands to read, write and display an Image

    F= system.file(images, file name.file type, package=EBImage)



    Y=writeImage(X,filename.JPEG, quality=any number between 1 and


    using EBImage package.

    The Magick is a R package associated with CRAN. CRAN is a network of file transfer protocol and web servers around the world that store up to date version of code and document for R. The magick package is a result of an ambitious effort to modernize and simplify high quality image processing in R. The magick package supports png, jpeg, tiff and pdf image file formats. The package is installed on windows or OS-X via CRAN using the instruction install.packages(magick). The package can be loaded with the command library (magick). The images can be read directly from the file path or URL using image_read. The image _write is the command used to export an image in any format to a file on disk or in memory and image_display is used to preview the image.


    R brings interest in statistical and graphical tool which are important and necessary for image processing techniques. Frery et al in [1], introduced the statistical software R to the image processing community, where in theory and practice of R code concepts are presented and explained. In [2], an image stitching and fusion operations are performed in R studio. In [3], a median filter which is much fast in operation is described and analyzed. In this paper a new median filter based on Perreault operation is implemented in R studio using EBImage package.


    The median filter is the basic building block and corner stone in the area of image restoration. The median filter is hampered by its algorithmic complexity. A brute force approach simply builts the list of pixels in the filter window and sorts them. The median is then the value situated at the middle of list. The complexity of this algorithm per pixel is O(r2logr) where r is a radius of the window. A bucket sort approach brings the complexity down to O(r2).

    The median filter in[4] exhibits O(r) complexity. This algorithm makes use of histogram for accumulating pixels in the window. The algorithm requires (2r+1) additions and (2r+1) substrations. The median from histogram is computed in constant time by summing the values from one end and stopping when the sum reaches (2r+1)2/2.

    A complexity of O(logr2) is attended by Gil et al in [5] using tree based algorithm. In this paper a simple O(1) median filter is implemented in R for images corrupted by impulse noise. The performance of the median filter is evaluated for different densities of Impulse noise and the

    restoration performance of the median filter is shown in fig 1,2 and 3. The estimation of corruption is tabulated in table 2.

    Total no of pixels

    Corrupted pixels

    persentage of corruption










    Table 2: Estimation of corruption in images.

    a b


    Fig 1: a) Original Image b) Image corrupted by 2.5% impulse noise c) Restored image using median filter.


    In this work the fast median filter for suppression of Impulse noise in images is implemented in R. This work is useful for researchers who are new to the field of image processing and to R software. Further the work can be extended to design the different filters for the noise suppression in images using R.


[1] Alejandro C Frery and Talita Perciano Introduction to Image Processing using R: Learning by Examples Springer Briefs in Computer Science,2013 Edition.

[2] K Naga Babu A Novel Approach on Image Processing using R Studio International Journal of Advanced Research in Computer and Communication Engineering, Vol 5, Issue 11, Nov 2016 .

[3] Simon Perreault and Patrick Hebert Median Filtering in Constant Time IEEE Transaction on Image Processing Vol 16,No 9, Sep 2007.

[4] T.Hung , G. Yang and G Tang A fast Two dimensional Median Filtering Algorithm IEEE Transaction on Acoustics Speech and Signal Processing, Vol 27, No 2 Page no 13-18, Feb 1979.

[5] J Gil and M Werman Computing 2-D min, median and max filters IEEE Transaction on Pattern Anal Mach Intell, Vol 15, No 5, pafe no 504-507, May 1993.

a b


Fig 2: a) Original Image b) Image corrupted by 10% impulse noise c) Restored image using median filter.

a b


Fig 3: a) Original Image b) Image corrupted by 20% impulse noise c) Restored image using median filter.

Leave a Reply