GithubHelp home page GithubHelp logo

avaneesh2001 / adaptive-median-and-median-filtering Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 551 KB

Image de noising by Adaptive median and Median filtering

License: GNU General Public License v3.0

MATLAB 100.00%

adaptive-median-and-median-filtering's Introduction

Adaptive Median and Median Filtering

Table of Contents

  1. Noise
    1.1. Image Noise
    1.2. Salt & pepper noise
  2. Median filtering
    2.1. Algorithm
  3. Adaptive Median Filtering
  4. Code
  5. Sample outputs
    5.1. Input
    5.2. Median Filtering
    5.3. Adaptive Median Filtering
  6. Drawbacks

Noise

Image Noise

Image noise is random variation of brightness or color information in images, and is usually an aspect of electronic noise.. It is an undesirable by-product of image capture that obscures the desired information.

Salt & pepper noise

Salt & pepper noise is an impulse type of noise in images. We consider saltand-pepper noise, for which a certain amount of the pixels in the image are either black or white. Normally if there is black dots in the image we called it pepper noise and if there is white dots in the image we called it salt noise. This noise is generally caused by errors in data transmission, failure in memory cell or analog-to-digital converter errors.
If we consider 8-bit image, salt and pepper noise randomly occur certain amount of pixels into two extremes, either 0 or 255.The noise significantly damages the image information which leads to difficulties in succeeding image processing tasks such as edge detection or image segmentation and image recognition tasks.

Median filtering

Median filter is the most commonly used filter. It is a non linear method of filtering. The size of the kernel can be of nxn size which is made to convolve or slide over a mxm corrupted image. While performing this operation the median value of nxn kernel on the image is obtained and then the value of a particular pixel is replaced with the median value of the nxn kernel.
The median m of a set of values is such that half of the values are greater than m and half are less than m

Algorithm

  1. Zero pad the input gray-scale of size (mxn) to form a matrix of size (m+2)x(n+2)

  2. Form a window matrix of size 3x3 with the elements of input matrix

  3. Copy the window matrix(3x3) into an array and sort it.

  4. Find the median element and replace that value in the middle of the window matrix in the zero-padded image.

  5. Shift the window and repeat the entire process to cover the entire pixels in the image.


Adaptive Median Filtering

Adaptive Median Filter is a variation of median filter that can better handle noise found in salt-and-pepper images if the probability of noise is less than 20%. This works by preserving detail of the image while smoothing the nonimpulse noise.
The working of adaptive filter is a two step process; in the first step its finds the median value for the kernel and in the second step it checks whether the current pixel value is a impulse (salt and pepper noise) or not. If pixel value is corrupted then it changes it value with median or else it retains the value of the gray scale pixel.
Another key feature about the median filter is that the size of the kernel grows during iteration of the image, which can provide for more accurate denoising based on certain conditions listed below.

Level A: if $Z_{min} < Z_{med} < Z_{max}$ , go to Level B .
             Else,increase the size of $S_{xy}$
             f $S_{xy} <= S_{max}$, repeat Level A
             Else, output $Z_{med}$
Level B: if $Z_{min} < Z_{xy} < Z_{max}$ , output $Z_{xy}$
             Else, output $Z_{med}$
$Z_{min}$ = Minimum gray level value in $S_{xy}$
$Z_{max}$ = Maximum gray level value in $S_{xy}$
$Z_{med}$ = Median of gray levels in $S_{xy}$
$Z_{xy}$ = gray level at coordinates (x, y)
$S_{max}$ = Maximum allowed size of $S_{xy}$\


Code

The code is available in "matlab code" folder
Code


Sample outputs

Input

input image

The input image

Median Filtering

Median filtering

Greayscale image with noise and median filtered output

Median filtering with diffrent noise

Median filtering with various noise levels

function vs inbuilt

Defined Medianfilter function vs inbuilt function

Adaptive Median Filtering

Adaptive Median filtering

Greayscale image with noise and adaptive median filtered output

Adaptive Median filtering with diffrent noise

Adaptive median filtering with various noise levels

A few Notes

  1. For low noise levels both median and adaptive median filters works efficiently, but as noise levels increases the adaptive filter does a better job in denoising than median filter.

  2. The signal to noise ratio of the output from median filter is less than that from adaptive median filter.

Drawbacks

  1. Effective only when the noise is impulse noise (salt and pepper).
  2. The median filter's output quality deteriorates when the noise is more than 20%.
  3. For large kernel size, there is no proper smoothening of the image instead valuable information from the image gets blured.

adaptive-median-and-median-filtering's People

Stargazers

R Avaneesh avatar

Watchers

R Avaneesh avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.