Parcourir la source

Add of MSCN coefficients processing function

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

BIN
docs/build/doctrees/environment.pickle


BIN
docs/build/doctrees/ipfml/ipfml.processing.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: 9cc5ffaae73bff096a40a243083d6a12
+config: b62be055d9befed35a84e386cd584bb4
 tags: 645f666f9bcd5a90fca523b33c5a78b7

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

@@ -8,7 +8,7 @@
   
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   
-  <title>Overview: module code &mdash; IPFML v0.3.4 documentation</title>
+  <title>Overview: module code &mdash; IPFML v0.3.5 documentation</title>
   
 
   
@@ -56,7 +56,7 @@
             
             
               <div class="version">
-                0.3.4
+                0.3.5
               </div>
             
           

+ 2 - 2
docs/build/html/_modules/ipfml/exceptions.html

@@ -8,7 +8,7 @@
   
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   
-  <title>ipfml.exceptions &mdash; IPFML v0.3.4 documentation</title>
+  <title>ipfml.exceptions &mdash; IPFML v0.3.5 documentation</title>
   
 
   
@@ -56,7 +56,7 @@
             
             
               <div class="version">
-                0.3.4
+                0.3.5
               </div>
             
           

+ 2 - 2
docs/build/html/_modules/ipfml/filters/noise.html

@@ -8,7 +8,7 @@
   
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   
-  <title>ipfml.filters.noise &mdash; IPFML v0.3.4 documentation</title>
+  <title>ipfml.filters.noise &mdash; IPFML v0.3.5 documentation</title>
   
 
   
@@ -56,7 +56,7 @@
             
             
               <div class="version">
-                0.3.4
+                0.3.5
               </div>
             
           

+ 2 - 2
docs/build/html/_modules/ipfml/iqa/fr.html

@@ -8,7 +8,7 @@
   
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   
-  <title>ipfml.iqa.fr &mdash; IPFML v0.3.4 documentation</title>
+  <title>ipfml.iqa.fr &mdash; IPFML v0.3.5 documentation</title>
   
 
   
@@ -56,7 +56,7 @@
             
             
               <div class="version">
-                0.3.4
+                0.3.5
               </div>
             
           

+ 2 - 2
docs/build/html/_modules/ipfml/metrics.html

@@ -8,7 +8,7 @@
   
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   
-  <title>ipfml.metrics &mdash; IPFML v0.3.4 documentation</title>
+  <title>ipfml.metrics &mdash; IPFML v0.3.5 documentation</title>
   
 
   
@@ -56,7 +56,7 @@
             
             
               <div class="version">
-                0.3.4
+                0.3.5
               </div>
             
           

Fichier diff supprimé car celui-ci est trop grand
+ 69 - 4
docs/build/html/_modules/ipfml/processing.html


+ 2 - 2
docs/build/html/_modules/ipfml/utils.html

@@ -8,7 +8,7 @@
   
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   
-  <title>ipfml.utils &mdash; IPFML v0.3.4 documentation</title>
+  <title>ipfml.utils &mdash; IPFML v0.3.5 documentation</title>
   
 
   
@@ -56,7 +56,7 @@
             
             
               <div class="version">
-                0.3.4
+                0.3.5
               </div>
             
           

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

@@ -15,6 +15,7 @@ ipfml.processing
       get_LAB_L_SVD_U
       get_LAB_L_SVD_V
       get_LAB_L_SVD_s
+      get_mscn_coefficients
       rgb_to_LAB_L_bits
       rgb_to_LAB_L_low_bits
       rgb_to_grey_low_bits

+ 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.3.4',
+    VERSION: 'v0.3.5',
     LANGUAGE: 'None',
     COLLAPSE_INDEX: false,
     FILE_SUFFIX: '.html',

+ 2 - 2
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.3.4 documentation</title>
+  <title>Contributing &mdash; IPFML v0.3.5 documentation</title>
   
 
   
@@ -57,7 +57,7 @@
             
             
               <div class="version">
-                0.3.4
+                0.3.5
               </div>
             
           

+ 2 - 2
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.3.4 documentation</title>
+  <title>Description &mdash; IPFML v0.3.5 documentation</title>
   
 
   
@@ -58,7 +58,7 @@
             
             
               <div class="version">
-                0.3.4
+                0.3.5
               </div>
             
           

+ 2 - 2
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.3.4 documentation</title>
+  <title>Examples &mdash; IPFML v0.3.5 documentation</title>
   
 
   
@@ -58,7 +58,7 @@
             
             
               <div class="version">
-                0.3.4
+                0.3.5
               </div>
             
           

+ 4 - 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.3.4 documentation</title>
+  <title>Index &mdash; IPFML v0.3.5 documentation</title>
   
 
   
@@ -57,7 +57,7 @@
             
             
               <div class="version">
-                0.3.4
+                0.3.5
               </div>
             
           
@@ -226,6 +226,8 @@
       <li><a href="ipfml/ipfml.processing.html#ipfml.processing.get_LAB_L_SVD_V">get_LAB_L_SVD_V() (in module ipfml.processing)</a>
 </li>
       <li><a href="ipfml/ipfml.metrics.html#ipfml.metrics.get_low_bits_img">get_low_bits_img() (in module ipfml.metrics)</a>
+</li>
+      <li><a href="ipfml/ipfml.processing.html#ipfml.processing.get_mscn_coefficients">get_mscn_coefficients() (in module ipfml.processing)</a>
 </li>
       <li><a href="ipfml/ipfml.metrics.html#ipfml.metrics.get_SVD">get_SVD() (in module ipfml.metrics)</a>
 </li>

+ 2 - 2
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.3.4 documentation</title>
+  <title>Image Processing For Machine Learning &mdash; IPFML v0.3.5 documentation</title>
   
 
   
@@ -57,7 +57,7 @@
             
             
               <div class="version">
-                0.3.4
+                0.3.5
               </div>
             
           

+ 2 - 2
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.3.4 documentation</title>
+  <title>Documentation &mdash; IPFML v0.3.5 documentation</title>
   
 
   
@@ -58,7 +58,7 @@
             
             
               <div class="version">
-                0.3.4
+                0.3.5
               </div>
             
           

+ 2 - 2
docs/build/html/ipfml/ipfml.exceptions.html

@@ -8,7 +8,7 @@
   
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   
-  <title>ipfml.exceptions &mdash; IPFML v0.3.4 documentation</title>
+  <title>ipfml.exceptions &mdash; IPFML v0.3.5 documentation</title>
   
 
   
@@ -58,7 +58,7 @@
             
             
               <div class="version">
-                0.3.4
+                0.3.5
               </div>
             
           

+ 2 - 2
docs/build/html/ipfml/ipfml.filters.noise.html

@@ -8,7 +8,7 @@
   
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   
-  <title>ipfml.filters.noise &mdash; IPFML v0.3.4 documentation</title>
+  <title>ipfml.filters.noise &mdash; IPFML v0.3.5 documentation</title>
   
 
   
@@ -58,7 +58,7 @@
             
             
               <div class="version">
-                0.3.4
+                0.3.5
               </div>
             
           

+ 2 - 2
docs/build/html/ipfml/ipfml.iqa.fr.html

@@ -8,7 +8,7 @@
   
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   
-  <title>ipfml.iqa.fr &mdash; IPFML v0.3.4 documentation</title>
+  <title>ipfml.iqa.fr &mdash; IPFML v0.3.5 documentation</title>
   
 
   
@@ -58,7 +58,7 @@
             
             
               <div class="version">
-                0.3.4
+                0.3.5
               </div>
             
           

+ 2 - 2
docs/build/html/ipfml/ipfml.metrics.html

@@ -8,7 +8,7 @@
   
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   
-  <title>ipfml.metrics &mdash; IPFML v0.3.4 documentation</title>
+  <title>ipfml.metrics &mdash; IPFML v0.3.5 documentation</title>
   
 
   
@@ -58,7 +58,7 @@
             
             
               <div class="version">
-                0.3.4
+                0.3.5
               </div>
             
           

+ 44 - 7
docs/build/html/ipfml/ipfml.processing.html

@@ -8,7 +8,7 @@
   
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   
-  <title>ipfml.processing &mdash; IPFML v0.3.4 documentation</title>
+  <title>ipfml.processing &mdash; IPFML v0.3.5 documentation</title>
   
 
   
@@ -58,7 +58,7 @@
             
             
               <div class="version">
-                0.3.4
+                0.3.5
               </div>
             
           
@@ -192,19 +192,22 @@
 <tr class="row-even"><td><a class="reference internal" href="#ipfml.processing.get_LAB_L_SVD_s" title="ipfml.processing.get_LAB_L_SVD_s"><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_LAB_L_SVD_s</span></code></a>(image)</td>
 <td>Returns s (Singular values) SVD from L of LAB Image information</td>
 </tr>
-<tr class="row-odd"><td><a class="reference internal" href="#ipfml.processing.rgb_to_LAB_L_bits" title="ipfml.processing.rgb_to_LAB_L_bits"><code class="xref py py-obj docutils literal notranslate"><span class="pre">rgb_to_LAB_L_bits</span></code></a>(image,&nbsp;interval)</td>
+<tr class="row-odd"><td><a class="reference internal" href="#ipfml.processing.get_mscn_coefficients" title="ipfml.processing.get_mscn_coefficients"><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_mscn_coefficients</span></code></a>(image)</td>
+<td>Compute the Mean Substracted Constrast Normalized coefficients of an image</td>
+</tr>
+<tr class="row-even"><td><a class="reference internal" href="#ipfml.processing.rgb_to_LAB_L_bits" title="ipfml.processing.rgb_to_LAB_L_bits"><code class="xref py py-obj docutils literal notranslate"><span class="pre">rgb_to_LAB_L_bits</span></code></a>(image,&nbsp;interval)</td>
 <td>Returns only bits from LAB L canal specified into the interval</td>
 </tr>
-<tr class="row-even"><td><a class="reference internal" href="#ipfml.processing.rgb_to_LAB_L_low_bits" title="ipfml.processing.rgb_to_LAB_L_low_bits"><code class="xref py py-obj docutils literal notranslate"><span class="pre">rgb_to_LAB_L_low_bits</span></code></a>(image[,&nbsp;nb_bits])</td>
+<tr class="row-odd"><td><a class="reference internal" href="#ipfml.processing.rgb_to_LAB_L_low_bits" title="ipfml.processing.rgb_to_LAB_L_low_bits"><code class="xref py py-obj docutils literal notranslate"><span class="pre">rgb_to_LAB_L_low_bits</span></code></a>(image[,&nbsp;nb_bits])</td>
 <td>Convert RGB Image into Lab L channel image using only 4 low bits values</td>
 </tr>
-<tr class="row-odd"><td><a class="reference internal" href="#ipfml.processing.rgb_to_grey_low_bits" title="ipfml.processing.rgb_to_grey_low_bits"><code class="xref py py-obj docutils literal notranslate"><span class="pre">rgb_to_grey_low_bits</span></code></a>(image[,&nbsp;nb_bits])</td>
+<tr class="row-even"><td><a class="reference internal" href="#ipfml.processing.rgb_to_grey_low_bits" title="ipfml.processing.rgb_to_grey_low_bits"><code class="xref py py-obj docutils literal notranslate"><span class="pre">rgb_to_grey_low_bits</span></code></a>(image[,&nbsp;nb_bits])</td>
 <td>Convert RGB Image into grey image using only 4 low bits values</td>
 </tr>
-<tr class="row-even"><td><a class="reference internal" href="#ipfml.processing.rgb_to_mscn" title="ipfml.processing.rgb_to_mscn"><code class="xref py py-obj docutils literal notranslate"><span class="pre">rgb_to_mscn</span></code></a>(image)</td>
+<tr class="row-odd"><td><a class="reference internal" href="#ipfml.processing.rgb_to_mscn" title="ipfml.processing.rgb_to_mscn"><code class="xref py py-obj docutils literal notranslate"><span class="pre">rgb_to_mscn</span></code></a>(image)</td>
 <td>Convert RGB Image into Mean Subtracted Contrast Normalized (MSCN)</td>
 </tr>
-<tr class="row-odd"><td><a class="reference internal" href="#ipfml.processing.rotate_image" title="ipfml.processing.rotate_image"><code class="xref py py-obj docutils literal notranslate"><span class="pre">rotate_image</span></code></a>(image[,&nbsp;angle,&nbsp;pil])</td>
+<tr class="row-even"><td><a class="reference internal" href="#ipfml.processing.rotate_image" title="ipfml.processing.rotate_image"><code class="xref py py-obj docutils literal notranslate"><span class="pre">rotate_image</span></code></a>(image[,&nbsp;angle,&nbsp;pil])</td>
 <td>Rotate image using specific angle</td>
 </tr>
 </tbody>
@@ -397,6 +400,40 @@
 </div>
 </dd></dl>
 
+<dl class="function">
+<dt id="ipfml.processing.get_mscn_coefficients">
+<code class="descclassname">ipfml.processing.</code><code class="descname">get_mscn_coefficients</code><span class="sig-paren">(</span><em>image</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/ipfml/processing.html#get_mscn_coefficients"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#ipfml.processing.get_mscn_coefficients" title="Permalink to this definition">¶</a></dt>
+<dd><p>Compute the Mean Substracted Constrast Normalized coefficients of an image</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"><p class="first"><strong>image</strong> – PIL Image, Numpy array or path of image</p>
+</td>
+</tr>
+<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">MSCN coefficients</p>
+</td>
+</tr>
+<tr class="field-odd field"><th class="field-name">Raises:</th><td class="field-body"><ul class="first last simple">
+<li><code class="xref py py-exc docutils literal notranslate"><span class="pre">FileNotFoundError</span></code> – If <cite>image</cite> is set as str path and image was not found</li>
+<li><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code> – If <cite>image</cite> numpy shape are not correct</li>
+</ul>
+</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">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="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">image_values</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">mscn_coefficients</span> <span class="o">=</span> <span class="n">processing</span><span class="o">.</span><span class="n">get_mscn_coefficients</span><span class="p">(</span><span class="n">image_values</span><span class="p">)</span>
+<span class="gp">&gt;&gt;&gt; </span><span class="n">mscn_coefficients</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.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="reference internal" href="../_modules/ipfml/processing.html#rgb_to_LAB_L_bits"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#ipfml.processing.rgb_to_LAB_L_bits" title="Permalink to this definition">¶</a></dt>

+ 2 - 2
docs/build/html/ipfml/ipfml.utils.html

@@ -8,7 +8,7 @@
   
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   
-  <title>ipfml.utils &mdash; IPFML v0.3.4 documentation</title>
+  <title>ipfml.utils &mdash; IPFML v0.3.5 documentation</title>
   
 
   
@@ -58,7 +58,7 @@
             
             
               <div class="version">
-                0.3.4
+                0.3.5
               </div>
             
           

BIN
docs/build/html/objects.inv


+ 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.3.4 documentation</title>
+  <title>Python Module Index &mdash; IPFML v0.3.5 documentation</title>
   
 
   
@@ -59,7 +59,7 @@
             
             
               <div class="version">
-                0.3.4
+                0.3.5
               </div>
             
           

+ 2 - 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.3.4 documentation</title>
+  <title>Search &mdash; IPFML v0.3.5 documentation</title>
   
 
   
@@ -56,7 +56,7 @@
             
             
               <div class="version">
-                0.3.4
+                0.3.5
               </div>
             
           

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


+ 2 - 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.3.4'
+version = '0.3.5'
 # The full versiabson, including alpha/beta/rc tags
-release = 'v0.3.4'
+release = 'v0.3.5'
 
 
 # -- General configuration ---------------------------------------------------

+ 1 - 0
docs/source/ipfml/ipfml.processing.rst

@@ -15,6 +15,7 @@ ipfml.processing
       get_LAB_L_SVD_U
       get_LAB_L_SVD_V
       get_LAB_L_SVD_s
+      get_mscn_coefficients
       rgb_to_LAB_L_bits
       rgb_to_LAB_L_low_bits
       rgb_to_grey_low_bits

+ 67 - 2
ipfml/processing.py

@@ -7,12 +7,13 @@ import random
 
 import cv2
 from skimage import transform, color
-import numpy as np
+from scipy import signal
 
+import numpy as np
 import ipfml.metrics as metrics
 from ipfml import exceptions
 
-from scipy import signal
+import os
 
 
 def get_LAB_L_SVD(image):
@@ -411,3 +412,67 @@ def rotate_image(image, angle=90, pil=True):
         return Image.fromarray(rotated_image, mode)
     else:
         return rotated_image
+
+
+def get_mscn_coefficients(image):
+    """Compute the Mean Substracted Constrast Normalized coefficients of an image
+
+    Args:
+        image: PIL Image, Numpy array or path of image
+
+    Returns:
+        MSCN coefficients
+
+    Raises:
+        FileNotFoundError: If `image` is set as str path and image was not found
+        ValueError: If `image` numpy shape are not correct
+
+    Example:
+
+    >>> from PIL import Image
+    >>> import numpy as np
+    >>> from ipfml import processing
+    >>> image_values = Image.open('./images/test_img.png')
+    >>> mscn_coefficients = processing.get_mscn_coefficients(image_values)
+    >>> mscn_coefficients.shape
+    (200, 200)
+    """
+
+    if isinstance(image, str):
+        if os.path.exists(image):
+            # open image directly as grey level image
+            imdist = cv2.imread(image, 0)
+        else:
+            raise FileNotFoundError('Image not found in your system')
+
+    elif isinstance(image, np.ndarray):
+        # convert if necessary to grey level numpy array
+        if image.ndim == 2:
+            imdist = image
+        if image.ndim == 3:
+            imdist = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
+        else:
+            raise ValueError('Incorrect image shape')
+    else:
+        # if PIL Image
+        image = np.asarray(image)
+
+        if image.ndim == 2:
+            imdist = image
+        if image.ndim == 3:
+            imdist = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
+        else:
+            raise ValueError('Incorrect image shape')
+
+    imdist = imdist.astype(np.float64)
+    imdist = imdist / 255.0
+
+    # calculating MSCN coefficients
+    mu = cv2.GaussianBlur(
+        imdist, (7, 7), 7 / 6, borderType=cv2.BORDER_CONSTANT)
+    mu_sq = mu * mu
+    sigma = cv2.GaussianBlur(
+        imdist * imdist, (7, 7), 7 / 6, borderType=cv2.BORDER_CONSTANT)
+    sigma = np.sqrt(abs((sigma - mu_sq)))
+    structdis = (imdist - mu) / (sigma + 1)
+    return structdis

+ 1 - 1
setup.py

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