Browse Source

Add of documentations website from sphinx

Jérôme BUISINE 2 years ago
parent
commit
2debef1596

+ 0 - 0
.nojekyll


+ 22 - 0
docs/Makefile

@@ -0,0 +1,22 @@
+# Minimal makefile for Sphinx documentation
+#
+
+# You can set these variables from the command line.
+SPHINXOPTS    =
+SPHINXBUILD   = sphinx-build
+SOURCEDIR     = source
+BUILDDIR      = _build
+
+# Put it first so that "make" without argument is like "make help".
+help:
+	@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
+
+rst:
+	sphinx-apidoc -o ./source ../ipfml/
+
+.PHONY: help Makefile
+
+# Catch-all target: route all unknown targets to Sphinx using the new
+# "make mode" option.  $(O) is meant as a shortcut for $(SPHINXOPTS).
+%: Makefile
+	@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

+ 56 - 0
docs/source/_static/pymunk.js

@@ -0,0 +1,56 @@
+$(function (){
+
+    console.log("There!")
+
+    var createList = function(selector){
+
+        var ul = $('<ul>');
+        var selected = $(selector);
+
+        console.log(selected.length);
+        if (selected.length === 0){
+            return;
+        }
+
+        selected.clone().each(function (i,e){
+
+            var p = $(e).children('.descclassname');
+            var n = $(e).children('.descname');
+            var l = $(e).children('.headerlink');
+
+            var a = $('<a>');
+            a.attr('href',l.attr('href')).attr('title', 'Link to this definition');
+
+            a.append(p).append(n);
+
+            var entry = $('<li>').append(a);
+            ul.append(entry);
+        });
+        return ul;
+    }
+
+
+    var c = $('<div style="float:left; min-width: 300px;">');
+
+    var ul0 = c.clone().append($('.submodule-index'))
+
+    customIndex = $('.custom-index');
+    customIndex.empty();
+    customIndex.append(ul0);
+
+    var x = [];
+    x.push(['Classes','dl.class > dt']);
+    x.push(['Functions','dl.function > dt']);
+    x.push(['Variables','dl.data > dt']);
+
+    x.forEach(function (e){
+        var l = createList(e[1]);
+        if (l) {
+            var ul = c.clone()
+                .append('<p class="rubric">'+e[0]+'</p>')
+                .append(l);
+        }
+        customIndex.append(ul);
+    });
+
+});

+ 11 - 0
docs/source/_templates/localtoc.html

@@ -0,0 +1,11 @@
+<h3><a href="{{ pathto(master_doc) }}">{{ _('Table Of Contents') }}</a></h3>
+{%- if display_toc %}
+
+  {{ toc }}
+{%- endif %}
+
+HERE!!!!
+
+<div class="custom-index container">
+    <script type="text/javascript" src={{ pathto(master_doc)[:-10] + '_static/pymunk.js' }}></script>
+</div>

+ 196 - 0
docs/source/conf.py

@@ -0,0 +1,196 @@
+# -*- coding: utf-8 -*-
+#
+# Configuration file for the Sphinx documentation builder.
+#
+# This file does only contain a selection of the most common options. For a
+# full list see the documentation:
+# http://www.sphinx-doc.org/en/master/config
+
+# -- Path setup --------------------------------------------------------------
+
+# If extensions (or modules to document with autodoc) are in another directory,
+# add these directories to sys.path here. If the directory is relative to the
+# documentation root, use os.path.abspath to make it absolute, like shown here.
+#
+import os
+import sys
+sys.path.insert(0, os.path.abspath('../../ipfml'))
+
+
+# -- Project information -----------------------------------------------------
+
+project = 'IPFML'
+copyright = '2019, Jérôme BUISINE'
+author = 'Jérôme BUISINE'
+
+# The short X.Y version
+version = '0.1.6'
+# The full version, including alpha/beta/rc tags
+release = 'v0.1.6'
+
+
+# -- General configuration ---------------------------------------------------
+
+# If your documentation needs a minimal Sphinx version, state it here.
+#
+# needs_sphinx = '1.0'
+
+# Add any Sphinx extension module names here, as strings. They can be
+# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
+# ones.
+extensions = [
+    'sphinx.ext.autodoc',
+    'sphinx.ext.doctest',
+    'sphinx.ext.coverage',
+    'sphinx.ext.napoleon',
+    'sphinx.ext.autosummary'
+]
+
+# Add any paths that contain templates here, relative to this directory.
+templates_path = ['_templates']
+
+# The suffix(es) of source filenames.
+# You can specify multiple suffix as a list of string:
+#
+# source_suffix = ['.rst', '.md']
+source_suffix = '.rst'
+
+# The master toctree document.
+master_doc = 'index'
+
+# The language for content autogenerated by Sphinx. Refer to documentation
+# for a list of supported languages.
+#
+# This is also used if you do content translation via gettext catalogs.
+# Usually you set "language" from the command line for these cases.
+language = None
+
+# List of patterns, relative to source directory, that match files and
+# directories to ignore when looking for source files.
+# This pattern also affects html_static_path and html_extra_path.
+exclude_patterns = []
+
+# The name of the Pygments (syntax highlighting) style to use.
+pygments_style = None
+
+
+# -- Options for HTML output -------------------------------------------------
+
+# The theme to use for HTML and HTML Help pages.  See the documentation for
+# a list of builtin themes.
+#
+html_theme = 'sphinx_rtd_theme'
+
+# Theme options are theme-specific and customize the look and feel of a theme
+# further.  For a list of options available for each theme, see the
+# documentation.
+#
+# html_theme_options = {}
+
+html_theme_options = {
+    'canonical_url': '',
+    #'analytics_id': 'UA-XXXXXXX-1',
+    'logo_only': False,
+    'display_version': True,
+    'prev_next_buttons_location': 'bottom',
+    'style_external_links': False,
+    #'vcs_pageview_mode': '',
+    # Toc options
+    'collapse_navigation': True,
+    'sticky_navigation': True,
+    'navigation_depth': 4,
+    'includehidden': True,
+    'titles_only': False
+}
+
+# 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".
+html_static_path = ['_static']
+
+# Custom sidebar templates, must be a dictionary that maps document names
+# to template names.
+#
+# The default sidebars (for documents that don't match any pattern) are
+# defined by theme itself.  Builtin themes are using these templates by
+# default: ``['localtoc.html', 'relations.html', 'sourcelink.html',
+# 'searchbox.html']``.
+#
+# html_sidebars = {}
+
+# -- Options for HTMLHelp output ---------------------------------------------
+
+# Output file base name for HTML help builder.
+htmlhelp_basename = 'IPFMLdoc'
+
+
+# -- Options for LaTeX output ------------------------------------------------
+
+latex_elements = {
+    # The paper size ('letterpaper' or 'a4paper').
+    #
+    # 'papersize': 'letterpaper',
+
+    # The font size ('10pt', '11pt' or '12pt').
+    #
+    # 'pointsize': '10pt',
+
+    # Additional stuff for the LaTeX preamble.
+    #
+    # 'preamble': '',
+
+    # Latex figure (float) alignment
+    #
+    # 'figure_align': 'htbp',
+}
+
+# Grouping the document tree into LaTeX files. List of tuples
+# (source start file, target name, title,
+#  author, documentclass [howto, manual, or own class]).
+latex_documents = [
+    (master_doc, 'IPFML.tex', 'IPFML Documentation',
+     'Jérôme BUISINE', 'manual'),
+]
+
+
+# -- Options for manual page output ------------------------------------------
+
+# One entry per manual page. List of tuples
+# (source start file, name, description, authors, manual section).
+man_pages = [
+    (master_doc, 'ipfml', 'IPFML Documentation',
+     [author], 1)
+]
+
+
+# -- Options for Texinfo output ----------------------------------------------
+
+# Grouping the document tree into Texinfo files. List of tuples
+# (source start file, target name, title, author,
+#  dir menu entry, description, category)
+texinfo_documents = [
+    (master_doc, 'IPFML', 'IPFML Documentation',
+     author, 'IPFML', 'One line description of project.',
+     'Miscellaneous'),
+]
+
+
+# -- Options for Epub output -------------------------------------------------
+
+# Bibliographic Dublin Core info.
+epub_title = project
+
+# The unique identifier of the text. This can be a ISBN number
+# or the project homepage.
+#
+# epub_identifier = ''
+
+# A unique identification for the text.
+#
+# epub_uid = ''
+
+# A list of files that should not be packed into the epub file.
+epub_exclude_files = ['search.html']
+
+
+# -- Extension configuration -------------------------------------------------

+ 23 - 0
docs/source/description.rst

@@ -0,0 +1,23 @@
+Description
+============
+
+
+Installation
+------------
+
+Just install package using pip 
+
+   >>> pip install ipfml
+
+
+How to use ?
+------------
+
+To use, simply do :
+
+    >>> from PIL import Image
+    >>> from ipfml import image_processing
+    >>> img = Image.open('path/to/image.png')
+    >>> s = image_processing.get_LAB_L_SVD_s(img)
+
+

+ 29 - 0
docs/source/index.rst

@@ -0,0 +1,29 @@
+.. IPFML documentation master file, created by
+   sphinx-quickstart on Fri Jan  4 12:10:59 2019.
+   You can adapt this file completely to your liking, but it should at least
+   contain the root `toctree` directive.
+
+IPFML's documentation!
+=================================
+
+.. toctree::
+   :maxdepth: 2
+      
+   description
+   ipfml
+   ipfml.filters
+
+What's IPFML ?
+=================
+
+Image Processing For Machine Learning python package.
+
+This is a package developed during a thesis project.
+
+
+Indices and tables
+==================
+
+* :ref:`genindex`
+* :ref:`modindex`
+* :ref:`search`

+ 10 - 0
docs/source/ipfml.filters.rst

@@ -0,0 +1,10 @@
+ipfml.filters
+=====================
+
+ipfml.filters.noise
+--------------------------
+
+.. automodule:: ipfml.filters.noise
+    :members:
+    :show-inheritance:
+    

+ 16 - 0
docs/source/ipfml.rst

@@ -0,0 +1,16 @@
+ipfml
+=============
+
+ipfml.metrics
+--------------------
+
+.. automodule:: ipfml.metrics
+    :members:
+    :show-inheritance:
+
+ipfml.processing
+-----------------------
+
+.. automodule:: ipfml.processing
+    :members:
+    :show-inheritance:

+ 140 - 74
ipfml/filters/noise.py

@@ -1,18 +1,29 @@
 import numpy as np
 from ipfml import processing
 
-def _global_noise_filter(image, n, generator, updator, identical=False, distribution_interval=(-0.5, 0.5), k=0.2):
-    """
-    @brief White noise filter to apply on image
-    @param image - image used as input (2D or 3D image representation)
-    @param n - used to set importance of noise [1, 999]
-    @param generator - random function we want to use to generate random numpy array
-    @param updator - lambda function used to update pixel value
-    @param distribution_interval - set the distribution interval of uniform distribution
-    @param k - variable that specifies the amount of noise to be taken into account in the output image
-    @return Image with specified noise applied
 
-    Usage :
+def _global_noise_filter(image,
+                         n,
+                         generator,
+                         updator,
+                         identical=False,
+                         distribution_interval=(-0.5, 0.5),
+                         k=0.2):
+    """White noise filter to apply on image
+
+    Args:
+        image: image used as input (2D or 3D image representation)
+        n: used to set importance of noise [1, 999]
+        generator: lambda function used to generate random numpy array with specific distribution
+        updator: lambda function used to update pixel value
+        identical: keep or not identical noise distribution for each canal if RGB Image (default False)
+        distribution_interval: tuple which set the distribution interval of uniform distribution (default (-0.5, 0.5))
+        k: variable that specifies the amount of noise to be taken into account in the output image (default 0.2)
+
+    Returns:
+        2D Numpy array with specified noise applied
+
+    Usage:
 
     >>> from ipfml.filters.noise import _global_noise_filter as gf
     >>> import numpy as np
@@ -55,7 +66,10 @@ def _global_noise_filter(image, n, generator, updator, identical=False, distribu
 
         # compute new pixel value
         # n * k * white_noise_filter[i]
-        noisy_image = np.asarray([updator(image_array_flatten[i], n, k, noise_filter[i]) for i in range(0, nb_pixels)])
+        noisy_image = np.asarray([
+            updator(image_array_flatten[i], n, k, noise_filter[i])
+            for i in range(0, nb_pixels)
+        ])
 
         # reshape and normalize new value
         noisy_image = noisy_image.reshape((width, height))
@@ -78,16 +92,24 @@ def _global_noise_filter(image, n, generator, updator, identical=False, distribu
     return output_array
 
 
-def white_noise(image, n, identical=False, distribution_interval=(-0.5, 0.5), k=0.2):
-    """
-    @brief White noise filter to apply on image
-    @param image - image used as input (2D or 3D image representation)
-    @param n - used to set importance of noise [1, 999]
-    @param distribution_interval - set the distribution interval of normal law distribution
-    @param k - variable that specifies the amount of noise to be taken into account in the output image
-    @return Image with white noise applied
+def white_noise(image,
+                n,
+                identical=False,
+                distribution_interval=(-0.5, 0.5),
+                k=0.2):
+    """White noise filter to apply on image
+
+    Args:
+        image: image used as input (2D or 3D image representation)
+        n: used to set importance of noise [1, 999]
+        identical: keep or not identical noise distribution for each canal if RGB Image (default False)
+        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)
 
-    Usage :
+    Returns:
+        2D Numpy array with white noise applied
+
+    Usage:
 
     >>> from ipfml.filters.noise import white_noise
     >>> import numpy as np
@@ -102,19 +124,28 @@ def white_noise(image, n, identical=False, distribution_interval=(-0.5, 0.5), k=
 
     updator = lambda x, n, k, noise: x + n * k * noise
 
-    return _global_noise_filter(image, n, generator, updator, identical, distribution_interval, k)
+    return _global_noise_filter(image, n, generator, updator, identical,
+                                distribution_interval, k)
 
 
-def gaussian_noise(image, n, identical=False, distribution_interval=(0, 1), k=0.1):
-    """
-    @brief Gaussian noise filter to apply on image
-    @param image - image used as input (2D or 3D image representation)
-    @param n - used to set importance of noise [1, 999]
-    @param distribution_interval - set the distribution interval of normal law distribution
-    @param k - variable that specifies the amount of noise to be taken into account in the output image
-    @return Image with gaussian noise applied
+def gaussian_noise(image,
+                   n,
+                   identical=False,
+                   distribution_interval=(0, 1),
+                   k=0.1):
+    """Gaussian noise filter to apply on image
+
+    Args:
+        image: image used as input (2D or 3D image representation)
+        n: used to set importance of noise [1, 999]
+        identical: keep or not identical noise distribution for each canal if RGB Image (default False)
+        distribution_interval: set the distribution interval of normal law distribution (default (0, 1))
+        k: variable that specifies the amount of noise to be taken into account in the output image (default 0.1)
 
-    Usage :
+    Returns:
+        2D Numpy array with gaussian noise applied
+
+    Usage:
 
     >>> from ipfml.filters.noise import gaussian_noise
     >>> import numpy as np
@@ -129,19 +160,28 @@ def gaussian_noise(image, n, identical=False, distribution_interval=(0, 1), k=0.
 
     updator = lambda x, n, k, noise: x + n * k * noise
 
-    return _global_noise_filter(image, n, generator, updator, identical, distribution_interval, k)
+    return _global_noise_filter(image, n, generator, updator, identical,
+                                distribution_interval, k)
 
 
-def laplace_noise(image, n, identical=False, distribution_interval=(0, 1), k=0.1):
-    """
-    @brief Laplace noise filter to apply on image
-    @param image - image used as input (2D or 3D image representation)
-    @param n - used to set importance of noise [1, 999]
-    @param distribution_interval - set the distribution interval of normal law distribution
-    @param k - variable that specifies the amount of noise to be taken into account in the output image
-    @return Image with Laplace noise applied
+def laplace_noise(image,
+                  n,
+                  identical=False,
+                  distribution_interval=(0, 1),
+                  k=0.1):
+    """Laplace noise filter to apply on image
+
+    Args:
+        image: image used as input (2D or 3D image representation)
+        n: used to set importance of noise [1, 999]
+        identical: keep or not identical noise distribution for each canal if RGB Image (default False)
+        distribution_interval: set the distribution interval of normal law distribution (default (0, 1))
+        k: variable that specifies the amount of noise to be taken into account in the output image (default 0.1)
 
-    Usage :
+    Returns:
+        2D Numpay array with Laplace noise applied
+
+    Usage:
 
     >>> from ipfml.filters.noise import laplace_noise
     >>> import numpy as np
@@ -156,19 +196,28 @@ def laplace_noise(image, n, identical=False, distribution_interval=(0, 1), k=0.1
 
     updator = lambda x, n, k, noise: x + n * k * noise
 
-    return _global_noise_filter(image, n, generator, updator, identical, distribution_interval, k)
+    return _global_noise_filter(image, n, generator, updator, identical,
+                                distribution_interval, k)
 
 
-def cauchy_noise(image, n, identical=False, distribution_interval=(0, 1), k=0.0002):
-    """
-    @brief Cauchy noise filter to apply on image
-    @param image - image used as input (2D or 3D image representation)
-    @param n - used to set importance of noise [1, 999]
-    @param distribution_interval - set the distribution interval of normal law distribution
-    @param k - variable that specifies the amount of noise to be taken into account in the output image
-    @return Image with Cauchy noise applied
+def cauchy_noise(image,
+                 n,
+                 identical=False,
+                 distribution_interval=(0, 1),
+                 k=0.0002):
+    """Cauchy noise filter to apply on image
 
-    Usage :
+    Args:
+        image: image used as input (2D or 3D image representation)
+        n: used to set importance of noise [1, 999]
+        identical: keep or not identical noise distribution for each canal if RGB Image (default False)
+        distribution_interval: set the distribution interval of normal law distribution (default (0, 1))
+        k: variable that specifies the amount of noise to be taken into account in the output image (default 0.0002)
+
+    Returns:
+        2D Numpy array with Cauchy noise applied
+
+    Usage:
 
     >>> from ipfml.filters.noise import cauchy_noise
     >>> import numpy as np
@@ -183,19 +232,28 @@ def cauchy_noise(image, n, identical=False, distribution_interval=(0, 1), k=0.00
 
     updator = lambda x, n, k, noise: x + n * k * noise
 
-    return _global_noise_filter(image, n, generator, updator, identical, distribution_interval, k)
+    return _global_noise_filter(image, n, generator, updator, identical,
+                                distribution_interval, k)
 
 
-def log_normal_noise(image, n, identical=False, distribution_interval=(0, 1), k=0.05):
-    """
-    @brief Log-normal noise filter to apply on image
-    @param image - image used as input (2D or 3D image representation)
-    @param n - used to set importance of noise [1, 999]
-    @param distribution_interval - set the distribution interval of normal law distribution
-    @param k - variable that specifies the amount of noise to be taken into account in the output image
-    @return Image with Log-normal noise applied
+def log_normal_noise(image,
+                     n,
+                     identical=False,
+                     distribution_interval=(0, 1),
+                     k=0.05):
+    """Log-normal noise filter to apply on image
+
+    Args:
+        image: image used as input (2D or 3D image representation)
+        n: used to set importance of noise [1, 999]
+        identical: keep or not identical noise distribution for each canal if RGB Image (default False)
+        distribution_interval: set the distribution interval of normal law distribution (default (0, 1))
+        k: variable that specifies the amount of noise to be taken into account in the output image (default 0.05)
+
+    Returns:
+        2D Numpy array with Log-normal noise applied
 
-    Usage :
+    Usage:
 
     >>> from ipfml.filters.noise import log_normal_noise
     >>> import numpy as np
@@ -210,19 +268,28 @@ def log_normal_noise(image, n, identical=False, distribution_interval=(0, 1), k=
 
     updator = lambda x, n, k, noise: x + n * k * noise
 
-    return _global_noise_filter(image, n, generator, updator, identical, distribution_interval, k)
+    return _global_noise_filter(image, n, generator, updator, identical,
+                                distribution_interval, k)
 
 
-def mut_white_noise(image, n, identical=False, distribution_interval=(-0.5, 0.5), k=0.2):
-    """
-    @brief Multiplied White noise filter to apply on image
-    @param image - image used as input (2D or 3D image representation)
-    @param n - used to set importance of noise [1, 999]
-    @param distribution_interval - set the distribution interval of normal law distribution
-    @param k - variable that specifies the amount of noise to be taken into account in the output image
-    @return Image with multiplied white noise applied
+def mut_white_noise(image,
+                    n,
+                    identical=False,
+                    distribution_interval=(-0.5, 0.5),
+                    k=0.2):
+    """Multiplied White noise filter to apply on image
+
+    Args:
+        image: image used as input (2D or 3D image representation)
+        n: used to set importance of noise [1, 999]
+        identical: keep or not identical noise distribution for each canal if RGB Image (default False)
+        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)
+
+    Returns:
+        2D Numpy array with multiplied white noise applied
 
-    Usage :
+    Usage:
 
     >>> from ipfml.filters.noise import mut_white_noise
     >>> import numpy as np
@@ -237,6 +304,5 @@ def mut_white_noise(image, n, identical=False, distribution_interval=(-0.5, 0.5)
 
     updator = lambda x, n, k, noise: x * n * k * noise
 
-    return _global_noise_filter(image, n, generator, updator, identical, distribution_interval, k)
-
-
+    return _global_noise_filter(image, n, generator, updator, identical,
+                                distribution_interval, k)

+ 151 - 83
ipfml/metrics.py

@@ -9,13 +9,17 @@ from skimage import io, color
 
 import cv2
 
+
 def get_SVD(image):
-    """
-    @brief Transforms Image into SVD
-    @param image to convert
-    @return U, s, V obtained from SVD compression
+    """Transforms Image using SVD compression
 
-    Usage :
+    Args:
+        image: image to convert into SVD compression
+
+    Return:
+        U, s, V obtained from SVD compression
+
+    Usage:
 
     >>> from PIL import Image
     >>> from ipfml import metrics
@@ -30,13 +34,17 @@ def get_SVD(image):
     """
     return svd(image, full_matrices=False)
 
+
 def get_SVD_s(image):
-    """
-    @brief Transforms Image into SVD and returns only 's' part
-    @param image - image to convert
-    @return s obtained from SVD compression
+    """Transforms Image into SVD and returns only 's' part
 
-    Usage :
+    Args:
+        image: image to convert
+
+    Returns:
+        vector of singular values obtained from SVD compression
+
+    Usage:
 
     >>> from PIL import Image
     >>> from ipfml import metrics
@@ -48,13 +56,17 @@ def get_SVD_s(image):
     U, s, V = svd(image, full_matrices=False)
     return s
 
+
 def get_SVD_U(image):
-    """
-    @brief Transforms Image into SVD and returns only 'U' part
-    @param image - image to convert
-    @return U matrix from SVD compression
+    """Transforms Image into SVD and returns only 'U' part
 
-    Usage :
+    Args:
+        image: image to convert
+
+    Returns:
+        U matrix from SVD compression
+
+    Usage:
 
     >>> from PIL import Image
     >>> from ipfml import metrics
@@ -67,11 +79,15 @@ def get_SVD_U(image):
     U, s, V = svd(image, full_matrices=False)
     return U
 
+
 def get_SVD_V(image):
-    """
-    @brief Transforms Image into SVD and returns only 'V' part
-    @param image - image to convert
-    @return V matrix obtained from SVD compression
+    """Transforms Image into SVD and returns only 'V' part
+
+    Args:
+        image: image to convert
+
+    Returns:
+        V matrix obtained from SVD compression
 
     Usage :
 
@@ -86,13 +102,17 @@ def get_SVD_V(image):
     U, s, V = svd(image, full_matrices=False)
     return V
 
+
 def get_LAB(image):
-    """
-    @brief Transforms RGB  Image into Lab
-    @param image - image to convert
-    @return Lab information
+    """Transforms RGB  Image into Lab
 
-    Usage :
+    Args:
+        image: image to convert
+
+    Returns:
+        Lab information
+
+    Usage:
 
     >>> from PIL import Image
     >>> from ipfml import metrics
@@ -104,11 +124,15 @@ def get_LAB(image):
 
     return color.rgb2lab(image)
 
+
 def get_LAB_L(image):
-    """
-    @brief Transforms RGB Image into Lab and returns L
-    @param image - image to convert
-    @return L chanel from Lab information
+    """Transforms RGB Image into Lab and returns L
+
+    Args:
+        image: image to convert
+
+    Returns:
+        The L chanel from Lab information
 
     >>> from PIL import Image
     >>> from ipfml import metrics
@@ -121,13 +145,17 @@ def get_LAB_L(image):
     lab = get_LAB(image)
     return lab[:, :, 0]
 
+
 def get_LAB_a(image):
-    """
-    @brief Transforms RGB Image into LAB and returns a
-    @param image - image to convert
-    @return a chanel from Lab information
+    """Transforms RGB Image into LAB and returns a
 
-    Usage :
+    Args:
+        image: image to convert
+
+    Returns:
+        The a chanel from Lab information
+
+    Usage:
 
     >>> from PIL import Image
     >>> from ipfml import metrics
@@ -140,11 +168,15 @@ def get_LAB_a(image):
     lab = get_LAB(image)
     return lab[:, :, 1]
 
+
 def get_LAB_b(image):
-    """
-    @brief Transforms RGB Image into LAB and returns b
-    @param image - image to convert
-    @return b chanel from Lab information
+    """Transforms RGB Image into LAB and returns b
+
+    Args:
+        image: image to convert
+
+    Returns:
+        The b chanel from Lab information
 
     Usage :
 
@@ -159,13 +191,17 @@ def get_LAB_b(image):
     lab = get_LAB(image)
     return lab[:, :, 2]
 
+
 def get_XYZ(image):
-    """
-    @brief Transforms RGB Image into XYZ
-    @param image - image to convert
-    @return XYZ information obtained from transformation
+    """Transforms RGB Image into XYZ
 
-    Usage :
+    Args:
+        image: image to convert
+
+    Returns:
+        XYZ information obtained from transformation
+
+    Usage:
 
     >>> from PIL import Image
     >>> from ipfml import metrics
@@ -176,13 +212,17 @@ def get_XYZ(image):
 
     return color.rgb2xyz(image)
 
+
 def get_XYZ_X(image):
-    """
-    @brief Transforms RGB Image into XYZ and returns X
-    @param image - image to convert
-    @return X chanel from XYZ information
+    """Transforms RGB Image into XYZ and returns X
 
-    Usage :
+    Args:
+        image: image to convert
+
+    Returns:
+        The X chanel from XYZ information
+
+    Usage:
 
     >>> from PIL import Image
     >>> from ipfml import metrics
@@ -195,13 +235,17 @@ def get_XYZ_X(image):
     xyz = color.rgb2xyz(image)
     return xyz[:, :, 0]
 
+
 def get_XYZ_Y(image):
-    """
-    @brief Transforms RGB Image into XYZ and returns Y
-    @param image - image to convert
-    @return Y chanel from XYZ information
+    """Transforms RGB Image into XYZ and returns Y
 
-    Usage :
+    Args:
+        image: image to convert
+
+    Returns:
+        The Y chanel from XYZ information
+
+    Usage:
 
     >>> from PIL import Image
     >>> from ipfml import metrics
@@ -214,13 +258,17 @@ def get_XYZ_Y(image):
     xyz = color.rgb2xyz(image)
     return xyz[:, :, 1]
 
+
 def get_XYZ_Z(image):
-    """
-    @brief Transforms RGB Image into XYZ and returns Z
-    @param image - image to convert
-    @return Z chanel from XYZ information
+    """Transforms RGB Image into XYZ and returns Z
 
-    Usage :
+    Args:
+        image: image to convert
+
+    Returns:
+        The Z chanel from XYZ information
+
+    Usage:
 
     >>> from PIL import Image
     >>> from ipfml import metrics
@@ -233,14 +281,18 @@ def get_XYZ_Z(image):
     xyz = color.rgb2xyz(image)
     return xyz[:, :, 2]
 
+
 def get_low_bits_img(image, nb_bits=4):
-    """
-    @brief Returns Image or Numpy array with data information reduced using only low bits
-    @param image, image to convert
-    @param nb_bits, optional parameter which indicates the number of bits to keep
-    @return Numpy array with reduced values
+    """Returns Image or Numpy array with data information reduced using only low bits
 
-    Usage :
+    Args:
+        image: image to convert
+        nb_bits: optional parameter which indicates the number of bits to keep
+
+    Returns:
+        Numpy array with reduced values
+
+    Usage:
 
     >>> from PIL import Image
     >>> from ipfml import metrics
@@ -251,10 +303,14 @@ def get_low_bits_img(image, nb_bits=4):
     """
 
     if nb_bits <= 0:
-        raise ValueError("unexpected value of number of bits to keep. @nb_bits needs to be positive and greater than 0.")
+        raise ValueError(
+            "unexpected value of number of bits to keep. @nb_bits needs to be positive and greater than 0."
+        )
 
     if nb_bits > 8:
-        raise ValueError("Unexpected value of number of bits to keep. @nb_bits needs to be in interval [1, 8].")
+        raise ValueError(
+            "Unexpected value of number of bits to keep. @nb_bits needs to be in interval [1, 8]."
+        )
 
     img_arr = np.array(image)
 
@@ -262,14 +318,18 @@ def get_low_bits_img(image, nb_bits=4):
 
     return img_arr & bits_values
 
+
 def get_bits_img(image, interval):
-    """
-    @brief Returns only bits specified into the interval
-    @param image to convert using this interval of bits value to keep
-    @param interval (begin, end) of bits values
-    @return Numpy array with reduced values
+    """Returns only bits specified into the interval
 
-    Usage :
+    Args:
+        image: image to convert using this interval of bits value to keep
+        interval: (begin, end) of bits values
+
+    Returns:
+        Numpy array with reduced values
+
+    Usage:
 
     >>> from PIL import Image
     >>> from ipfml import metrics
@@ -283,10 +343,14 @@ def get_bits_img(image, interval):
     begin, end = interval
 
     if begin < 1:
-        raise ValueError("Unexpected value of interval. Minimum value of interval needs to be >= 1.")
+        raise ValueError(
+            "Unexpected value of interval. Interval min value needs to be >= 1."
+        )
 
     if end > 8:
-        raise ValueError("Unexpected value of interval. Maximum value of interval needs to be <= 8.")
+        raise ValueError(
+            "Unexpected value of interval. Interval min value needs to be <= 8."
+        )
 
     if begin >= end:
         raise ValueError("Unexpected interval values order.")
@@ -297,12 +361,15 @@ def get_bits_img(image, interval):
 
 
 def gray_to_mscn(image):
-    """
-    @brief Convert Grayscale Image into Mean Subtracted Contrast Normalized (MSCN)
-    @param image - grayscale image
-    @returns MSCN matrix obtained from transformation
+    """Convert Grayscale Image into Mean Subtracted Contrast Normalized (MSCN)
 
-    Usage :
+    Args:
+        image: grayscale image
+
+    Returns:
+        MSCN matrix obtained from transformation
+
+    Usage:
 
     >>> from PIL import Image
     >>> from ipfml import processing
@@ -312,12 +379,13 @@ def gray_to_mscn(image):
     (200, 200)
     """
 
-    s = 7/6
-    blurred = cv2.GaussianBlur(image, (7, 7), s) # apply gaussian blur to the image
+    s = 7 / 6
+    blurred = cv2.GaussianBlur(image, (7, 7),
+                               s)  # apply gaussian blur to the image
     blurred_sq = blurred * blurred
     sigma = cv2.GaussianBlur(image * image, (7, 7), s)
-    sigma = abs(sigma - blurred_sq) ** 0.5
-    sigma = sigma + 1.0/255 # avoid DivideByZero Exception
-    mscn = (image - blurred)/sigma # MSCN(i, j) image
+    sigma = abs(sigma - blurred_sq)**0.5
+    sigma = sigma + 1.0 / 255  # avoid DivideByZero Exception
+    mscn = (image - blurred) / sigma  # MSCN(i, j) image
 
     return mscn

+ 119 - 72
ipfml/processing.py

@@ -9,13 +9,17 @@ import cv2
 
 from scipy import signal
 
+
 def get_LAB_L_SVD(image):
-    """
-    @brief Returns Singular values from LAB L Image information
-    @param image - PIL Image or Numpy array
-    @return U, s, V information obtained from SVD compression using Lab
+    """Returns Singular values from LAB L Image information
+
+    Args:
+        image: PIL Image or Numpy array
 
-    Usage :
+    Returns:
+        U, s, V information obtained from SVD compression using Lab
+
+    Usage:
 
     >>> from PIL import Image
     >>> from ipfml import processing
@@ -31,13 +35,17 @@ def get_LAB_L_SVD(image):
     L = metrics.get_LAB_L(image)
     return metrics.get_SVD(L)
 
+
 def get_LAB_L_SVD_s(image):
-    """
-    @brief Returns s (Singular values) SVD from L of LAB Image information
-    @param image - PIL Image or numpy array
-    @return vector of singular values
+    """Returns s (Singular values) SVD from L of LAB Image information
+
+    Args:
+        image: PIL Image or Numpy array
+
+    Returns:
+        vector of singular values
 
-    Usage :
+    Usage:
 
     >>> from PIL import Image
     >>> from ipfml import processing
@@ -51,12 +59,15 @@ def get_LAB_L_SVD_s(image):
 
 
 def get_LAB_L_SVD_U(image):
-    """
-    @brief Returns U SVD from L of LAB Image information
-    @param image - PIL Image
-    @return U matrix of SVD compression
+    """Returns U SVD from L of LAB Image information
+
+    Args:
+        image: PIL Image or Numpy array
 
-    Usage :
+    Returns:
+        U matrix of SVD compression
+
+    Usage:
 
     >>> from PIL import Image
     >>> from ipfml import processing
@@ -68,13 +79,17 @@ def get_LAB_L_SVD_U(image):
     L = metrics.get_LAB_L(image)
     return metrics.get_SVD_U(L)
 
+
 def get_LAB_L_SVD_V(image):
-    """
-    @brief Returns V SVD from L of LAB Image information
-    @param image - PIL Image or numpy array
-    @return V matrix of SVD compression
+    """Returns V SVD from L of LAB Image information
+
+    Args:
+        image: PIL Image or Numpy array
+
+    Returns:
+        V matrix of SVD compression
 
-    Usage :
+    Usage:
 
     >>> from PIL import Image
     >>> from ipfml import processing
@@ -89,16 +104,19 @@ def get_LAB_L_SVD_V(image):
 
 
 def divide_in_blocks(image, block_size, pil=True):
-    '''
-    @brief Divide image into equal size blocks
-    @param image - PIL Image or numpy array
-    @param block - tuple (width, height) representing the size of each dimension of the block
-    @param pil - kind block type (PIL by default or Numpy array)
-    @return list containing all 2D numpy blocks (in RGB or not)
+    '''Divide image into equal size blocks
+
+    Args:
+        image: PIL Image or Numpy array
+        block: tuple (width, height) representing the size of each dimension of the block
+        pil: block type returned (default True)
+
+    Returns:
+        list containing all 2D Numpy blocks (in RGB or not)
 
-    Usage :
+    Usage:
 
-    >>> import numpy as np
+    >>> import Numpy as np
     >>> from PIL import Image
     >>> from ipfml import processing
     >>> from ipfml import metrics
@@ -122,7 +140,7 @@ def divide_in_blocks(image, block_size, pil=True):
     blocks = []
     mode = 'RGB'
 
-    # convert in numpy array
+    # convert in Numpy array
     image_array = np.array(image)
 
     # check dimension of input image
@@ -135,10 +153,10 @@ def divide_in_blocks(image, block_size, pil=True):
     # check size compatibility
     width, height = block_size
 
-    if(image_width % width != 0):
+    if (image_width % width != 0):
         raise "Width size issue, block size not compatible"
 
-    if(image_height % height != 0):
+    if (image_height % height != 0):
         raise "Height size issue, block size not compatible"
 
     nb_block_width = image_width / width
@@ -153,10 +171,12 @@ def divide_in_blocks(image, block_size, pil=True):
             begin_y = j * height
 
             # getting sub block information
-            current_block = image_array[begin_x:(begin_x + width), begin_y:(begin_y + height)]
+            current_block = image_array[begin_x:(begin_x + width), begin_y:(
+                begin_y + height)]
 
             if pil:
-                blocks.append(Image.fromarray(current_block.astype('uint8'), mode))
+                blocks.append(
+                    Image.fromarray(current_block.astype('uint8'), mode))
             else:
                 blocks.append(current_block)
 
@@ -164,15 +184,18 @@ def divide_in_blocks(image, block_size, pil=True):
 
 
 def normalize_arr(arr):
-    '''
-    @brief Normalize data of 1D array shape
-    @param arr - array data of 1D shape
-    @return Normalized 1D array
+    '''Normalize data of 1D array shape
+
+    Args:
+        arr: array data of 1D shape
 
-    Usage :
+    Returns:
+        Normalized 1D array
+
+    Usage:
 
     >>> from ipfml import processing
-    >>> import numpy as np
+    >>> import Numpy as np
     >>> arr = np.arange(11)
     >>> arr_normalized = processing.normalize_arr(arr)
     >>> arr_normalized[1]
@@ -184,20 +207,24 @@ def normalize_arr(arr):
     min_value = min(arr)
 
     for v in arr:
-         output_arr.append((v - min_value) / (max_value - min_value))
+        output_arr.append((v - min_value) / (max_value - min_value))
 
     return output_arr
 
 
 def normalize_arr_with_range(arr, min, max):
-    '''
-    @brief Normalize data of 1D array shape
-    @param arr - array data of 1D shape
+    '''Normalize data of 1D array shape
+
+    Args:
+        arr: array data of 1D shape
 
-    Usage :
+    Returns:
+        Normalized 1D Numpy array
+
+    Usage:
 
     >>> from ipfml import processing
-    >>> import numpy as np
+    >>> import Numpy as np
     >>> arr = np.arange(11)
     >>> arr_normalized = processing.normalize_arr_with_range(arr, 0, 20)
     >>> arr_normalized[1]
@@ -213,12 +240,15 @@ def normalize_arr_with_range(arr, min, max):
 
 
 def normalize_2D_arr(arr):
-    """
-    @brief Return array normalize from its min and max values
-    @param arr - 2D numpy array
-    @return normalized 2D array
+    """Return array normalize from its min and max values
 
-    Usage :
+    Args:
+        arr: 2D Numpy array
+
+    Returns:
+        Normalized 2D Numpy array
+
+    Usage:
 
     >>> from PIL import Image
     >>> from ipfml import processing
@@ -239,17 +269,22 @@ def normalize_2D_arr(arr):
 
     for row_index in range(0, height):
         values = arr[row_index, :]
-        output_array.append(normalize_arr_with_range(values, min_value, max_value))
+        output_array.append(
+            normalize_arr_with_range(values, min_value, max_value))
 
     return np.asarray(output_array)
 
 
 def rgb_to_mscn(image):
-    """
-    @brief Convert RGB Image into Mean Subtracted Contrast Normalized (MSCN)
-    @param 3D RGB image numpy array or PIL RGB image
+    """Convert RGB Image into Mean Subtracted Contrast Normalized (MSCN)
+
+    Args:
+        image: 3D RGB image Numpy array or PIL RGB image
+
+    Returns:
+        2D Numpy array with MSCN information
 
-    Usage :
+    Usage:
 
     >>> from PIL import Image
     >>> from ipfml import processing
@@ -263,18 +298,22 @@ def rgb_to_mscn(image):
     img_arr = np.array(image)
 
     # convert rgb image to gray
-    im = np.array(color.rgb2gray(img_arr)*255, 'uint8')
+    im = np.array(color.rgb2gray(img_arr) * 255, 'uint8')
 
     return metrics.gray_to_mscn(im)
 
 
 def rgb_to_grey_low_bits(image, nb_bits=4):
-    """
-    @brief Convert RGB Image into grey image using only 4 low bits values
-    @param 3D RGB image numpy array or PIL RGB image
-    @param nb_bits, optional parameter which indicates the number of bits to keep
+    """Convert RGB Image into grey image using only 4 low bits values
+
+    Args:
+        image: 3D RGB image Numpy array or PIL RGB image
+        nb_bits: optional parameter which indicates the number of bits to keep (default 4)
+
+    Returns:
+        2D Numpy array with low bits information kept
 
-    Usage :
+    Usage:
 
     >>> from PIL import Image
     >>> from ipfml import processing
@@ -285,18 +324,22 @@ def rgb_to_grey_low_bits(image, nb_bits=4):
     """
 
     img_arr = np.array(image)
-    grey_block = np.array(color.rgb2gray(img_arr)*255, 'uint8')
+    grey_block = np.array(color.rgb2gray(img_arr) * 255, 'uint8')
 
     return metrics.get_low_bits_img(grey_block, nb_bits)
 
 
 def rgb_to_LAB_L_low_bits(image, nb_bits=4):
-    """
-    @brief Convert RGB Image into Lab L channel image using only 4 low bits values
-    @param 3D RGB image numpy array or PIL RGB image
-    @param nb_bits, optional parameter which indicates the number of bits to keep
+    """Convert RGB Image into Lab L channel image using only 4 low bits values
+
+    Args:
+        image: 3D RGB image Numpy array or PIL RGB image
+        nb_bits: optional parameter which indicates the number of bits to keep (default 4)
 
-    Usage :
+    Returns:
+        2D Numpy array with low bits information kept
+
+    Usage:
 
     >>> from PIL import Image
     >>> from ipfml import processing
@@ -310,12 +353,16 @@ def rgb_to_LAB_L_low_bits(image, nb_bits=4):
 
     return metrics.get_low_bits_img(L_block, nb_bits)
 
+
 def rgb_to_LAB_L_bits(image, interval):
-    """
-    @brief Returns only bits from LAB L canal specified into the interval
-    @param image to convert using this interval of bits value to keep
-    @param interval (begin, end) of bits values
-    @return Numpy array with reduced values
+    """Returns only bits from LAB L canal specified into the interval
+
+    Args:
+        image: image to convert using this interval of bits value to keep
+        interval: (begin, end) of bits values
+
+    Returns:
+        2D Numpy array with reduced values
 
     >>> from PIL import Image
     >>> from ipfml import processing

+ 46 - 35
setup.py

@@ -6,48 +6,59 @@ def readme():
         return f.read()
 
 class BuildTestCommand(setuptools.command.build_py.build_py):
-  """Custom build command."""
+    """Custom build command."""
 
-  def run(self):
+    def run(self):
 
-    # run tests using doctest
-    import doctest
-    from ipfml import processing
-    from ipfml import metrics
-    from ipfml.filters import noise as noise_filters
+        # run tests using doctest
+        import doctest
+        from ipfml import processing
+        from ipfml import metrics
+        from ipfml.filters import noise as noise_filters
 
-    doctest.testmod(processing)
-    doctest.testmod(metrics)
-    doctest.testmod(noise_filters)
+        print("Run test command...")
+        doctest.testmod(processing)
+        doctest.testmod(metrics)
+        doctest.testmod(noise_filters)
 
-    setuptools.command.build_py.build_py.run(self)
+        # Run format code using ypaf
+        try:
+            print("Run format code command...")
+            self.spawn(['yapf', '-ir', '-vv', 'ipfml'])
+        except RuntimeError:
+            self.warn('format pakcage code failed')
 
-setup(name='IPFML',
-      version='0.1.6',
-      description='Image Processing For Machine Learning',
-      long_description=readme(),
-      classifiers=[
+        setuptools.command.build_py.build_py.run(self)
+
+
+setup(
+    name='ipfml',
+    version='0.1.6',
+    description='Image Processing For Machine Learning',
+    long_description=readme(),
+    classifiers=[
         'Development Status :: 3 - Alpha',
         'License :: OSI Approved :: MIT License',
         'Programming Language :: Python :: 3.6',
         'Topic :: Scientific/Engineering :: Artificial Intelligence'
-      ],
-      url='https://gogs.univ-littoral.fr/jerome.buisine/IPFML',
-      author='Jérôme BUISINE',
-      author_email='jerome.buisine@univ-littoral.fr',
-      license='MIT',
-      packages=['ipfml'],
-      install_requires=[
-          'matplotlib',
-          'numpy',
-          'Pillow',
-          'sklearn',
-          'scikit-image',
-          'scipy',
-          'opencv-python',
-          'scipy'
-      ],
-      cmdclass={
+    ],
+    url='https://gogs.univ-littoral.fr/jerome.buisine/IPFML',
+    author='Jérôme BUISINE',
+    author_email='jerome.buisine@univ-littoral.fr',
+    license='MIT',
+    packages=['ipfml'],
+    install_requires=[
+        'matplotlib',
+        'numpy',
+        'Pillow',
+        'sklearn',
+        'scikit-image',
+        'scipy',
+        'opencv-python',
+        'scipy',
+        'yapf'
+    ],
+    cmdclass={
         'build_py': BuildTestCommand,
-      },
-      zip_safe=False)
+    },
+    zip_safe=False)