Parcourir la source

Add of contribution guidelines

Jérôme BUISINE il y a 5 ans
Parent
commit
b80571d1e0
7 fichiers modifiés avec 181 ajouts et 17 suppressions
  1. 160 0
      CONTRIBUTING.md
  2. 1 1
      README.md
  3. 5 0
      README.rst
  4. BIN
      docs/build/doctrees/environment.pickle
  5. 2 4
      docs/source/contributing.rst
  6. 12 12
      ipfml/filters/noise.py
  7. 1 0
      requirements.txt

+ 160 - 0
CONTRIBUTING.md

@@ -0,0 +1,160 @@
+Contribution guidelines
+=====================================
+
+<p align="center">
+    <img src="ipfml_logo.png" width="30%">
+    <br />
+    Image Processing For Machine Learning
+</p>
+
+
+# Welcome !
+
+Thank you for taking the time to read this guide for the package's contribution. I'm glad to know that you may bring a lot to the IPFML package. This document will show you the good development practices used in the project and how you can easily participate in its evolution!
+
+# Table of contents
+
+1. [Naming conventions](#naming-conventions)
+
+    1.1. [Git naming conventions](#git-naming-conventions)
+
+    1.2. [Package modules conventions](#package-modules-conventions)
+
+2. [Coding conventions](#coding-conventions)
+
+    2.1. [Python conventions](#python-conventions)
+
+    2.3  [Code documentation](#code-documentation)
+
+    2.2. [Test implementation](#test-implementation)
+
+3. [Submission process](#submission-process)
+
+    3.1. [Build package](#build-package)
+
+    3.2. [Pull request](#pull-request)
+
+4. [Request an enhancement or report a bug](#request-an-enhancement-or-report-a-bug)
+
+# Naming conventions
+
+## Git naming conventions
+
+This project uses the naming conventions of the git branches set up by the [git-flow](https://danielkummer.github.io/git-flow-cheatsheet/) interface. To make your contribution as easy as possible to inject into the project, you will need to name your git branch as follows:
+
+```bash
+git branch feature/YourFeatureBranchName
+```
+
+Using git-flow interface:
+
+```bash
+git flow feature start YourFeatureBranchName
+```
+
+## Package modules conventions
+
+As you perhaps already saw, package contains multiples modules and submodules. It's really import to be well organized package and let it intuitive to access as possible to features.
+
+For the moment there are no precise conventions on the naming of new modules or sub-modules, it must just in a first step respect the hierarchy already in place and avoid any redundancies.
+
+In order to facilitate the integration of new modules, do not hesitate to let me know the name it could have beforehand.
+
+# Coding conventions
+
+## Python conventions
+
+This project follows the [coding conventions](http://google.github.io/styleguide/pyguide.html) implemented by Google. To help you to format **\*.py** files, it is possible to use the [yapf](https://github.com/google/yapf/) package developed by Google.
+
+Note that the **yapf** package is used during build process of **ipfml** package to format the whole code following these conventions.
+
+## Code documentation
+
+In order to allow quick access to the code, the project follows the documentation conventions (docstring) proposed by Google. Here an example:
+
+```python
+'''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)
+
+  Raises:
+      ValueError: If `image_width` or `image_heigt` are not compatible to produce correct block sizes
+'''
+```
+
+You can generate documentation and display updates using these following commands:
+
+```
+bash build.sh
+firefox docs/index.html
+```
+
+## Test implementation
+
+This project use the [doctest](https://docs.python.org/3/library/doctest.html) package which enables to write tests into documentation as shown in example below:
+
+```python
+"""Cauchy 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.0002)
+
+  Returns:
+      2D Numpy array with Cauchy noise applied
+
+  Example:
+
+  >>> from ipfml.filters.noise import cauchy_noise
+  >>> import numpy as np
+  >>> image = np.random.uniform(0, 255, 10000).reshape((100, 100))
+  >>> noisy_image = cauchy_noise(image, 10)
+  >>> noisy_image.shape
+  (100, 100)
+"""
+```
+
+Moreover, tests written are displayed into generated documentation and let examples of how to use the developed function.
+
+# Submission process
+
+## Build pakcage
+
+One thing to do before submit your feature is to build the package:
+
+```bash
+python setup.py build
+```
+
+This command do a lot of thing for you:
+  - Runs the tests from documentation and raise errors if there are.
+  - Formats all **\*.py** inside *ipfml* folder using **yapf**.
+  - Generate new documentation output inside **docs** folder.
+
+## Pull request
+
+Once you have built the package following previous instructions. You can make a pull request using GitHub. A [documentation](https://help.github.com/articles/about-pull-requests/) about pull requests is available.
+
+# Request an enhancement or report a bug
+
+To enhance the package, do not hesitate to report bug or missing feature. To do that, just submit an issue using at one of this labels:
+
+- **feature** or **idea**: for new an enhancement to develop
+- **bug:** for a detected bug
+
+You can also add your own labels too or add priority label:
+
+- prio:**low**
+- prio:**normal**
+- prio:**high**
+
+Whatever the problem reported, I will thank you for your contribution to this project. So do not hesitate.

+ 1 - 1
README.md

@@ -38,7 +38,7 @@ All these modules will be enhanced during development of the package. Documentat
 How to contribute
 -----------------
 
-This git project uses [git-flow](https://danielkummer.github.io/git-flow-cheatsheet/) implementation. You are free to contribute to it.
+Please refer to the [CONTRIBUTION.md](https://github.com/jbuisine/IPFML/blob/master/LICENSE) file if you want to contribute!
 
 ## Contributors
 

+ 5 - 0
README.rst

@@ -40,3 +40,8 @@ Documentation
 For more information about package, documentation_ is available.
 
 .. _documentation: https://jbuisine.github.io/IPFML/
+
+Contribution
+------------
+
+Please refer to the [CONTRIBUTION.md](https://github.com/jbuisine/IPFML/blob/master/LICENSE) file if you want to contribute!

BIN
docs/build/doctrees/environment.pickle


+ 2 - 4
docs/source/contributing.rst

@@ -6,13 +6,11 @@ Contributing
    :align: center
 
 
-
 Using GitHub
 ------------
 
 This git project uses git-flow_ implementation. You are free to contribute to it.
 
-.. _git-flow: https://danielkummer.github.io/git-flow-cheatsheet/    
-
-You just have to create your own feature branch and make a pull request.
+.. _git-flow: https://danielkummer.github.io/git-flow-cheatsheet/
 
+Please refer to the [CONTRIBUTION.md](https://github.com/jbuisine/IPFML/blob/master/LICENSE) guidelines file if you want more information about process!

+ 12 - 12
ipfml/filters/noise.py

@@ -21,7 +21,7 @@ def _global_noise_filter(image, generator, updator, identical=False):
     >>> from ipfml.filters.noise import _global_noise_filter as gf
     >>> import numpy as np
     >>> image = np.random.uniform(0, 255, 10000).reshape((100, 100))
-    >>> generator = lambda w, h: np.random.uniform(-0.5, 0.5, (w, h))
+    >>> generator = lambda h, w: np.random.uniform(-0.5, 0.5, (h, w))
     >>> n = 10
     >>> k = 0.2
     >>> updator = lambda x, noise: x + n * k * noise
@@ -34,9 +34,9 @@ def _global_noise_filter(image, generator, updator, identical=False):
     nb_chanel = 1
 
     if image_array.ndim != 3:
-        width, height = image_array.shape
+        height, width = image_array.shape
     else:
-        width, height, nb_chanel = image_array.shape
+        height, width, nb_chanel = image_array.shape
 
     if nb_chanel == 1 or identical:
         noise_filter = generator(width, height)
@@ -65,7 +65,7 @@ def _global_noise_filter(image, generator, updator, identical=False):
 
             # redefine noise if necessary
             if not identical:
-                noise_filter = generator(width, height)
+                noise_filter = generator(height, width)
 
             # compute new pixel value
             # x + n * k * white_noise_filter[i] as example
@@ -115,7 +115,7 @@ def white_noise(image,
     """
 
     a, b = distribution_interval
-    generator = lambda w, h: np.random.uniform(a, b, (w, h))
+    generator = lambda h, w: np.random.uniform(a, b, (h, w))
 
     updator = lambda x, noise: x + n * k * noise
 
@@ -150,7 +150,7 @@ def gaussian_noise(image,
     """
 
     a, b = distribution_interval
-    generator = lambda w, h: np.random.normal(a, b, (w, h))
+    generator = lambda h, w: np.random.normal(a, b, (h, w))
 
     updator = lambda x, noise: x + n * k * noise
 
@@ -185,7 +185,7 @@ def laplace_noise(image,
     """
 
     a, b = distribution_interval
-    generator = lambda w, h: np.random.laplace(a, b, (w, h))
+    generator = lambda h, w: np.random.laplace(a, b, (h, w))
 
     updator = lambda x, noise: x + n * k * noise
 
@@ -220,7 +220,7 @@ def cauchy_noise(image,
     """
 
     a, b = distribution_interval
-    generator = lambda w, h: np.random.standard_cauchy((w, h))
+    generator = lambda h, w: np.random.standard_cauchy((h, w))
 
     updator = lambda x, noise: x + n * k * noise
 
@@ -255,7 +255,7 @@ def log_normal_noise(image,
     """
 
     a, b = distribution_interval
-    generator = lambda w, h: np.random.lognormal(a, b, (w, h))
+    generator = lambda h, w: np.random.lognormal(a, b, (h, w))
 
     updator = lambda x, noise: x + n * k * noise
 
@@ -290,7 +290,7 @@ def mut_white_noise(image,
     """
 
     a, b = distribution_interval
-    generator = lambda w, h: np.random.uniform(a, b, (w, h))
+    generator = lambda h, w: np.random.uniform(a, b, (h, w))
 
     updator = lambda x, noise: x * n * k * noise
 
@@ -320,7 +320,7 @@ def salt_pepper_noise(image, n, identical=False, p=0.1, k=0.5):
     (100, 100)
     """
 
-    def _generator(w, h):
+    def _generator(h, w):
 
         x = w * h
         nb_elem = int(p * x)
@@ -329,7 +329,7 @@ def salt_pepper_noise(image, n, identical=False, p=0.1, k=0.5):
         elements[0:nb_elem] = 1
         np.random.shuffle(elements)
 
-        return elements.reshape(w, h)
+        return elements.reshape(h, w)
 
     # here noise variable is boolean to update or not pixel value
     def _updator(x, noise):

+ 1 - 0
requirements.txt

@@ -8,3 +8,4 @@ scipy
 opencv-python
 scipy
 yapf
+doctest