Browse Source

Update of documentation and noise filters

Jérôme BUISINE 2 years ago
parent
commit
862b897a33

+ 4 - 1
.gitignore

@@ -10,7 +10,7 @@ __pycache__/
 # Distribution / packaging
 .Python
 env/
-#build/
+build/
 develop-eggs/
 dist/
 downloads/
@@ -55,3 +55,6 @@ coverage.xml
 # PyBuilder
 target/
 .python-version
+
+# Docs
+!docs/build

BIN
docs/build/doctrees/environment.pickle


BIN
docs/build/doctrees/ipfml.doctree


+ 30 - 20
docs/build/html/ipfml.html

@@ -1081,7 +1081,7 @@
 <dl class="function">
 <dt id="ipfml.iqa.fr.mae">
 <code class="descclassname">ipfml.iqa.fr.</code><code class="descname">mae</code><span class="sig-paren">(</span><em>img_true</em>, <em>img_test</em><span class="sig-paren">)</span><a class="headerlink" href="#ipfml.iqa.fr.mae" title="Permalink to this definition">¶</a></dt>
-<dd><p>Returns Mean-Squared Error between two Numpy arrays</p>
+<dd><p>Returns Mean Absolute Error between two Numpy arrays</p>
 <table class="docutils field-list" frame="void" rules="none">
 <col class="field-name" />
 <col class="field-body" />
@@ -1092,7 +1092,7 @@
 </ul>
 </td>
 </tr>
-<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Computed MSE score</p>
+<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Computed MAE score</p>
 </td>
 </tr>
 <tr class="field-odd field"><th class="field-name">Raises:</th><td class="field-body"><p class="first last"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NumpyShapeComparisonException</span></code> – if shape of images are not the same</p>
@@ -1101,13 +1101,13 @@
 </tbody>
 </table>
 <p class="rubric">Example</p>
-<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">ipfml</span> <span class="k">import</span> <span class="n">utils</span>
+<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">ipfml.iqa</span> <span class="k">import</span> <span class="n">fr</span>
 <span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
 <span class="gp">&gt;&gt;&gt; </span><span class="n">arr1</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
-<span class="gp">&gt;&gt;&gt; </span><span class="n">arr2</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span>
-<span class="gp">&gt;&gt;&gt; </span><span class="n">mse</span> <span class="o">=</span> <span class="n">utils</span><span class="o">.</span><span class="n">mse</span><span class="p">(</span><span class="n">arr1</span><span class="p">,</span> <span class="n">arr2</span><span class="p">)</span>
-<span class="gp">&gt;&gt;&gt; </span><span class="n">mse</span>
-<span class="go">100</span>
+<span class="gp">&gt;&gt;&gt; </span><span class="n">arr2</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="mi">15</span><span class="p">)</span>
+<span class="gp">&gt;&gt;&gt; </span><span class="n">mae_score</span> <span class="o">=</span> <span class="n">fr</span><span class="o">.</span><span class="n">mae</span><span class="p">(</span><span class="n">arr1</span><span class="p">,</span> <span class="n">arr2</span><span class="p">)</span>
+<span class="gp">&gt;&gt;&gt; </span><span class="n">mae_score</span>
+<span class="go">5.0</span>
 </pre></div>
 </div>
 </dd></dl>
@@ -1121,7 +1121,7 @@
 <dl class="function">
 <dt id="ipfml.iqa.fr.mse">
 <code class="descclassname">ipfml.iqa.fr.</code><code class="descname">mse</code><span class="sig-paren">(</span><em>img_true</em>, <em>img_test</em><span class="sig-paren">)</span><a class="headerlink" href="#ipfml.iqa.fr.mse" title="Permalink to this definition">¶</a></dt>
-<dd><p>Returns Mean-Squared Error between two Numpy arrays</p>
+<dd><p>Returns Mean-Squared Error score between two Numpy arrays</p>
 <table class="docutils field-list" frame="void" rules="none">
 <col class="field-name" />
 <col class="field-body" />
@@ -1141,13 +1141,13 @@
 </tbody>
 </table>
 <p class="rubric">Example</p>
-<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">ipfml</span> <span class="k">import</span> <span class="n">utils</span>
+<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">ipfml.iqa</span> <span class="k">import</span> <span class="n">fr</span>
 <span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
 <span class="gp">&gt;&gt;&gt; </span><span class="n">arr1</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
-<span class="gp">&gt;&gt;&gt; </span><span class="n">arr2</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span>
-<span class="gp">&gt;&gt;&gt; </span><span class="n">mse</span> <span class="o">=</span> <span class="n">utils</span><span class="o">.</span><span class="n">mse</span><span class="p">(</span><span class="n">arr1</span><span class="p">,</span> <span class="n">arr2</span><span class="p">)</span>
-<span class="gp">&gt;&gt;&gt; </span><span class="n">mse</span>
-<span class="go">100</span>
+<span class="gp">&gt;&gt;&gt; </span><span class="n">arr2</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="mi">15</span><span class="p">)</span>
+<span class="gp">&gt;&gt;&gt; </span><span class="n">mse_score</span> <span class="o">=</span> <span class="n">fr</span><span class="o">.</span><span class="n">mse</span><span class="p">(</span><span class="n">arr1</span><span class="p">,</span> <span class="n">arr2</span><span class="p">)</span>
+<span class="gp">&gt;&gt;&gt; </span><span class="n">mse_score</span>
+<span class="go">25.0</span>
 </pre></div>
 </div>
 </dd></dl>
@@ -1171,12 +1171,22 @@
 </tr>
 </tbody>
 </table>
+<p class="rubric">Example</p>
+<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">ipfml.iqa</span> <span class="k">import</span> <span class="n">fr</span>
+<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
+<span class="gp">&gt;&gt;&gt; </span><span class="n">arr1</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
+<span class="gp">&gt;&gt;&gt; </span><span class="n">arr2</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="mi">15</span><span class="p">)</span>
+<span class="gp">&gt;&gt;&gt; </span><span class="n">pnsr_score</span> <span class="o">=</span> <span class="n">fr</span><span class="o">.</span><span class="n">pnsr</span><span class="p">(</span><span class="n">arr1</span><span class="p">,</span> <span class="n">arr2</span><span class="p">)</span>
+<span class="gp">&gt;&gt;&gt; </span><span class="nb">int</span><span class="p">(</span><span class="n">pnsr_score</span><span class="p">)</span>
+<span class="go">365</span>
+</pre></div>
+</div>
 </dd></dl>
 
 <dl class="function">
 <dt id="ipfml.iqa.fr.rmse">
 <code class="descclassname">ipfml.iqa.fr.</code><code class="descname">rmse</code><span class="sig-paren">(</span><em>img_true</em>, <em>img_test</em><span class="sig-paren">)</span><a class="headerlink" href="#ipfml.iqa.fr.rmse" title="Permalink to this definition">¶</a></dt>
-<dd><p>Returns Mean-Squared Error between two Numpy arrays</p>
+<dd><p>Returns Root Mean-Squared Error score between two Numpy arrays</p>
 <table class="docutils field-list" frame="void" rules="none">
 <col class="field-name" />
 <col class="field-body" />
@@ -1187,7 +1197,7 @@
 </ul>
 </td>
 </tr>
-<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Computed MSE score</p>
+<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Computed RMSE score</p>
 </td>
 </tr>
 <tr class="field-odd field"><th class="field-name">Raises:</th><td class="field-body"><p class="first last"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NumpyShapeComparisonException</span></code> – if shape of images are not the same</p>
@@ -1196,13 +1206,13 @@
 </tbody>
 </table>
 <p class="rubric">Example</p>
-<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">ipfml</span> <span class="k">import</span> <span class="n">utils</span>
+<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">ipfml.iqa</span> <span class="k">import</span> <span class="n">fr</span>
 <span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
 <span class="gp">&gt;&gt;&gt; </span><span class="n">arr1</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
-<span class="gp">&gt;&gt;&gt; </span><span class="n">arr2</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span>
-<span class="gp">&gt;&gt;&gt; </span><span class="n">rmse</span> <span class="o">=</span> <span class="n">utils</span><span class="o">.</span><span class="n">rmse</span><span class="p">(</span><span class="n">arr1</span><span class="p">,</span> <span class="n">arr2</span><span class="p">)</span>
-<span class="gp">&gt;&gt;&gt; </span><span class="n">rmse</span>
-<span class="go">100</span>
+<span class="gp">&gt;&gt;&gt; </span><span class="n">arr2</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="mi">15</span><span class="p">)</span>
+<span class="gp">&gt;&gt;&gt; </span><span class="n">rmse_score</span> <span class="o">=</span> <span class="n">fr</span><span class="o">.</span><span class="n">rmse</span><span class="p">(</span><span class="n">arr1</span><span class="p">,</span> <span class="n">arr2</span><span class="p">)</span>
+<span class="gp">&gt;&gt;&gt; </span><span class="n">rmse_score</span>
+<span class="go">5.0</span>
 </pre></div>
 </div>
 </dd></dl>

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


+ 11 - 2
ipfml/exceptions.py

@@ -2,16 +2,25 @@
 Module which contains all customs Exceptions
 """
 
+
 class NumpyDimensionComparisonException(Exception):
     """
     Numpy dimensions comparison Exception raised if two numpy arrays provided do not have same dimensions
     """
+
     def __init__(self):
-        Exception.__init__(self, "Numpy arrays provided for comparisons do not have same dimensions")
+        Exception.__init__(
+            self,
+            "Numpy arrays provided for comparisons do not have same dimensions"
+        )
+
 
 class NumpyShapeComparisonException(Exception):
     """
     Numpy shape comparison Exception raised if two numpy arrays provided do not have same shape extactly
     """
+
     def __init__(self):
-        Exception.__init__(self, "Numpy arrays provided for comparisons do not have same shape")
+        Exception.__init__(
+            self,
+            "Numpy arrays provided for comparisons do not have same shape")

+ 2 - 2
ipfml/filters/noise.py

@@ -300,8 +300,8 @@ def mut_white_noise(image,
     (100, 100)
     """
 
-    min_value = 1 - (k/2);
-    max_value = 1 + (k/2);
+    min_value = 1 - (k / 2)
+    max_value = 1 + (k / 2)
 
     a, b = distribution_interval
     generator = lambda h, w: min_value + (np.random.uniform(a, b, (h, w)) * (max_value - min_value))

+ 41 - 23
ipfml/iqa/fr.py

@@ -1,13 +1,22 @@
 from skimage.measure import compare_ssim, compare_psnr
 from ipfml.exceptions import NumpyShapeComparisonException
 
+import numpy as np
 """
 Full-reference Image Quality Assessment (FR-IQA) methods
 """
 
-def _prepare_arrays(arr1, arr2):
-    img_true = np.asarray(img_true, dtype=float_32)
-    img_test = np.asarray(img_test, dtype=float_32)
+
+def _prepare_arrays(img_true, img_test):
+    """
+    Prepare image data
+
+    Raises:
+        NumpyShapeComparisonException: if shape of images are not the same
+    """
+
+    img_true = np.asarray(img_true, dtype='float32')
+    img_test = np.asarray(img_test, dtype='float32')
 
     if img_true.shape != img_test.shape:
         raise NumpyShapeComparisonException
@@ -16,7 +25,7 @@ def _prepare_arrays(arr1, arr2):
 
 
 def mse(img_true, img_test):
-    """Returns Mean-Squared Error between two Numpy arrays
+    """Returns Mean-Squared Error score between two Numpy arrays
 
     Args:
         img_true: Image, numpy array of any dimension
@@ -29,13 +38,13 @@ def mse(img_true, img_test):
         NumpyShapeComparisonException: if shape of images are not the same
 
     Example:
-        >>> from ipfml import utils
+        >>> from ipfml.iqa import fr
         >>> import numpy as np
         >>> arr1 = np.arange(10)
-        >>> arr2 = np.arange(5, 10)
-        >>> mse = utils.mse(arr1, arr2)
-        >>> mse
-        100
+        >>> arr2 = np.arange(5, 15)
+        >>> mse_score = fr.mse(arr1, arr2)
+        >>> mse_score
+        25.0
     """
 
     img_true, img_test = _prepare_arrays(img_true, img_test)
@@ -44,52 +53,52 @@ def mse(img_true, img_test):
 
 
 def rmse(img_true, img_test):
-    """Returns Mean-Squared Error between two Numpy arrays
+    """Returns Root Mean-Squared Error score between two Numpy arrays
 
     Args:
         img_true: Image, numpy array of any dimension
         img_test: Image, numpy array of any dimension
 
     Returns:
-        Computed MSE score
+        Computed RMSE score
 
     Raises:
         NumpyShapeComparisonException: if shape of images are not the same
 
     Example:
-        >>> from ipfml import utils
+        >>> from ipfml.iqa import fr
         >>> import numpy as np
         >>> arr1 = np.arange(10)
-        >>> arr2 = np.arange(5, 10)
-        >>> rmse = utils.rmse(arr1, arr2)
-        >>> rmse
-        100
+        >>> arr2 = np.arange(5, 15)
+        >>> rmse_score = fr.rmse(arr1, arr2)
+        >>> rmse_score
+        5.0
     """
 
     return np.sqrt(mse(img_true, img_test))
 
 
 def mae(img_true, img_test):
-    """Returns Mean-Squared Error between two Numpy arrays
+    """Returns Mean Absolute Error between two Numpy arrays
 
     Args:
         img_true: Image, numpy array of any dimension
         img_test: Image, numpy array of any dimension
 
     Returns:
-        Computed MSE score
+        Computed MAE score
 
     Raises:
         NumpyShapeComparisonException: if shape of images are not the same
 
     Example:
-        >>> from ipfml import utils
+        >>> from ipfml.iqa import fr
         >>> import numpy as np
         >>> arr1 = np.arange(10)
-        >>> arr2 = np.arange(5, 10)
-        >>> mse = utils.mse(arr1, arr2)
-        >>> mse
-        100
+        >>> arr2 = np.arange(5, 15)
+        >>> mae_score = fr.mae(arr1, arr2)
+        >>> mae_score
+        5.0
     """
 
     img_true, img_test = _prepare_arrays(img_true, img_test)
@@ -106,6 +115,15 @@ def pnsr(img_true, img_test):
 
     Returns:
         Computed PSNR score
+
+    Example:
+        >>> from ipfml.iqa import fr
+        >>> import numpy as np
+        >>> arr1 = np.arange(10)
+        >>> arr2 = np.arange(5, 15)
+        >>> pnsr_score = fr.pnsr(arr1, arr2)
+        >>> int(pnsr_score)
+        365
     """
 
     return compare_psnr(img_true, img_test)

+ 1 - 2
ipfml/utils.py

@@ -1,10 +1,9 @@
 import numpy as np
-
-
 """
 Utils functions of ipfml package
 """
 
+
 def normalize_arr(arr):
     '''Normalize data of 1D array shape
 

+ 1 - 1
setup.py

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