Parcourir la source

Add of salt and pepper noise

Jérôme BUISINE il y a 5 ans
Parent
commit
dc6aa10808

+ 3 - 2
README.md

@@ -1,8 +1,9 @@
 Image Processing For Machine Learning
 =====================================
 
-![ipfml_logo](ipfml_logo.png)
-
+<center>
+    <img src="ipfml_logo.png" width="40%">
+</center>
 
 Installation
 ------------

+ 4 - 6
README.rst

@@ -1,15 +1,13 @@
 Image Processing For Machine Learning
 =====================================
 
-.. image:: ipfml_logo.png
-
 This is a package developed during a thesis project.
 
 Installation
 ------------
 
 .. code:: bash
-   
+
    pip install ifpml
 
 How to use ?
@@ -18,7 +16,7 @@ How to use ?
 To use, simply do :
 
 .. code:: python
-   
+
    from PIL import Image
    from ipfml import processing
    img = Image.open('path/to/image.png')
@@ -39,6 +37,6 @@ All these modules will be enhanced during development of the package.
 Documentation
 -------------
 
-For more information about package, documentation_ is available. 
+For more information about package, documentation_ is available.
 
-.. _documentation: https://jbuisine.github.io/IPFML/  
+.. _documentation: https://jbuisine.github.io/IPFML/

BIN
docs/build/doctrees/contributing.doctree


BIN
docs/build/doctrees/description.doctree


BIN
docs/build/doctrees/environment.pickle


BIN
docs/build/doctrees/index.doctree


BIN
docs/build/doctrees/ipfml.doctree


+ 3 - 0
docs/build/html/_sources/contributing.rst.txt

@@ -2,6 +2,9 @@ Contributing
 =====================================
 
 .. image:: _static/ipfml_logo.png
+   :width: 400 px
+   :align: center
+
 
 
 Using GitHub

+ 4 - 3
docs/build/html/_sources/description.rst.txt

@@ -2,7 +2,8 @@ Description
 =====================================
 
 .. image:: _static/ipfml_logo.png
-
+   :width: 400 px
+   :align: center
 
 Installation
 ------------
@@ -22,6 +23,6 @@ To use, simply do :
 .. code:: python
     
    from PIL import Image
-   from ipfml import image_processing
+   from ipfml import processing
    img = Image.open('path/to/image.png')
-   s = image_processing.get_LAB_L_SVD_s(img)
+   s = processing.get_LAB_L_SVD_s(img)

+ 2 - 0
docs/build/html/_sources/index.rst.txt

@@ -7,6 +7,8 @@ Image Processing For Machine Learning
 =====================================
 
 .. image:: _static/ipfml_logo.png
+   :width: 400 px
+   :align: center
 
 What's IPFML ?
 =================

+ 1 - 0
docs/build/html/_sources/ipfml.rst.txt

@@ -21,6 +21,7 @@ ipfml.filters
 
 ipfml.filters.noise
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
 .. automodule:: ipfml.filters.noise
     :members:
     :show-inheritance:

+ 1 - 1
docs/build/html/contributing.html

@@ -156,7 +156,7 @@
             
   <div class="section" id="contributing">
 <h1>Contributing<a class="headerlink" href="#contributing" title="Permalink to this headline">¶</a></h1>
-<img alt="_images/ipfml_logo.png" src="_images/ipfml_logo.png" />
+<a class="reference internal image-reference" href="_images/ipfml_logo.png"><img alt="_images/ipfml_logo.png" class="align-center" src="_images/ipfml_logo.png" style="width: 400px;" /></a>
 <div class="section" id="using-github">
 <h2>Using GitHub<a class="headerlink" href="#using-github" title="Permalink to this headline">¶</a></h2>
 <p>This git project uses <a class="reference external" href="https://danielkummer.github.io/git-flow-cheatsheet/">git-flow</a> implementation. You are free to contribute to it.</p>

+ 3 - 3
docs/build/html/description.html

@@ -158,7 +158,7 @@
             
   <div class="section" id="description">
 <h1>Description<a class="headerlink" href="#description" title="Permalink to this headline">¶</a></h1>
-<img alt="_images/ipfml_logo.png" src="_images/ipfml_logo.png" />
+<a class="reference internal image-reference" href="_images/ipfml_logo.png"><img alt="_images/ipfml_logo.png" class="align-center" src="_images/ipfml_logo.png" style="width: 400px;" /></a>
 <div class="section" id="installation">
 <h2>Installation<a class="headerlink" href="#installation" title="Permalink to this headline">¶</a></h2>
 <p>Just install package using pip</p>
@@ -170,9 +170,9 @@
 <h2>How to use ?<a class="headerlink" href="#how-to-use" title="Permalink to this headline">¶</a></h2>
 <p>To use, simply do :</p>
 <div class="code python highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">PIL</span> <span class="k">import</span> <span class="n">Image</span>
-<span class="kn">from</span> <span class="nn">ipfml</span> <span class="k">import</span> <span class="n">image_processing</span>
+<span class="kn">from</span> <span class="nn">ipfml</span> <span class="k">import</span> <span class="n">processing</span>
 <span class="n">img</span> <span class="o">=</span> <span class="n">Image</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="s1">&#39;path/to/image.png&#39;</span><span class="p">)</span>
-<span class="n">s</span> <span class="o">=</span> <span class="n">image_processing</span><span class="o">.</span><span class="n">get_LAB_L_SVD_s</span><span class="p">(</span><span class="n">img</span><span class="p">)</span>
+<span class="n">s</span> <span class="o">=</span> <span class="n">processing</span><span class="o">.</span><span class="n">get_LAB_L_SVD_s</span><span class="p">(</span><span class="n">img</span><span class="p">)</span>
 </pre></div>
 </div>
 </div>

+ 9 - 0
docs/build/html/genindex.html

@@ -161,6 +161,7 @@
  | <a href="#M"><strong>M</strong></a>
  | <a href="#N"><strong>N</strong></a>
  | <a href="#R"><strong>R</strong></a>
+ | <a href="#S"><strong>S</strong></a>
  | <a href="#W"><strong>W</strong></a>
  
 </div>
@@ -292,6 +293,14 @@
   </ul></td>
 </tr></table>
 
+<h2 id="S">S</h2>
+<table style="width: 100%" class="indextable genindextable"><tr>
+  <td style="width: 33%; vertical-align: top;"><ul>
+      <li><a href="ipfml.html#ipfml.filters.noise.salt_pepper_noise">salt_pepper_noise() (in module ipfml.filters.noise)</a>
+</li>
+  </ul></td>
+</tr></table>
+
 <h2 id="W">W</h2>
 <table style="width: 100%" class="indextable genindextable"><tr>
   <td style="width: 33%; vertical-align: top;"><ul>

+ 1 - 1
docs/build/html/index.html

@@ -153,7 +153,7 @@
             
   <div class="section" id="image-processing-for-machine-learning">
 <h1>Image Processing For Machine Learning<a class="headerlink" href="#image-processing-for-machine-learning" title="Permalink to this headline">¶</a></h1>
-<img alt="_images/ipfml_logo.png" src="_images/ipfml_logo.png" />
+<a class="reference internal image-reference" href="_images/ipfml_logo.png"><img alt="_images/ipfml_logo.png" class="align-center" src="_images/ipfml_logo.png" style="width: 400px;" /></a>
 </div>
 <div class="section" id="what-s-ipfml">
 <h1>What’s IPFML ?<a class="headerlink" href="#what-s-ipfml" title="Permalink to this headline">¶</a></h1>

Fichier diff supprimé car celui-ci est trop grand
+ 33 - 0
docs/build/html/ipfml.html


+ 3 - 3
docs/build/html/objects.inv

@@ -2,6 +2,6 @@
 # Project: IPFML
 # Version: 0.2.0
 # The remainder of this file is compressed using zlib.
-xÚ¥”MOã0†ïù–Øk#ºGn,]¤•Š„„¨€‹å8Sg´þˆl‡~ý&qC‚–ŠØ½%ã÷y=¶gë½’ù¥ërmЩÛ+eÊF¹$8¬W^É‹[ý «ÿ§rÎ^µôÃbßhîÑh²ž›œ¢kœC¦SyÉjÉ8$ãFt¨UL¦:¨ÆÓC…>9…HX�·ÈÝâÇ:êsžn¯El1"t›±¨ˆ…v›„>¦@»ÈÅBOÏ/	}J�žS èô
-ôŽ¢±œ4‡4Ö²–zC•ãz	W[áBZ,nª	ÉK|Å(jZHÃÿº¸§[ZʧØe5}’Þ�EÇž:Œ\|úsC™µÉø™,= ¯¨eZ@¤�E_cá
-ú*=‡+=ÍCXhÏ´ø¾U¸Ñ]w�ïÛÄùòª4œ¬ÖdÔäfÉJpÜb=xΨY8@›)�ÁSµ7ÆXPÿ>þe4êÞ©dÈ^<FƒøOÿ™M²£ã\¡X÷þ÷Ó¸5–Ü1^¡²fu”áB>9|ÜÙÞ(О
èÆÅYÕíj\Ð]˜4!?×mëÏDˆñCX¿ï2ÍþØwa
+xÚ¥”MkÜ0†ïþ‚öº¦é1·4ÛBa�Ð%ÉEÈò¬<T_Hr7ί¯m­c‡f©¥½Ù£÷y5’fíAÉò€2€ó¥6è�ØîZ™º•@¾×› ä§Û|&›ÿ¥JÎZÞtôÍâÐjÐhrµ49GÖz�Lçò’YÉ8dãFô¨SLæ:¨6Ðcƒ!;Ïd ¬—k‘¸¿‚à�ûÕï}Ò—ÝÝ|KØbBè.b9P•
+=ì·ý•ís Ÿ
+=>=g ô1zÊ�’Ó«0xŠJ¤rÒóXÇ:Užë5œu†C?Ç´XÝT3RÖøk ¨i%
ÿíÓvœ{lm)Ÿc×ÕôYz�zê8µñè×-eÎeã²ôˆ¡¡Ži‰6NTC�Å+ªô~ªô<á »Ðâÿ­Â�jÃÐ&>Ô×µádsE–ñQMn‘¢ÏÚÑsA-ÂÚÎ�^˜²ü˜bQýýôWШkx¥’U ñ�âŸÃg1ËNŽK…býûßÏcà‡qäŽñ5�0§‡£ŒòÎáí†ÈÖðV�l<@?.>ÈÊv›i!BwqÒÄü|¿
oÞ1Åqý¾Ï´ø¹Ô�é

Fichier diff supprimé car celui-ci est trop grand
+ 1 - 1
docs/build/html/searchindex.js


+ 3 - 0
docs/source/contributing.rst

@@ -2,6 +2,9 @@ Contributing
 =====================================
 
 .. image:: _static/ipfml_logo.png
+   :width: 400 px
+   :align: center
+
 
 
 Using GitHub

+ 2 - 1
docs/source/description.rst

@@ -2,7 +2,8 @@ Description
 =====================================
 
 .. image:: _static/ipfml_logo.png
-
+   :width: 400 px
+   :align: center
 
 Installation
 ------------

+ 2 - 0
docs/source/index.rst

@@ -7,6 +7,8 @@ Image Processing For Machine Learning
 =====================================
 
 .. image:: _static/ipfml_logo.png
+   :width: 400 px
+   :align: center
 
 What's IPFML ?
 =================

+ 50 - 15
ipfml/filters/noise.py

@@ -7,7 +7,6 @@ def _global_noise_filter(image,
                          generator,
                          updator,
                          identical=False,
-                         distribution_interval=(-0.5, 0.5),
                          k=0.2):
     """White noise filter to apply on image
 
@@ -17,7 +16,6 @@ def _global_noise_filter(image,
         generator: lambda function used to generate random numpy array with specific distribution
         updator: lambda function used to update pixel value
         identical: keep or not identical noise distribution for each canal if RGB Image (default False)
-        distribution_interval: tuple which set the distribution interval of uniform distribution (default (-0.5, 0.5))
         k: variable that specifies the amount of noise to be taken into account in the output image (default 0.2)
 
     Returns:
@@ -43,7 +41,6 @@ def _global_noise_filter(image,
     else:
         width, height, nb_chanel = image_array.shape
 
-    a, b = distribution_interval
     nb_pixels = width * height
 
     if identical:
@@ -124,8 +121,7 @@ def white_noise(image,
 
     updator = lambda x, n, k, noise: x + n * k * noise
 
-    return _global_noise_filter(image, n, generator, updator, identical,
-                                distribution_interval, k)
+    return _global_noise_filter(image, n, generator, updator, identical, k)
 
 
 def gaussian_noise(image,
@@ -160,8 +156,7 @@ def gaussian_noise(image,
 
     updator = lambda x, n, k, noise: x + n * k * noise
 
-    return _global_noise_filter(image, n, generator, updator, identical,
-                                distribution_interval, k)
+    return _global_noise_filter(image, n, generator, updator, identical, k)
 
 
 def laplace_noise(image,
@@ -196,8 +191,7 @@ def laplace_noise(image,
 
     updator = lambda x, n, k, noise: x + n * k * noise
 
-    return _global_noise_filter(image, n, generator, updator, identical,
-                                distribution_interval, k)
+    return _global_noise_filter(image, n, generator, updator, identical, k)
 
 
 def cauchy_noise(image,
@@ -232,8 +226,7 @@ def cauchy_noise(image,
 
     updator = lambda x, n, k, noise: x + n * k * noise
 
-    return _global_noise_filter(image, n, generator, updator, identical,
-                                distribution_interval, k)
+    return _global_noise_filter(image, n, generator, updator, identical, k)
 
 
 def log_normal_noise(image,
@@ -268,8 +261,7 @@ def log_normal_noise(image,
 
     updator = lambda x, n, k, noise: x + n * k * noise
 
-    return _global_noise_filter(image, n, generator, updator, identical,
-                                distribution_interval, k)
+    return _global_noise_filter(image, n, generator, updator, identical, k)
 
 
 def mut_white_noise(image,
@@ -304,5 +296,48 @@ def mut_white_noise(image,
 
     updator = lambda x, n, k, noise: x * n * k * noise
 
-    return _global_noise_filter(image, n, generator, updator, identical,
-                                distribution_interval, k)
+    return _global_noise_filter(image, n, generator, updator, identical, k)
+
+
+def salt_pepper_noise(image,
+                     n,
+                     identical=False,
+                     p=0.1,
+                     k=0.5):
+    """Pepper salt noise filter to apply on image
+
+    Args:
+        image: image used as input (2D or 3D image representation)
+        n: used to set importance of noise [1, 999]
+        identical: keep or not identical noise distribution for each canal if RGB Image (default False)
+        p: probability to increase pixel value otherwise decrease it
+        k: variable that specifies the amount of noise to be taken into account in the output image (default 0.5)
+
+    Returns:
+        2D Numpy array with salt and pepper noise applied
+
+    Example:
+
+    >>> from ipfml.filters.noise import salt_pepper_noise
+    >>> import numpy as np
+    >>> image = np.random.uniform(0, 255, 10000).reshape((100, 100))
+    >>> noisy_image = salt_pepper_noise(image, 10)
+    >>> noisy_image.shape
+    (100, 100)
+    """
+
+    def _generator(x):
+        nb_elem = int(p * x)
+
+        elements = np.full(x, 0)
+        elements[0:nb_elem] = 1
+        np.random.shuffle(elements)
+
+        return elements
+
+    # here noise variable is boolean to increase or decrease pixel value
+    updator = lambda x, n, k, noise: (x + n * k) if noise == 1 else (x - n * k)
+
+    return _global_noise_filter(image, n, _generator, updator, identical, k)
+
+