Parcourir la source

Add of FR-IQA metrics

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

BIN
docs/build/doctrees/environment.pickle


BIN
docs/build/doctrees/ipfml.doctree


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

@@ -1,6 +1,7 @@
 Documentation
 Documentation
 =============
 =============
 
 
+
 ipfml.metrics
 ipfml.metrics
 ---------------------------
 ---------------------------
 
 
@@ -8,6 +9,7 @@ ipfml.metrics
     :members:
     :members:
     :show-inheritance:
     :show-inheritance:
 
 
+
 ipfml.processing
 ipfml.processing
 ---------------------------
 ---------------------------
 
 
@@ -26,6 +28,7 @@ ipfml.filters.noise
     :members:
     :members:
     :show-inheritance:
     :show-inheritance:
 
 
+
 ipfml.iqa
 ipfml.iqa
 ---------------------------
 ---------------------------
 
 
@@ -36,3 +39,19 @@ ipfml.iqa.fr
     :members:
     :members:
     :show-inheritance:
     :show-inheritance:
 
 
+
+ipfml.utils
+---------------------------
+
+.. automodule:: ipfml.utils
+    :members:
+    :show-inheritance:
+
+
+ipfml.exceptions
+---------------------------
+
+.. automodule:: ipfml.exceptions
+    :members:
+    :show-inheritance:
+

+ 22 - 7
docs/build/html/genindex.html

@@ -164,6 +164,7 @@
  | <a href="#L"><strong>L</strong></a>
  | <a href="#L"><strong>L</strong></a>
  | <a href="#M"><strong>M</strong></a>
  | <a href="#M"><strong>M</strong></a>
  | <a href="#N"><strong>N</strong></a>
  | <a href="#N"><strong>N</strong></a>
+ | <a href="#P"><strong>P</strong></a>
  | <a href="#R"><strong>R</strong></a>
  | <a href="#R"><strong>R</strong></a>
  | <a href="#S"><strong>S</strong></a>
  | <a href="#S"><strong>S</strong></a>
  | <a href="#V"><strong>V</strong></a>
  | <a href="#V"><strong>V</strong></a>
@@ -237,6 +238,8 @@
 <h2 id="I">I</h2>
 <h2 id="I">I</h2>
 <table style="width: 100%" class="indextable genindextable"><tr>
 <table style="width: 100%" class="indextable genindextable"><tr>
   <td style="width: 33%; vertical-align: top;"><ul>
   <td style="width: 33%; vertical-align: top;"><ul>
+      <li><a href="ipfml.html#module-ipfml.exceptions">ipfml.exceptions (module)</a>
+</li>
       <li><a href="ipfml.html#module-ipfml.filters.noise">ipfml.filters.noise (module)</a>
       <li><a href="ipfml.html#module-ipfml.filters.noise">ipfml.filters.noise (module)</a>
 </li>
 </li>
       <li><a href="ipfml.html#module-ipfml.iqa.fr">ipfml.iqa.fr (module)</a>
       <li><a href="ipfml.html#module-ipfml.iqa.fr">ipfml.iqa.fr (module)</a>
@@ -246,6 +249,8 @@
       <li><a href="ipfml.html#module-ipfml.metrics">ipfml.metrics (module)</a>
       <li><a href="ipfml.html#module-ipfml.metrics">ipfml.metrics (module)</a>
 </li>
 </li>
       <li><a href="ipfml.html#module-ipfml.processing">ipfml.processing (module)</a>
       <li><a href="ipfml.html#module-ipfml.processing">ipfml.processing (module)</a>
+</li>
+      <li><a href="ipfml.html#module-ipfml.utils">ipfml.utils (module)</a>
 </li>
 </li>
   </ul></td>
   </ul></td>
 </tr></table>
 </tr></table>
@@ -281,13 +286,25 @@
 <h2 id="N">N</h2>
 <h2 id="N">N</h2>
 <table style="width: 100%" class="indextable genindextable"><tr>
 <table style="width: 100%" class="indextable genindextable"><tr>
   <td style="width: 33%; vertical-align: top;"><ul>
   <td style="width: 33%; vertical-align: top;"><ul>
-      <li><a href="ipfml.html#ipfml.processing.normalize_2D_arr">normalize_2D_arr() (in module ipfml.processing)</a>
+      <li><a href="ipfml.html#ipfml.utils.normalize_2D_arr">normalize_2D_arr() (in module ipfml.utils)</a>
+</li>
+      <li><a href="ipfml.html#ipfml.utils.normalize_arr">normalize_arr() (in module ipfml.utils)</a>
 </li>
 </li>
   </ul></td>
   </ul></td>
   <td style="width: 33%; vertical-align: top;"><ul>
   <td style="width: 33%; vertical-align: top;"><ul>
-      <li><a href="ipfml.html#ipfml.processing.normalize_arr">normalize_arr() (in module ipfml.processing)</a>
+      <li><a href="ipfml.html#ipfml.utils.normalize_arr_with_range">normalize_arr_with_range() (in module ipfml.utils)</a>
+</li>
+      <li><a href="ipfml.html#ipfml.exceptions.NumpyDimensionComparisonException">NumpyDimensionComparisonException</a>
 </li>
 </li>
-      <li><a href="ipfml.html#ipfml.processing.normalize_arr_with_range">normalize_arr_with_range() (in module ipfml.processing)</a>
+      <li><a href="ipfml.html#ipfml.exceptions.NumpyShapeComparisonException">NumpyShapeComparisonException</a>
+</li>
+  </ul></td>
+</tr></table>
+
+<h2 id="P">P</h2>
+<table style="width: 100%" class="indextable genindextable"><tr>
+  <td style="width: 33%; vertical-align: top;"><ul>
+      <li><a href="ipfml.html#ipfml.iqa.fr.pnsr">pnsr() (in module ipfml.iqa.fr)</a>
 </li>
 </li>
   </ul></td>
   </ul></td>
 </tr></table>
 </tr></table>
@@ -304,6 +321,8 @@
       <li><a href="ipfml.html#ipfml.processing.rgb_to_LAB_L_low_bits">rgb_to_LAB_L_low_bits() (in module ipfml.processing)</a>
       <li><a href="ipfml.html#ipfml.processing.rgb_to_LAB_L_low_bits">rgb_to_LAB_L_low_bits() (in module ipfml.processing)</a>
 </li>
 </li>
       <li><a href="ipfml.html#ipfml.processing.rgb_to_mscn">rgb_to_mscn() (in module ipfml.processing)</a>
       <li><a href="ipfml.html#ipfml.processing.rgb_to_mscn">rgb_to_mscn() (in module ipfml.processing)</a>
+</li>
+      <li><a href="ipfml.html#ipfml.iqa.fr.rmse">rmse() (in module ipfml.iqa.fr)</a>
 </li>
 </li>
   </ul></td>
   </ul></td>
 </tr></table>
 </tr></table>
@@ -312,10 +331,6 @@
 <table style="width: 100%" class="indextable genindextable"><tr>
 <table style="width: 100%" class="indextable genindextable"><tr>
   <td style="width: 33%; vertical-align: top;"><ul>
   <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><a href="ipfml.html#ipfml.filters.noise.salt_pepper_noise">salt_pepper_noise() (in module ipfml.filters.noise)</a>
-</li>
-  </ul></td>
-  <td style="width: 33%; vertical-align: top;"><ul>
-      <li><a href="ipfml.html#ipfml.iqa.fr.ssim">ssim() (in module ipfml.iqa.fr)</a>
 </li>
 </li>
   </ul></td>
   </ul></td>
 </tr></table>
 </tr></table>

+ 2 - 0
docs/build/html/index.html

@@ -173,6 +173,8 @@
 <li class="toctree-l2"><a class="reference internal" href="ipfml.html#module-ipfml.processing">ipfml.processing</a></li>
 <li class="toctree-l2"><a class="reference internal" href="ipfml.html#module-ipfml.processing">ipfml.processing</a></li>
 <li class="toctree-l2"><a class="reference internal" href="ipfml.html#ipfml-filters">ipfml.filters</a></li>
 <li class="toctree-l2"><a class="reference internal" href="ipfml.html#ipfml-filters">ipfml.filters</a></li>
 <li class="toctree-l2"><a class="reference internal" href="ipfml.html#ipfml-iqa">ipfml.iqa</a></li>
 <li class="toctree-l2"><a class="reference internal" href="ipfml.html#ipfml-iqa">ipfml.iqa</a></li>
+<li class="toctree-l2"><a class="reference internal" href="ipfml.html#module-ipfml.utils">ipfml.utils</a></li>
+<li class="toctree-l2"><a class="reference internal" href="ipfml.html#module-ipfml.exceptions">ipfml.exceptions</a></li>
 </ul>
 </ul>
 </li>
 </li>
 <li class="toctree-l1"><a class="reference internal" href="examples.html">Examples</a><ul>
 <li class="toctree-l1"><a class="reference internal" href="examples.html">Examples</a><ul>

+ 209 - 92
docs/build/html/ipfml.html

@@ -96,6 +96,8 @@
 <li class="toctree-l3"><a class="reference internal" href="#module-ipfml.iqa.fr">ipfml.iqa.fr</a></li>
 <li class="toctree-l3"><a class="reference internal" href="#module-ipfml.iqa.fr">ipfml.iqa.fr</a></li>
 </ul>
 </ul>
 </li>
 </li>
+<li class="toctree-l2"><a class="reference internal" href="#module-ipfml.utils">ipfml.utils</a></li>
+<li class="toctree-l2"><a class="reference internal" href="#module-ipfml.exceptions">ipfml.exceptions</a></li>
 </ul>
 </ul>
 </li>
 </li>
 <li class="toctree-l1"><a class="reference internal" href="examples.html">Examples</a></li>
 <li class="toctree-l1"><a class="reference internal" href="examples.html">Examples</a></li>
@@ -720,82 +722,6 @@
 </div>
 </div>
 </dd></dl>
 </dd></dl>
 
 
-<dl class="function">
-<dt id="ipfml.processing.normalize_2D_arr">
-<code class="descclassname">ipfml.processing.</code><code class="descname">normalize_2D_arr</code><span class="sig-paren">(</span><em>arr</em><span class="sig-paren">)</span><a class="headerlink" href="#ipfml.processing.normalize_2D_arr" title="Permalink to this definition">¶</a></dt>
-<dd><p>Return array normalize from its min and max values</p>
-<table class="docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>arr</strong> – 2D Numpy array</td>
-</tr>
-<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">Normalized 2D Numpy array</td>
-</tr>
-</tbody>
-</table>
-<p>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">PIL</span> <span class="k">import</span> <span class="n">Image</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">processing</span>
-<span class="gp">&gt;&gt;&gt; </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;./images/test_img.png&#39;</span><span class="p">)</span>
-<span class="gp">&gt;&gt;&gt; </span><span class="n">img_mscn</span> <span class="o">=</span> <span class="n">processing</span><span class="o">.</span><span class="n">rgb_to_mscn</span><span class="p">(</span><span class="n">img</span><span class="p">)</span>
-<span class="gp">&gt;&gt;&gt; </span><span class="n">img_normalized</span> <span class="o">=</span> <span class="n">processing</span><span class="o">.</span><span class="n">normalize_2D_arr</span><span class="p">(</span><span class="n">img_mscn</span><span class="p">)</span>
-<span class="gp">&gt;&gt;&gt; </span><span class="n">img_normalized</span><span class="o">.</span><span class="n">shape</span>
-<span class="go">(200, 200)</span>
-</pre></div>
-</div>
-</dd></dl>
-
-<dl class="function">
-<dt id="ipfml.processing.normalize_arr">
-<code class="descclassname">ipfml.processing.</code><code class="descname">normalize_arr</code><span class="sig-paren">(</span><em>arr</em><span class="sig-paren">)</span><a class="headerlink" href="#ipfml.processing.normalize_arr" title="Permalink to this definition">¶</a></dt>
-<dd><p>Normalize data of 1D array shape</p>
-<table class="docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>arr</strong> – array data of 1D shape</td>
-</tr>
-<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">Normalized 1D array</td>
-</tr>
-</tbody>
-</table>
-<p>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">processing</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">arr</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">11</span><span class="p">)</span>
-<span class="gp">&gt;&gt;&gt; </span><span class="n">arr_normalized</span> <span class="o">=</span> <span class="n">processing</span><span class="o">.</span><span class="n">normalize_arr</span><span class="p">(</span><span class="n">arr</span><span class="p">)</span>
-<span class="gp">&gt;&gt;&gt; </span><span class="n">arr_normalized</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
-<span class="go">0.1</span>
-</pre></div>
-</div>
-</dd></dl>
-
-<dl class="function">
-<dt id="ipfml.processing.normalize_arr_with_range">
-<code class="descclassname">ipfml.processing.</code><code class="descname">normalize_arr_with_range</code><span class="sig-paren">(</span><em>arr</em>, <em>min</em>, <em>max</em><span class="sig-paren">)</span><a class="headerlink" href="#ipfml.processing.normalize_arr_with_range" title="Permalink to this definition">¶</a></dt>
-<dd><p>Normalize data of 1D array shape</p>
-<table class="docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>arr</strong> – array data of 1D shape</td>
-</tr>
-<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">Normalized 1D Numpy array</td>
-</tr>
-</tbody>
-</table>
-<p>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">processing</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">arr</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">11</span><span class="p">)</span>
-<span class="gp">&gt;&gt;&gt; </span><span class="n">arr_normalized</span> <span class="o">=</span> <span class="n">processing</span><span class="o">.</span><span class="n">normalize_arr_with_range</span><span class="p">(</span><span class="n">arr</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">20</span><span class="p">)</span>
-<span class="gp">&gt;&gt;&gt; </span><span class="n">arr_normalized</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
-<span class="go">0.05</span>
-</pre></div>
-</div>
-</dd></dl>
-
 <dl class="function">
 <dl class="function">
 <dt id="ipfml.processing.rgb_to_LAB_L_bits">
 <dt id="ipfml.processing.rgb_to_LAB_L_bits">
 <code class="descclassname">ipfml.processing.</code><code class="descname">rgb_to_LAB_L_bits</code><span class="sig-paren">(</span><em>image</em>, <em>interval</em><span class="sig-paren">)</span><a class="headerlink" href="#ipfml.processing.rgb_to_LAB_L_bits" title="Permalink to this definition">¶</a></dt>
 <code class="descclassname">ipfml.processing.</code><code class="descname">rgb_to_LAB_L_bits</code><span class="sig-paren">(</span><em>image</em>, <em>interval</em><span class="sig-paren">)</span><a class="headerlink" href="#ipfml.processing.rgb_to_LAB_L_bits" title="Permalink to this definition">¶</a></dt>
@@ -1049,7 +975,7 @@
 
 
 <dl class="function">
 <dl class="function">
 <dt id="ipfml.filters.noise.mut_white_noise">
 <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.002</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>
 <dd><p>Multiplied White noise filter to apply on image</p>
 <table class="docutils field-list" frame="void" rules="none">
 <table class="docutils field-list" frame="void" rules="none">
 <col class="field-name" />
 <col class="field-name" />
@@ -1059,7 +985,7 @@
 <li><strong>image</strong> – image used as input (2D or 3D image representation)</li>
 <li><strong>image</strong> – image used as input (2D or 3D image representation)</li>
 <li><strong>n</strong> – used to set importance of noise [1, 999]</li>
 <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>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>distribution_interval</strong> – set the distribution interval of normal law distribution (default (0, 1))</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>
 <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>
 </ul>
 </td>
 </td>
@@ -1154,46 +1080,237 @@
 <span id="ipfml-iqa-fr"></span><h3>ipfml.iqa.fr<a class="headerlink" href="#module-ipfml.iqa.fr" title="Permalink to this headline">¶</a></h3>
 <span id="ipfml-iqa-fr"></span><h3>ipfml.iqa.fr<a class="headerlink" href="#module-ipfml.iqa.fr" title="Permalink to this headline">¶</a></h3>
 <dl class="function">
 <dl class="function">
 <dt id="ipfml.iqa.fr.mae">
 <dt id="ipfml.iqa.fr.mae">
-<code class="descclassname">ipfml.iqa.fr.</code><code class="descname">mae</code><span class="sig-paren">(</span><em>I</em>, <em>K</em><span class="sig-paren">)</span><a class="headerlink" href="#ipfml.iqa.fr.mae" title="Permalink to this definition">¶</a></dt>
-<dd></dd></dl>
+<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>
+<table class="docutils field-list" frame="void" rules="none">
+<col class="field-name" />
+<col class="field-body" />
+<tbody valign="top">
+<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
+<li><strong>img_true</strong> – Image, numpy array of any dimension</li>
+<li><strong>img_test</strong> – Image, numpy array of any dimension</li>
+</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>
+</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>
+</td>
+</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</span> <span class="k">import</span> <span class="n">utils</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>
+</pre></div>
+</div>
+</dd></dl>
 
 
 <dl class="function">
 <dl class="function">
 <dt id="ipfml.iqa.fr.ms_ssim">
 <dt id="ipfml.iqa.fr.ms_ssim">
-<code class="descclassname">ipfml.iqa.fr.</code><code class="descname">ms_ssim</code><span class="sig-paren">(</span><em>I</em>, <em>K</em><span class="sig-paren">)</span><a class="headerlink" href="#ipfml.iqa.fr.ms_ssim" title="Permalink to this definition">¶</a></dt>
-<dd></dd></dl>
+<code class="descclassname">ipfml.iqa.fr.</code><code class="descname">ms_ssim</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.ms_ssim" title="Permalink to this definition">¶</a></dt>
+<dd><p>Implemented later..</p>
+</dd></dl>
 
 
 <dl class="function">
 <dl class="function">
 <dt id="ipfml.iqa.fr.mse">
 <dt id="ipfml.iqa.fr.mse">
-<code class="descclassname">ipfml.iqa.fr.</code><code class="descname">mse</code><span class="sig-paren">(</span><em>I</em>, <em>K</em><span class="sig-paren">)</span><a class="headerlink" href="#ipfml.iqa.fr.mse" title="Permalink to this definition">¶</a></dt>
-<dd><p>Returns difference between two images</p>
+<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>
 <table class="docutils field-list" frame="void" rules="none">
 <table class="docutils field-list" frame="void" rules="none">
 <col class="field-name" />
 <col class="field-name" />
 <col class="field-body" />
 <col class="field-body" />
 <tbody valign="top">
 <tbody valign="top">
 <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
 <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
-<li><strong>I</strong> – PIL Image or Numpy array</li>
-<li><strong>K</strong> – PIL Image or Numpy array</li>
+<li><strong>img_true</strong> – Image, numpy array of any dimension</li>
+<li><strong>img_test</strong> – Image, numpy array of any dimension</li>
 </ul>
 </ul>
 </td>
 </td>
 </tr>
 </tr>
-<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">comparison score between these two images</p>
+<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Computed MSE 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>
 </td>
 </td>
 </tr>
 </tr>
 </tbody>
 </tbody>
 </table>
 </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>
+<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>
+</pre></div>
+</div>
 </dd></dl>
 </dd></dl>
 
 
 <dl class="function">
 <dl class="function">
-<dt id="ipfml.iqa.fr.ssim">
-<code class="descclassname">ipfml.iqa.fr.</code><code class="descname">ssim</code><span class="sig-paren">(</span><em>I</em>, <em>K</em><span class="sig-paren">)</span><a class="headerlink" href="#ipfml.iqa.fr.ssim" title="Permalink to this definition">¶</a></dt>
-<dd></dd></dl>
+<dt id="ipfml.iqa.fr.pnsr">
+<code class="descclassname">ipfml.iqa.fr.</code><code class="descname">pnsr</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.pnsr" title="Permalink to this definition">¶</a></dt>
+<dd><p>Returns the computed Peak Signal to Noise Ratio (PSNR) between two images</p>
+<table class="docutils field-list" frame="void" rules="none">
+<col class="field-name" />
+<col class="field-body" />
+<tbody valign="top">
+<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
+<li><strong>img_true</strong> – Image, numpy array of any dimension</li>
+<li><strong>img_test</strong> – Image, numpy array of any dimension</li>
+</ul>
+</td>
+</tr>
+<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">Computed PSNR score</p>
+</td>
+</tr>
+</tbody>
+</table>
+</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>
+<table class="docutils field-list" frame="void" rules="none">
+<col class="field-name" />
+<col class="field-body" />
+<tbody valign="top">
+<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
+<li><strong>img_true</strong> – Image, numpy array of any dimension</li>
+<li><strong>img_test</strong> – Image, numpy array of any dimension</li>
+</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>
+</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>
+</td>
+</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</span> <span class="k">import</span> <span class="n">utils</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>
+</pre></div>
+</div>
+</dd></dl>
 
 
 <dl class="function">
 <dl class="function">
 <dt id="ipfml.iqa.fr.vif">
 <dt id="ipfml.iqa.fr.vif">
-<code class="descclassname">ipfml.iqa.fr.</code><code class="descname">vif</code><span class="sig-paren">(</span><em>I</em>, <em>K</em><span class="sig-paren">)</span><a class="headerlink" href="#ipfml.iqa.fr.vif" title="Permalink to this definition">¶</a></dt>
-<dd></dd></dl>
+<code class="descclassname">ipfml.iqa.fr.</code><code class="descname">vif</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.vif" title="Permalink to this definition">¶</a></dt>
+<dd><p>Implemented later..</p>
+</dd></dl>
 
 
 </div>
 </div>
+</div>
+<div class="section" id="module-ipfml.utils">
+<span id="ipfml-utils"></span><h2>ipfml.utils<a class="headerlink" href="#module-ipfml.utils" title="Permalink to this headline">¶</a></h2>
+<dl class="function">
+<dt id="ipfml.utils.normalize_2D_arr">
+<code class="descclassname">ipfml.utils.</code><code class="descname">normalize_2D_arr</code><span class="sig-paren">(</span><em>arr</em><span class="sig-paren">)</span><a class="headerlink" href="#ipfml.utils.normalize_2D_arr" title="Permalink to this definition">¶</a></dt>
+<dd><p>Return array normalize from its min and max values</p>
+<table class="docutils field-list" frame="void" rules="none">
+<col class="field-name" />
+<col class="field-body" />
+<tbody valign="top">
+<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>arr</strong> – 2D Numpy array</td>
+</tr>
+<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">Normalized 2D Numpy array</td>
+</tr>
+</tbody>
+</table>
+<p>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">PIL</span> <span class="k">import</span> <span class="n">Image</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><span class="p">,</span> <span class="n">processing</span>
+<span class="gp">&gt;&gt;&gt; </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;./images/test_img.png&#39;</span><span class="p">)</span>
+<span class="gp">&gt;&gt;&gt; </span><span class="n">img_mscn</span> <span class="o">=</span> <span class="n">processing</span><span class="o">.</span><span class="n">rgb_to_mscn</span><span class="p">(</span><span class="n">img</span><span class="p">)</span>
+<span class="gp">&gt;&gt;&gt; </span><span class="n">img_normalized</span> <span class="o">=</span> <span class="n">utils</span><span class="o">.</span><span class="n">normalize_2D_arr</span><span class="p">(</span><span class="n">img_mscn</span><span class="p">)</span>
+<span class="gp">&gt;&gt;&gt; </span><span class="n">img_normalized</span><span class="o">.</span><span class="n">shape</span>
+<span class="go">(200, 200)</span>
+</pre></div>
+</div>
+</dd></dl>
+
+<dl class="function">
+<dt id="ipfml.utils.normalize_arr">
+<code class="descclassname">ipfml.utils.</code><code class="descname">normalize_arr</code><span class="sig-paren">(</span><em>arr</em><span class="sig-paren">)</span><a class="headerlink" href="#ipfml.utils.normalize_arr" title="Permalink to this definition">¶</a></dt>
+<dd><p>Normalize data of 1D array shape</p>
+<table class="docutils field-list" frame="void" rules="none">
+<col class="field-name" />
+<col class="field-body" />
+<tbody valign="top">
+<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>arr</strong> – array data of 1D shape</td>
+</tr>
+<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">Normalized 1D array</td>
+</tr>
+</tbody>
+</table>
+<p>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>
+<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">arr</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">11</span><span class="p">)</span>
+<span class="gp">&gt;&gt;&gt; </span><span class="n">arr_normalized</span> <span class="o">=</span> <span class="n">utils</span><span class="o">.</span><span class="n">normalize_arr</span><span class="p">(</span><span class="n">arr</span><span class="p">)</span>
+<span class="gp">&gt;&gt;&gt; </span><span class="n">arr_normalized</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
+<span class="go">0.1</span>
+</pre></div>
+</div>
+</dd></dl>
+
+<dl class="function">
+<dt id="ipfml.utils.normalize_arr_with_range">
+<code class="descclassname">ipfml.utils.</code><code class="descname">normalize_arr_with_range</code><span class="sig-paren">(</span><em>arr</em>, <em>min</em>, <em>max</em><span class="sig-paren">)</span><a class="headerlink" href="#ipfml.utils.normalize_arr_with_range" title="Permalink to this definition">¶</a></dt>
+<dd><p>Normalize data of 1D array shape</p>
+<table class="docutils field-list" frame="void" rules="none">
+<col class="field-name" />
+<col class="field-body" />
+<tbody valign="top">
+<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>arr</strong> – array data of 1D shape</td>
+</tr>
+<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">Normalized 1D Numpy array</td>
+</tr>
+</tbody>
+</table>
+<p>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">processing</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">arr</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">11</span><span class="p">)</span>
+<span class="gp">&gt;&gt;&gt; </span><span class="n">arr_normalized</span> <span class="o">=</span> <span class="n">processing</span><span class="o">.</span><span class="n">normalize_arr_with_range</span><span class="p">(</span><span class="n">arr</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">20</span><span class="p">)</span>
+<span class="gp">&gt;&gt;&gt; </span><span class="n">arr_normalized</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
+<span class="go">0.05</span>
+</pre></div>
+</div>
+</dd></dl>
+
+</div>
+<div class="section" id="module-ipfml.exceptions">
+<span id="ipfml-exceptions"></span><h2>ipfml.exceptions<a class="headerlink" href="#module-ipfml.exceptions" title="Permalink to this headline">¶</a></h2>
+<p>Module which contains all customs Exceptions</p>
+<dl class="exception">
+<dt id="ipfml.exceptions.NumpyDimensionComparisonException">
+<em class="property">exception </em><code class="descclassname">ipfml.exceptions.</code><code class="descname">NumpyDimensionComparisonException</code><a class="headerlink" href="#ipfml.exceptions.NumpyDimensionComparisonException" title="Permalink to this definition">¶</a></dt>
+<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">Exception</span></code></p>
+<p>Numpy dimensions comparison Exception raised if two numpy arrays provided do not have same dimensions</p>
+</dd></dl>
+
+<dl class="exception">
+<dt id="ipfml.exceptions.NumpyShapeComparisonException">
+<em class="property">exception </em><code class="descclassname">ipfml.exceptions.</code><code class="descname">NumpyShapeComparisonException</code><a class="headerlink" href="#ipfml.exceptions.NumpyShapeComparisonException" title="Permalink to this definition">¶</a></dt>
+<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">Exception</span></code></p>
+<p>Numpy shape comparison Exception raised if two numpy arrays provided do not have same shape extactly</p>
+</dd></dl>
+
 </div>
 </div>
 </div>
 </div>
 
 

BIN
docs/build/html/objects.inv


+ 10 - 0
docs/build/html/py-modindex.html

@@ -166,6 +166,11 @@
        <td>
        <td>
        <code class="xref">ipfml</code></td><td>
        <code class="xref">ipfml</code></td><td>
        <em></em></td></tr>
        <em></em></td></tr>
+     <tr class="cg-1">
+       <td></td>
+       <td>&#160;&#160;&#160;
+       <a href="ipfml.html#module-ipfml.exceptions"><code class="xref">ipfml.exceptions</code></a></td><td>
+       <em></em></td></tr>
      <tr class="cg-1">
      <tr class="cg-1">
        <td></td>
        <td></td>
        <td>&#160;&#160;&#160;
        <td>&#160;&#160;&#160;
@@ -186,6 +191,11 @@
        <td>&#160;&#160;&#160;
        <td>&#160;&#160;&#160;
        <a href="ipfml.html#module-ipfml.processing"><code class="xref">ipfml.processing</code></a></td><td>
        <a href="ipfml.html#module-ipfml.processing"><code class="xref">ipfml.processing</code></a></td><td>
        <em></em></td></tr>
        <em></em></td></tr>
+     <tr class="cg-1">
+       <td></td>
+       <td>&#160;&#160;&#160;
+       <a href="ipfml.html#module-ipfml.utils"><code class="xref">ipfml.utils</code></a></td><td>
+       <em></em></td></tr>
    </table>
    </table>
 
 
 
 

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


+ 19 - 0
docs/source/ipfml.rst

@@ -1,6 +1,7 @@
 Documentation
 Documentation
 =============
 =============
 
 
+
 ipfml.metrics
 ipfml.metrics
 ---------------------------
 ---------------------------
 
 
@@ -8,6 +9,7 @@ ipfml.metrics
     :members:
     :members:
     :show-inheritance:
     :show-inheritance:
 
 
+
 ipfml.processing
 ipfml.processing
 ---------------------------
 ---------------------------
 
 
@@ -26,6 +28,7 @@ ipfml.filters.noise
     :members:
     :members:
     :show-inheritance:
     :show-inheritance:
 
 
+
 ipfml.iqa
 ipfml.iqa
 ---------------------------
 ---------------------------
 
 
@@ -36,3 +39,19 @@ ipfml.iqa.fr
     :members:
     :members:
     :show-inheritance:
     :show-inheritance:
 
 
+
+ipfml.utils
+---------------------------
+
+.. automodule:: ipfml.utils
+    :members:
+    :show-inheritance:
+
+
+ipfml.exceptions
+---------------------------
+
+.. automodule:: ipfml.exceptions
+    :members:
+    :show-inheritance:
+

+ 17 - 0
ipfml/exceptions.py

@@ -0,0 +1,17 @@
+"""
+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")
+
+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")

+ 102 - 17
ipfml/iqa/fr.py

@@ -1,40 +1,125 @@
-# Add PNSR, SSIM, VIF
+from skimage.measure import compare_ssim, compare_psnr
+from ipfml.exceptions import NumpyShapeComparisonException
 
 
+"""
+Full-reference Image Quality Assessment (FR-IQA) methods
+"""
 
 
-def pnsr(img, dist_img):
+def _prepare_arrays(arr1, arr2):
+    img_true = np.asarray(img_true, dtype=float_32)
+    img_test = np.asarray(img_test, dtype=float_32)
+
+    if img_true.shape != img_test.shape:
+        raise NumpyShapeComparisonException
+
+    return img_true, img_test
 
 
-    pass
 
 
-def mse(I, K):
-    """Returns difference between two images
+def mse(img_true, img_test):
+    """Returns Mean-Squared Error between two Numpy arrays
 
 
     Args:
     Args:
-        I: PIL Image or Numpy array
-        K: PIL Image or Numpy array
+        img_true: Image, numpy array of any dimension
+        img_test: Image, numpy array of any dimension
 
 
     Returns:
     Returns:
-        comparison score between these two images
-    """
-    pass
+        Computed MSE score
 
 
-def mae(I, K):
-    """
+    Raises:
+        NumpyShapeComparisonException: if shape of images are not the same
 
 
+    Example:
+        >>> from ipfml import utils
+        >>> import numpy as np
+        >>> arr1 = np.arange(10)
+        >>> arr2 = np.arange(5, 10)
+        >>> mse = utils.mse(arr1, arr2)
+        >>> mse
+        100
     """
     """
-    pass
 
 
+    img_true, img_test = _prepare_arrays(img_true, img_test)
 
 
-def ssim(I, K):
-    """
+    return np.mean(np.square(img_true - img_test), dtype=np.float64)
+
+
+def rmse(img_true, img_test):
+    """Returns Mean-Squared 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
+
+    Raises:
+        NumpyShapeComparisonException: if shape of images are not the same
+
+    Example:
+        >>> from ipfml import utils
+        >>> import numpy as np
+        >>> arr1 = np.arange(10)
+        >>> arr2 = np.arange(5, 10)
+        >>> rmse = utils.rmse(arr1, arr2)
+        >>> rmse
+        100
     """
     """
 
 
-def ms_ssim(I, K):
+    return np.sqrt(mse(img_true, img_test))
+
+
+def mae(img_true, img_test):
+    """Returns Mean-Squared 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
+
+    Raises:
+        NumpyShapeComparisonException: if shape of images are not the same
+
+    Example:
+        >>> from ipfml import utils
+        >>> import numpy as np
+        >>> arr1 = np.arange(10)
+        >>> arr2 = np.arange(5, 10)
+        >>> mse = utils.mse(arr1, arr2)
+        >>> mse
+        100
     """
     """
 
 
+    img_true, img_test = _prepare_arrays(img_true, img_test)
+
+    return np.mean(np.absolute(img_true - img_test), dtype=np.float64)
+
+
+def pnsr(img_true, img_test):
+    """Returns the computed Peak Signal to Noise Ratio (PSNR) between two images
+
+    Args:
+        img_true: Image, numpy array of any dimension
+        img_test: Image, numpy array of any dimension
+
+    Returns:
+        Computed PSNR score
     """
     """
 
 
-def vif(I, K):
+    return compare_psnr(img_true, img_test)
+
+
+def ms_ssim(img_true, img_test):
+    """
+    Implemented later..
     """
     """
+    pass
+
 
 
+def vif(img_true, img_test):
     """
     """
+    Implemented later..
+    """
+    pass

+ 0 - 92
ipfml/processing.py

@@ -186,98 +186,6 @@ def divide_in_blocks(image, block_size, pil=True):
     return blocks
     return blocks
 
 
 
 
-def normalize_arr(arr):
-    '''Normalize data of 1D array shape
-
-    Args:
-        arr: array data of 1D shape
-
-    Returns:
-        Normalized 1D array
-
-    Example:
-
-    >>> from ipfml import processing
-    >>> import numpy as np
-    >>> arr = np.arange(11)
-    >>> arr_normalized = processing.normalize_arr(arr)
-    >>> arr_normalized[1]
-    0.1
-    '''
-
-    output_arr = []
-    max_value = max(arr)
-    min_value = min(arr)
-
-    for v in arr:
-        output_arr.append((v - min_value) / (max_value - min_value))
-
-    return output_arr
-
-
-def normalize_arr_with_range(arr, min, max):
-    '''Normalize data of 1D array shape
-
-    Args:
-        arr: array data of 1D shape
-
-    Returns:
-        Normalized 1D Numpy array
-
-    Example:
-
-    >>> from ipfml import processing
-    >>> import numpy as np
-    >>> arr = np.arange(11)
-    >>> arr_normalized = processing.normalize_arr_with_range(arr, 0, 20)
-    >>> arr_normalized[1]
-    0.05
-    '''
-
-    output_arr = []
-
-    for v in arr:
-        output_arr.append((v - min) / (max - min))
-
-    return output_arr
-
-
-def normalize_2D_arr(arr):
-    """Return array normalize from its min and max values
-
-    Args:
-        arr: 2D Numpy array
-
-    Returns:
-        Normalized 2D Numpy array
-
-    Example:
-
-    >>> from PIL import Image
-    >>> from ipfml import processing
-    >>> img = Image.open('./images/test_img.png')
-    >>> img_mscn = processing.rgb_to_mscn(img)
-    >>> img_normalized = processing.normalize_2D_arr(img_mscn)
-    >>> img_normalized.shape
-    (200, 200)
-    """
-
-    # getting min and max value from 2D array
-    max_value = arr.max(axis=1).max()
-    min_value = arr.min(axis=1).min()
-
-    # normalize each row
-    output_array = []
-    width, height = arr.shape
-
-    for row_index in range(0, height):
-        values = arr[row_index, :]
-        output_array.append(
-            normalize_arr_with_range(values, min_value, max_value))
-
-    return np.asarray(output_array)
-
-
 def rgb_to_mscn(image):
 def rgb_to_mscn(image):
     """Convert RGB Image into Mean Subtracted Contrast Normalized (MSCN)
     """Convert RGB Image into Mean Subtracted Contrast Normalized (MSCN)
 
 

+ 97 - 0
ipfml/utils.py

@@ -0,0 +1,97 @@
+import numpy as np
+
+
+"""
+Utils functions of ipfml package
+"""
+
+def normalize_arr(arr):
+    '''Normalize data of 1D array shape
+
+    Args:
+        arr: array data of 1D shape
+
+    Returns:
+        Normalized 1D array
+
+    Example:
+
+    >>> from ipfml import utils
+    >>> import numpy as np
+    >>> arr = np.arange(11)
+    >>> arr_normalized = utils.normalize_arr(arr)
+    >>> arr_normalized[1]
+    0.1
+    '''
+
+    output_arr = []
+    max_value = max(arr)
+    min_value = min(arr)
+
+    for v in arr:
+        output_arr.append((v - min_value) / (max_value - min_value))
+
+    return output_arr
+
+
+def normalize_arr_with_range(arr, min, max):
+    '''Normalize data of 1D array shape
+
+    Args:
+        arr: array data of 1D shape
+
+    Returns:
+        Normalized 1D Numpy array
+
+    Example:
+
+    >>> from ipfml import processing
+    >>> import numpy as np
+    >>> arr = np.arange(11)
+    >>> arr_normalized = processing.normalize_arr_with_range(arr, 0, 20)
+    >>> arr_normalized[1]
+    0.05
+    '''
+
+    output_arr = []
+
+    for v in arr:
+        output_arr.append((v - min) / (max - min))
+
+    return output_arr
+
+
+def normalize_2D_arr(arr):
+    """Return array normalize from its min and max values
+
+    Args:
+        arr: 2D Numpy array
+
+    Returns:
+        Normalized 2D Numpy array
+
+    Example:
+
+    >>> from PIL import Image
+    >>> from ipfml import utils, processing
+    >>> img = Image.open('./images/test_img.png')
+    >>> img_mscn = processing.rgb_to_mscn(img)
+    >>> img_normalized = utils.normalize_2D_arr(img_mscn)
+    >>> img_normalized.shape
+    (200, 200)
+    """
+
+    # getting min and max value from 2D array
+    max_value = arr.max(axis=1).max()
+    min_value = arr.min(axis=1).min()
+
+    # normalize each row
+    output_array = []
+    width, height = arr.shape
+
+    for row_index in range(0, height):
+        values = arr[row_index, :]
+        output_array.append(
+            normalize_arr_with_range(values, min_value, max_value))
+
+    return np.asarray(output_array)