Browse Source

Noise filters issues fixed

Jérôme BUISINE 2 years ago
parent
commit
780ab130c9

+ 3 - 0
CONTRIBUTION.md

@@ -141,6 +141,9 @@ This command do a lot of thing for you:
   - Runs the tests from documentation and raise errors if there are.
   - Formats all **\*.py** inside *ipfml* folder using **yapf**.
 
+Do not forget to build documentation as explained in section [2.3](#code-documentation).
+
+
 ## Pull request
 
 Once you have built the package following previous instructions. You can make a pull request using GitHub. A [documentation](https://help.github.com/articles/about-pull-requests/) about pull requests is available.

BIN
docs/build/doctrees/contributing.doctree


BIN
docs/build/doctrees/description.doctree


BIN
docs/build/doctrees/environment.pickle


BIN
docs/build/doctrees/examples.doctree


BIN
docs/build/doctrees/index.doctree


BIN
docs/build/doctrees/ipfml.doctree


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

@@ -1,4 +1,4 @@
 # Sphinx build info version 1
 # This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
-config: 1c8ed53caf85831b15e6fb8cd7f810e0
+config: b880d941bb6bde0971be7f6f4ef05ce2
 tags: 645f666f9bcd5a90fca523b33c5a78b7

BIN
docs/build/html/_images/nature_gaussian_noise.png


+ 3 - 2
docs/build/html/_sources/examples.rst.txt

@@ -61,8 +61,9 @@ Noise filter example
    img_path = 'path/to/image_nature.jpg'
    img = Image.open(img_path)
 
-   # set noise impact to 30
-   noisy_image = nf.gaussian_noise(img, n=30)
+   # set noise impact to 400
+   # set same noise for each chanel
+   noisy_image = nf.gaussian_noise(img, n=400, identical=True)
 
    output = Image.fromarray(noisy_image)
    output.show()

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

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

+ 1 - 1
docs/build/html/_static/documentation_options.js

@@ -1,6 +1,6 @@
 var DOCUMENTATION_OPTIONS = {
     URL_ROOT: document.getElementById("documentation_options").getAttribute('data-url_root'),
-    VERSION: 'v0.2.5',
+    VERSION: 'v0.2.6',
     LANGUAGE: 'None',
     COLLAPSE_INDEX: false,
     FILE_SUFFIX: '.html',

BIN
docs/build/html/_static/nature_gaussian_noise.png


+ 5 - 3
docs/build/html/contributing.html

@@ -8,7 +8,7 @@
   
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   
-  <title>Contributing &mdash; IPFML v0.2.5 documentation</title>
+  <title>Contributing &mdash; IPFML v0.2.6 documentation</title>
   
 
   
@@ -57,7 +57,7 @@
             
             
               <div class="version">
-                0.2.5
+                0.2.6
               </div>
             
           
@@ -141,7 +141,9 @@
       <li class="wy-breadcrumbs-aside">
         
             
-            <a href="_sources/contributing.rst.txt" rel="nofollow"> View page source</a>
+            
+              <a href="https://github.com/jbuisine/IPFML/blob/master/docs/source/contributing.rst" class="fa fa-github"> Edit on GitHub</a>
+            
           
         
       </li>

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

@@ -8,7 +8,7 @@
   
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   
-  <title>Description &mdash; IPFML v0.2.5 documentation</title>
+  <title>Description &mdash; IPFML v0.2.6 documentation</title>
   
 
   
@@ -58,7 +58,7 @@
             
             
               <div class="version">
-                0.2.5
+                0.2.6
               </div>
             
           
@@ -143,7 +143,9 @@
       <li class="wy-breadcrumbs-aside">
         
             
-            <a href="_sources/description.rst.txt" rel="nofollow"> View page source</a>
+            
+              <a href="https://github.com/jbuisine/IPFML/blob/master/docs/source/description.rst" class="fa fa-github"> Edit on GitHub</a>
+            
           
         
       </li>

+ 8 - 5
docs/build/html/examples.html

@@ -8,7 +8,7 @@
   
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   
-  <title>Examples &mdash; IPFML v0.2.5 documentation</title>
+  <title>Examples &mdash; IPFML v0.2.6 documentation</title>
   
 
   
@@ -58,7 +58,7 @@
             
             
               <div class="version">
-                0.2.5
+                0.2.6
               </div>
             
           
@@ -144,7 +144,9 @@
       <li class="wy-breadcrumbs-aside">
         
             
-            <a href="_sources/examples.rst.txt" rel="nofollow"> View page source</a>
+            
+              <a href="https://github.com/jbuisine/IPFML/blob/master/docs/source/examples.rst" class="fa fa-github"> Edit on GitHub</a>
+            
           
         
       </li>
@@ -206,8 +208,9 @@
 <span class="n">img_path</span> <span class="o">=</span> <span class="s1">&#39;path/to/image_nature.jpg&#39;</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="n">img_path</span><span class="p">)</span>
 
-<span class="c1"># set noise impact to 30</span>
-<span class="n">noisy_image</span> <span class="o">=</span> <span class="n">nf</span><span class="o">.</span><span class="n">gaussian_noise</span><span class="p">(</span><span class="n">img</span><span class="p">,</span> <span class="n">n</span><span class="o">=</span><span class="mi">30</span><span class="p">)</span>
+<span class="c1"># set noise impact to 400</span>
+<span class="c1"># set same noise for each chanel</span>
+<span class="n">noisy_image</span> <span class="o">=</span> <span class="n">nf</span><span class="o">.</span><span class="n">gaussian_noise</span><span class="p">(</span><span class="n">img</span><span class="p">,</span> <span class="n">n</span><span class="o">=</span><span class="mi">400</span><span class="p">,</span> <span class="n">identical</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
 
 <span class="n">output</span> <span class="o">=</span> <span class="n">Image</span><span class="o">.</span><span class="n">fromarray</span><span class="p">(</span><span class="n">noisy_image</span><span class="p">)</span>
 <span class="n">output</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>

+ 6 - 2
docs/build/html/genindex.html

@@ -9,7 +9,7 @@
   
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   
-  <title>Index &mdash; IPFML v0.2.5 documentation</title>
+  <title>Index &mdash; IPFML v0.2.6 documentation</title>
   
 
   
@@ -57,7 +57,7 @@
             
             
               <div class="version">
-                0.2.5
+                0.2.6
               </div>
             
           
@@ -138,6 +138,10 @@
       <li class="wy-breadcrumbs-aside">
         
             
+            
+              <a href="https://github.com/jbuisine/IPFML/blob/master/docs/source/genindex" class="fa fa-github"> Edit on GitHub</a>
+            
+          
         
       </li>
     

+ 5 - 3
docs/build/html/index.html

@@ -8,7 +8,7 @@
   
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   
-  <title>Image Processing For Machine Learning &mdash; IPFML v0.2.5 documentation</title>
+  <title>Image Processing For Machine Learning &mdash; IPFML v0.2.6 documentation</title>
   
 
   
@@ -57,7 +57,7 @@
             
             
               <div class="version">
-                0.2.5
+                0.2.6
               </div>
             
           
@@ -138,7 +138,9 @@
       <li class="wy-breadcrumbs-aside">
         
             
-            <a href="_sources/index.rst.txt" rel="nofollow"> View page source</a>
+            
+              <a href="https://github.com/jbuisine/IPFML/blob/master/docs/source/index.rst" class="fa fa-github"> Edit on GitHub</a>
+            
           
         
       </li>

+ 7 - 5
docs/build/html/ipfml.html

@@ -8,7 +8,7 @@
   
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   
-  <title>Documentation &mdash; IPFML v0.2.5 documentation</title>
+  <title>Documentation &mdash; IPFML v0.2.6 documentation</title>
   
 
   
@@ -58,7 +58,7 @@
             
             
               <div class="version">
-                0.2.5
+                0.2.6
               </div>
             
           
@@ -147,7 +147,9 @@
       <li class="wy-breadcrumbs-aside">
         
             
-            <a href="_sources/ipfml.rst.txt" rel="nofollow"> View page source</a>
+            
+              <a href="https://github.com/jbuisine/IPFML/blob/master/docs/source/ipfml.rst" class="fa fa-github"> Edit on GitHub</a>
+            
           
         
       </li>
@@ -1043,7 +1045,7 @@
 
 <dl class="function">
 <dt id="ipfml.filters.noise.mut_white_noise">
-<code class="descclassname">ipfml.filters.noise.</code><code class="descname">mut_white_noise</code><span class="sig-paren">(</span><em>image</em>, <em>n</em>, <em>identical=False</em>, <em>distribution_interval=(-0.5</em>, <em>0.5)</em>, <em>k=0.2</em><span class="sig-paren">)</span><a class="headerlink" href="#ipfml.filters.noise.mut_white_noise" title="Permalink to this definition">¶</a></dt>
+<code class="descclassname">ipfml.filters.noise.</code><code class="descname">mut_white_noise</code><span class="sig-paren">(</span><em>image</em>, <em>n</em>, <em>identical=False</em>, <em>distribution_interval=(0</em>, <em>1)</em>, <em>k=0.002</em><span class="sig-paren">)</span><a class="headerlink" href="#ipfml.filters.noise.mut_white_noise" title="Permalink to this definition">¶</a></dt>
 <dd><p>Multiplied White noise filter to apply on image</p>
 <table class="docutils field-list" frame="void" rules="none">
 <col class="field-name" />
@@ -1054,7 +1056,7 @@
 <li><strong>n</strong> – used to set importance of noise [1, 999]</li>
 <li><strong>identical</strong> – keep or not identical noise distribution for each canal if RGB Image (default False)</li>
 <li><strong>distribution_interval</strong> – set the distribution interval of normal law distribution (default (-0.5, 0.5))</li>
-<li><strong>k</strong> – variable that specifies the amount of noise to be taken into account in the output image (default 0.2)</li>
+<li><strong>k</strong> – variable that specifies the amount of noise to be taken into account in the output image (default 0.002)</li>
 </ul>
 </td>
 </tr>

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

@@ -1,6 +1,6 @@
 # Sphinx inventory version 2
 # Project: IPFML
-# Version: 0.2.5
+# Version: 0.2.6
 # The remainder of this file is compressed using zlib.
 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 Ÿ

+ 2 - 2
docs/build/html/py-modindex.html

@@ -8,7 +8,7 @@
   
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   
-  <title>Python Module Index &mdash; IPFML v0.2.5 documentation</title>
+  <title>Python Module Index &mdash; IPFML v0.2.6 documentation</title>
   
 
   
@@ -59,7 +59,7 @@
             
             
               <div class="version">
-                0.2.5
+                0.2.6
               </div>
             
           

+ 6 - 2
docs/build/html/search.html

@@ -8,7 +8,7 @@
   
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   
-  <title>Search &mdash; IPFML v0.2.5 documentation</title>
+  <title>Search &mdash; IPFML v0.2.6 documentation</title>
   
 
   
@@ -56,7 +56,7 @@
             
             
               <div class="version">
-                0.2.5
+                0.2.6
               </div>
             
           
@@ -137,6 +137,10 @@
       <li class="wy-breadcrumbs-aside">
         
             
+            
+              <a href="https://github.com/jbuisine/IPFML/blob/master/docs/source/search" class="fa fa-github"> Edit on GitHub</a>
+            
+          
         
       </li>
     

File diff suppressed because it is too large
+ 1 - 1
docs/build/html/searchindex.js


BIN
docs/source/_static/nature_gaussian_noise.png


+ 9 - 2
docs/source/conf.py

@@ -24,9 +24,9 @@ copyright = '2019, Jérôme BUISINE'
 author = 'Jérôme BUISINE'
 
 # The short X.Y version
-version = '0.2.5'
+version = '0.2.6'
 # The full versiabson, including alpha/beta/rc tags
-release = 'v0.2.5'
+release = 'v0.2.6'
 
 
 # -- General configuration ---------------------------------------------------
@@ -103,6 +103,13 @@ html_theme_options = {
     'titles_only': False
 }
 
+html_context = {
+  'display_github': True,
+  'github_user': 'jbuisine',
+  'github_repo': 'IPFML',
+  'github_version': 'master/docs/source/'
+}
+
 # Add any paths that contain custom static files (such as style sheets) here,
 # relative to this directory. They are copied after the builtin static files,
 # so a file named "default.css" will overwrite the builtin "default.css".

+ 3 - 2
docs/source/examples.rst

@@ -61,8 +61,9 @@ Noise filter example
    img_path = 'path/to/image_nature.jpg'
    img = Image.open(img_path)
 
-   # set noise impact to 30
-   noisy_image = nf.gaussian_noise(img, n=30)
+   # set noise impact to 400
+   # set same noise for each chanel
+   noisy_image = nf.gaussian_noise(img, n=400, identical=True)
 
    output = Image.fromarray(noisy_image)
    output.show()

+ 1 - 0
docs/source/index.rst

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

+ 25 - 14
ipfml/filters/noise.py

@@ -4,6 +4,19 @@ import random
 from ipfml import processing
 
 
+def _normalise(x):
+
+    if isinstance(x, np.ndarray):
+        return np.array(list(map(_normalise, x)))
+
+    if x > 255:
+        return 255
+    if x < 0:
+        return 0
+
+    return x
+
+
 def _global_noise_filter(image, generator, updator, identical=False):
     """White noise filter to apply on image
 
@@ -39,7 +52,7 @@ def _global_noise_filter(image, generator, updator, identical=False):
         height, width, nb_chanel = image_array.shape
 
     if nb_chanel == 1 or identical:
-        noise_filter = generator(width, height)
+        noise_filter = generator(height, width)
 
     # final output numpy array
     output_array = []
@@ -47,12 +60,10 @@ def _global_noise_filter(image, generator, updator, identical=False):
     # check number of chanel
     if nb_chanel == 1:
 
-        image_array_flatten = image_array
-
-        noisy_image = np.array(
-            list(map(updator, image_array_flatten, noise_filter)))
+        noisy_image = np.array(list(map(updator, image_array, noise_filter)))
 
-        return np.array(noisy_image, 'uint8')
+        # normalise values
+        return np.array(list(map(_normalise, noisy_image)), 'uint8')
 
     else:
         # final output numpy array
@@ -61,7 +72,7 @@ def _global_noise_filter(image, generator, updator, identical=False):
         for chanel in range(0, nb_chanel):
 
             # getting flatten information from image and noise
-            image_array_flatten = image_array[:, :, chanel]
+            image_array_chanel = image_array[:, :, chanel]
 
             # redefine noise if necessary
             if not identical:
@@ -70,10 +81,10 @@ def _global_noise_filter(image, generator, updator, identical=False):
             # compute new pixel value
             # x + n * k * white_noise_filter[i] as example
             noisy_image = np.array(
-                list(map(updator, image_array_flatten, noise_filter)))
+                list(map(updator, image_array_chanel, noise_filter)))
 
-            # set uint8 values
-            noisy_image = np.array(noisy_image, 'uint8')
+            # normalise values
+            noisy_image = np.array(list(map(_normalise, noisy_image)), 'uint8')
 
             # in order to concatenate output array
             noisy_image = noisy_image[:, :, np.newaxis]
@@ -265,8 +276,8 @@ def log_normal_noise(image,
 def mut_white_noise(image,
                     n,
                     identical=False,
-                    distribution_interval=(-0.5, 0.5),
-                    k=0.2):
+                    distribution_interval=(0, 1),
+                    k=0.002):
     """Multiplied White noise filter to apply on image
 
     Args:
@@ -274,7 +285,7 @@ def mut_white_noise(image,
         n: used to set importance of noise [1, 999]
         identical: keep or not identical noise distribution for each canal if RGB Image (default False)
         distribution_interval: set the distribution interval of normal law 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)
+        k: variable that specifies the amount of noise to be taken into account in the output image (default 0.002)
 
     Returns:
         2D Numpy array with multiplied white noise applied
@@ -292,7 +303,7 @@ def mut_white_noise(image,
     a, b = distribution_interval
     generator = lambda h, w: np.random.uniform(a, b, (h, w))
 
-    updator = lambda x, noise: x * n * k * noise
+    updator = lambda x, noise: x * (n * k * noise)
 
     return _global_noise_filter(image, generator, updator, identical)
 

+ 1 - 1
setup.py

@@ -35,7 +35,7 @@ class BuildTestCommand(setuptools.command.build_py.build_py):
 
 setup(
     name='ipfml',
-    version='0.2.5',
+    version='0.2.6',
     description='Image Processing For Machine Learning',
     long_description=readme(),
     classifiers=[