{ "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "code", "language": "python", "outputs": [], "collapsed": false, "input": [ "%matplotlib inline" ], "metadata": {} }, { "source": "
\n

# Mean filters

\n

This example compares the following mean filters of the rank filter package:

\n
\n
\n
• local mean: all pixels belonging to the structuring element to compute\naverage gray level.
• \n
• percentile mean: only use values between percentiles p0 and p1\n(here 10% and 90%).
• \n
• bilateral mean: only use pixels of the structuring element having a gray\nlevel situated inside g-s0 and g+s1 (here g-500 and g+500)
• \n
\n
\n

Percentile and usual mean give here similar results, these filters smooth the\ncomplete image (background and details). Bilateral mean exhibits a high\nfiltering rate for continuous area (i.e. background) while higher image\nfrequencies remain untouched.

\n
\n", "cell_type": "markdown", "metadata": {} }, { "cell_type": "code", "language": "python", "outputs": [], "collapsed": false, "input": "import numpy as np\nimport matplotlib.pyplot as plt\n\nfrom skimage import data\nfrom skimage.morphology import disk\nfrom skimage.filter import rank\n\n\nimage = (data.coins()).astype(np.uint16) * 16\nselem = disk(20)\n\npercentile_result = rank.mean_percentile(image, selem=selem, p0=.1, p1=.9)\nbilateral_result = rank.mean_bilateral(image, selem=selem, s0=500, s1=500)\nnormal_result = rank.mean(image, selem=selem)\n\n\nfig, axes = plt.subplots(nrows=3, figsize=(8, 10))\nax0, ax1, ax2 = axes\n\nax0.imshow(np.hstack((image, percentile_result)))\nax0.set_title('Percentile mean')\nax0.axis('off')\n\nax1.imshow(np.hstack((image, bilateral_result)))\nax1.set_title('Bilateral mean')\nax1.axis('off')\n\nax2.imshow(np.hstack((image, normal_result)))\nax2.set_title('Local mean')\nax2.axis('off')\n\nplt.show()", "metadata": {} } ], "metadata": {} } ], "metadata": { "name": "" } }