Parcourir la source

Package refactoring; Documentation updated; Error handling improvments

Jérôme BUISINE il y a 5 ans
Parent
commit
3491104de2
7 fichiers modifiés avec 139 ajouts et 242 suppressions
  1. 9 5
      README.md
  2. 14 36
      README.rst
  3. 0 0
      ipfml/filters/__init__.py
  4. 0 0
      ipfml/filters/noise.py
  5. 62 65
      ipfml/metrics.py
  6. 49 133
      ipfml/image_processing.py
  7. 5 3
      setup.py

+ 9 - 5
README.md

@@ -20,15 +20,15 @@ Modules
 
 This project contains modules.
 
-- **image_processing** : *Image processing module*
+- **processing** : *Image processing module*
     - get_LAB_L_SVD_U(image): *Returns U SVD from L of LAB Image information*
     - get_LAB_L_SVD_s(image): *Returns s (Singular values) SVD from L of LAB Image information*
     - get_LAB_L_SVD_V(image): *Returns V SVD from L of LAB Image information*
     - divide_in_blocks(image, block_size): *Divide image into equal size blocks*
     - rgb_to_mscn(image): *Convert RGB Image into Mean Subtracted Contrast Normalized (MSCN) using only gray level*
-    - rgb_to_grey_low_bits(image, bind=15): *Convert RGB Image into grey image using only 4 low bits values by default*
-    - rgb_to_LAB_L_low_bits(image, bind=15): *Convert RGB Image into LAB L channel image using only 4 low bits values by default*
-    - rgb_to_LAB_L_bits(image, interval): *Convert RGB Image into LAB L channel image using specific interval of bits to keep (2, 5) such as example*
+    - rgb_to_grey_low_bits(image, nb_bits=4): *Convert RGB Image into grey image using only 4 low bits values by default*
+    - rgb_to_LAB_L_low_bits(image, nb_bits=4): *Convert RGB Image into LAB L chanel image using only 4 low bits values by default*
+    - rgb_to_LAB_L_bits(image, interval): *Convert RGB Image into LAB L chanel image using specific interval of bits to keep (2, 5) such as example*
     - normalize_arr(arr): *Normalize array values*
     - normalize_arr_with_range(arr, min, max): *Normalize array values with specific min and max values*
     - normalize_2D_arr(arr): *Return 2D array normalize from its min and max values*
@@ -46,7 +46,11 @@ This project contains modules.
     - get_XYZ_X(image): *Transforms Image into XYZ and returns only 'X' part*
     - get_XYZ_Y(image): *Transforms Image into XYZ and returns only 'Y' part*
     - get_XYZ_Z(image): *Transforms Image into XYZ and returns only 'Z' part*
-    - get_low_bits_img(image, bind=15): *Returns Image or Numpy array with data information reduced using only low bits (by default*
+    - get_low_bits_img(image, nb_bits=4): *Returns Image or Numpy array with data information reduced using only low bits*
+
+- **filters** : *Image filter module*
+    - **noise** : *Noise filters implemented*
+        - white_noise(image, n, distribution_interval=(-0.5, 0.5)) : *Add white noise to image using the **n** variable which manages intensity of noise in interval [1, 999] and the **distribution_interval** variable which manages interval of uniform distribution*
 
 All these modules will be enhanced during development of the project
 

+ 14 - 36
README.rst

@@ -3,6 +3,8 @@ IPFML
 
 Image Processing For Machine Learning package.
 
+This is a package developed during a thesis project.
+
 How to use ?
 ------------
 
@@ -19,39 +21,15 @@ Modules
 
 This project contains modules.
 
-- **image_processing** : *Image processing module*
-    - get_LAB_L_SVD_U(image): *Returns U SVD from L of LAB Image information*
-    - get_LAB_L_SVD_s(image): *Returns s (Singular values) SVD from L of LAB Image information*
-    - get_LAB_L_SVD_V(image): *Returns V SVD from L of LAB Image information*
-    - divide_in_blocks(image, block_size): Divide image into equal size blocks
-    - rgb_to_mscn(image): *Convert RGB Image into Mean Subtracted Contrast Normalized (MSCN) using only gray level*
-    - rgb_to_grey_low_bits(image, bind=15): *Convert RGB Image into grey image using only 4 low bits values by default*
-    - rgb_to_LAB_L_low_bits(image, bind=15): *Convert RGB Image into LAB L channel image using only 4 low bits values by default*
-    - rgb_to_LAB_L_bits(image, interval): *Convert RGB Image into LAB L channel image using specific interval of bits to keep (2, 5) such as example*
-    - normalize_arr(arr): *Normalize array values*
-    - normalize_arr_with_range(arr, min, max): *Normalize array values with specific min and max values*
-    - normalize_2D_arr(arr): *Return 2D array normalize from its min and max values*
-    
-- **metrics** : *Metrics computation of PIL or 2D numpy image*
-    - get_SVD(image): *Transforms PIL Image into SVD*
-    - get_SVD_U(image): *Transforms PIL Image into SVD and returns only 'U' part*
-    - get_SVD_s(image): *Transforms PIL Image into SVD and returns only 's' part*
-    - get_SVD_V(image): *Transforms PIL Image into SVD and returns only 'V' part*
-    - get_LAB(image): *Transforms PIL Image into LAB*
-    - get_LAB_L(image): *Transforms PIL Image into LAB and returns only 'L' part*
-    - get_LAB_A(image): *Transforms PIL Image into LAB and returns only 'A' part*
-    - get_LAB_B(image): *Transforms PIL Image into LAB and returns only 'B' part*
-    - get_XYZ(image): *Transforms PIL Image into XYZ*
-    - get_XYZ_X(image): *Transforms PIL Image into XYZ and returns only 'X' part*
-    - get_XYZ_Y(image): *Transforms PIL Image into XYZ and returns only 'Y' part*
-    - get_XYZ_Z(image): *Transforms PIL Image into XYZ and returns only 'Z' part*
-    - get_low_bits_img(image, bind=15): *Returns Image or Numpy array with data information reduced using only low bits (by default 4)*
-
-All these modules will be enhanced during development of the project
-
-How to contribute
------------------
-
-This git project uses git-flow_ implementation. You are free to contribute to it.
-
-.. _git-flow : https://danielkummer.github.io/git-flow-cheatsheet/
+- **processing** : *Image processing of images*
+- **metrics** : *Metrics computation of PIL or 2D, 3D numpy images*
+- **filters** : *Filters implemented such as noise filters*
+
+All these modules will be enhanced during development of the package.
+
+Documentation
+-------------
+
+For more information about package, documentation_ is available  
+
+.. _documentation: https://gogs.univ-littoral.fr/jerome.buisine/IPFML

+ 0 - 0
ipfml/filters/__init__.py


+ 0 - 0
ipfml/filters/noise.py


+ 62 - 65
ipfml/metrics.py

@@ -9,32 +9,11 @@ from skimage import io, color
 
 import cv2
 
-def get_image_path(image):
-    """
-    @brief Returns file path of PIL Image
-    @param PIL Image
-    @return image path
-
-    >>> from PIL import Image
-    >>> from ipfml import metrics
-    >>> img = Image.open('./images/test_img.png')
-    >>> path = metrics.get_image_path(img)
-    >>> 'images/test_img.png' in path
-    True
-    """
-
-    if hasattr(image, 'filename'):
-        file_path = image.filename
-    else:
-        raise Exception("Image provided is not correct, required filename property...")
-
-    return file_path
-
 def get_SVD(image):
     """
     @brief Transforms Image into SVD
     @param image to convert
-    @return U, s, V image decomposition
+    @return U, s, V obtained from SVD compression
 
     Usage :
 
@@ -54,8 +33,8 @@ def get_SVD(image):
 def get_SVD_s(image):
     """
     @brief Transforms Image into SVD and returns only 's' part
-    @param image to convert
-    @return s
+    @param image - image to convert
+    @return s obtained from SVD compression
 
     Usage :
 
@@ -72,8 +51,8 @@ def get_SVD_s(image):
 def get_SVD_U(image):
     """
     @brief Transforms Image into SVD and returns only 'U' part
-    @param image to convert
-    @return U
+    @param image - image to convert
+    @return U matrix from SVD compression
 
     Usage :
 
@@ -91,8 +70,8 @@ def get_SVD_U(image):
 def get_SVD_V(image):
     """
     @brief Transforms Image into SVD and returns only 'V' part
-    @param image to convert
-    @return V
+    @param image - image to convert
+    @return V matrix obtained from SVD compression
 
     Usage :
 
@@ -109,8 +88,8 @@ def get_SVD_V(image):
 
 def get_LAB(image):
     """
-    @brief Transforms PIL RGB Image into LAB
-    @param image to convert
+    @brief Transforms RGB  Image into Lab
+    @param image - image to convert
     @return Lab information
 
     Usage :
@@ -127,9 +106,9 @@ def get_LAB(image):
 
 def get_LAB_L(image):
     """
-    @brief Transforms PIL RGB Image into LAB and returns L
-    @param image to convert
-    @return Lab information
+    @brief Transforms RGB Image into Lab and returns L
+    @param image - image to convert
+    @return L chanel from Lab information
 
     >>> from PIL import Image
     >>> from ipfml import metrics
@@ -142,38 +121,38 @@ def get_LAB_L(image):
     lab = get_LAB(image)
     return lab[:, :, 0]
 
-def get_LAB_A(image):
+def get_LAB_a(image):
     """
-    @brief Transforms PIL RGB Image into LAB and returns A
-    @param image to convert
-    @return Lab information
+    @brief Transforms RGB Image into LAB and returns a
+    @param image - image to convert
+    @return a chanel from Lab information
 
     Usage :
 
     >>> from PIL import Image
     >>> from ipfml import metrics
     >>> img = Image.open('./images/test_img.png')
-    >>> A = metrics.get_LAB_A(img)
-    >>> A.shape
+    >>> a = metrics.get_LAB_a(img)
+    >>> a.shape
     (200, 200)
     """
 
     lab = get_LAB(image)
     return lab[:, :, 1]
 
-def get_LAB_B(image):
+def get_LAB_b(image):
     """
-    @brief Transforms PIL RGB Image into LAB and returns B
-    @param image to convert
-    @return Lab information
+    @brief Transforms RGB Image into LAB and returns b
+    @param image - image to convert
+    @return b chanel from Lab information
 
     Usage :
 
     >>> from PIL import Image
     >>> from ipfml import metrics
     >>> img = Image.open('./images/test_img.png')
-    >>> B = metrics.get_LAB_B(img)
-    >>> B.shape
+    >>> b = metrics.get_LAB_b(img)
+    >>> b.shape
     (200, 200)
     """
 
@@ -182,9 +161,9 @@ def get_LAB_B(image):
 
 def get_XYZ(image):
     """
-    @brief Transforms PIL RGB Image into XYZ
-    @param image to convert
-    @return Lab information
+    @brief Transforms RGB Image into XYZ
+    @param image - image to convert
+    @return XYZ information obtained from transformation
 
     Usage :
 
@@ -199,9 +178,9 @@ def get_XYZ(image):
 
 def get_XYZ_X(image):
     """
-    @brief Transforms PIL RGB Image into XYZ and returns X
-    @param image to convert
-    @return Lab information
+    @brief Transforms RGB Image into XYZ and returns X
+    @param image - image to convert
+    @return X chanel from XYZ information
 
     Usage :
 
@@ -218,9 +197,9 @@ def get_XYZ_X(image):
 
 def get_XYZ_Y(image):
     """
-    @brief Transforms PIL RGB Image into XYZ and returns Y
-    @param image to convert
-    @return Lab information
+    @brief Transforms RGB Image into XYZ and returns Y
+    @param image - image to convert
+    @return Y chanel from XYZ information
 
     Usage :
 
@@ -237,9 +216,9 @@ def get_XYZ_Y(image):
 
 def get_XYZ_Z(image):
     """
-    @brief Transforms PIL RGB Image into XYZ and returns Z
-    @param image to convert
-    @return Lab information
+    @brief Transforms RGB Image into XYZ and returns Z
+    @param image - image to convert
+    @return Z chanel from XYZ information
 
     Usage :
 
@@ -254,11 +233,11 @@ def get_XYZ_Z(image):
     xyz = color.rgb2xyz(image)
     return xyz[:, :, 2]
 
-def get_low_bits_img(image, bind=15):
+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 to convert
-    @bind optional : bits to keep using & Bitwise operator
+    @param image, image to convert
+    @param nb_bits, optional parameter which indicates the number of bits to keep
     @return Numpy array with reduced values
 
     Usage :
@@ -266,14 +245,22 @@ def get_low_bits_img(image, bind=15):
     >>> from PIL import Image
     >>> from ipfml import metrics
     >>> img = Image.open('./images/test_img.png')
-    >>> low_bits_img = metrics.get_low_bits_img(img)
+    >>> low_bits_img = metrics.get_low_bits_img(img, 5)
     >>> low_bits_img.shape
     (200, 200, 3)
     """
 
+    if nb_bits <= 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].")
+
     img_arr = np.array(image)
 
-    return img_arr & bind
+    bits_values = sum([pow(2, i - 1) for i in range(1, nb_bits + 1)])
+
+    return img_arr & bits_values
 
 def get_bits_img(image, interval):
     """
@@ -295,6 +282,15 @@ def get_bits_img(image, interval):
     img_arr = np.array(image)
     begin, end = interval
 
+    if begin < 1:
+        raise ValueError("Unexpected value of interval. Minimum value of interval needs to be >= 1.")
+
+    if end > 8:
+        raise ValueError("Unexpected value of interval. Maximum value of interval needs to be <= 8.")
+
+    if begin >= end:
+        raise ValueError("Unexpected interval values order.")
+
     bits_values = sum([pow(2, i - 1) for i in range(begin, end + 1)])
 
     return img_arr & bits_values
@@ -303,14 +299,15 @@ def get_bits_img(image, interval):
 def gray_to_mscn(image):
     """
     @brief Convert Grayscale Image into Mean Subtracted Contrast Normalized (MSCN)
-    @param grayscale image numpy array or PIL RGB image
+    @param image - grayscale image
+    @returns MSCN matrix obtained from transformation
 
     Usage :
 
     >>> from PIL import Image
-    >>> from ipfml import image_processing
+    >>> from ipfml import processing
     >>> img = Image.open('./images/test_img.png')
-    >>> img_mscn = image_processing.rgb_to_mscn(img)
+    >>> img_mscn = processing.rgb_to_mscn(img)
     >>> img_mscn.shape
     (200, 200)
     """

+ 49 - 133
ipfml/image_processing.py

@@ -12,15 +12,15 @@ from scipy import signal
 def get_LAB_L_SVD(image):
     """
     @brief Returns Singular values from LAB L Image information
-    @param fig a matplotlib figure
-    @return a Python Imaging Library (PIL) image : default size (480,640,3)
+    @param image - PIL Image or Numpy array
+    @return U, s, V information obtained from SVD compression using Lab
 
     Usage :
 
     >>> from PIL import Image
-    >>> from ipfml import image_processing
+    >>> from ipfml import processing
     >>> img = Image.open('./images/test_img.png')
-    >>> U, s, V = image_processing.get_LAB_L_SVD(img)
+    >>> U, s, V = processing.get_LAB_L_SVD(img)
     >>> U.shape
     (200, 200)
     >>> len(s)
@@ -34,33 +34,34 @@ def get_LAB_L_SVD(image):
 def get_LAB_L_SVD_s(image):
     """
     @brief Returns s (Singular values) SVD from L of LAB Image information
-    @param PIL Image
+    @param image - PIL Image or numpy array
     @return vector of singular values
 
     Usage :
 
     >>> from PIL import Image
-    >>> from ipfml import image_processing
+    >>> from ipfml import processing
     >>> img = Image.open('./images/test_img.png')
-    >>> s = image_processing.get_LAB_L_SVD_s(img)
+    >>> s = processing.get_LAB_L_SVD_s(img)
     >>> len(s)
     200
     """
     L = metrics.get_LAB_L(image)
     return metrics.get_SVD_s(L)
 
+
 def get_LAB_L_SVD_U(image):
     """
     @brief Returns U SVD from L of LAB Image information
-    @param PIL Image
-    @return vector of singular values
+    @param image - PIL Image
+    @return U matrix of SVD compression
 
     Usage :
 
     >>> from PIL import Image
-    >>> from ipfml import image_processing
+    >>> from ipfml import processing
     >>> img = Image.open('./images/test_img.png')
-    >>> U = image_processing.get_LAB_L_SVD_U(img)
+    >>> U = processing.get_LAB_L_SVD_U(img)
     >>> U.shape
     (200, 200)
     """
@@ -70,15 +71,15 @@ def get_LAB_L_SVD_U(image):
 def get_LAB_L_SVD_V(image):
     """
     @brief Returns V SVD from L of LAB Image information
-    @param PIL Image
-    @return vector of singular values
+    @param image - PIL Image or numpy array
+    @return V matrix of SVD compression
 
     Usage :
 
     >>> from PIL import Image
-    >>> from ipfml import image_processing
+    >>> from ipfml import processing
     >>> img = Image.open('./images/test_img.png')
-    >>> V = image_processing.get_LAB_L_SVD_V(img)
+    >>> V = processing.get_LAB_L_SVD_V(img)
     >>> V.shape
     (200, 200)
     """
@@ -86,10 +87,11 @@ def get_LAB_L_SVD_V(image):
     L = metrics.get_LAB_L(image)
     return metrics.get_SVD_V(L)
 
+
 def divide_in_blocks(image, block_size, pil=True):
     '''
     @brief Divide image into equal size blocks
-    @param img - PIL Image or numpy array
+    @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)
@@ -98,7 +100,7 @@ def divide_in_blocks(image, block_size, pil=True):
 
     >>> import numpy as np
     >>> from PIL import Image
-    >>> from ipfml import image_processing
+    >>> from ipfml import processing
     >>> from ipfml import metrics
     >>> image_values = np.random.randint(255, size=(800, 800, 3))
     >>> blocks = divide_in_blocks(image_values, (20, 20))
@@ -164,14 +166,15 @@ def divide_in_blocks(image, block_size, pil=True):
 def normalize_arr(arr):
     '''
     @brief Normalize data of 1D array shape
-    @param array - array data of 1D shape
+    @param arr - array data of 1D shape
+    @return Normalized 1D array
 
     Usage :
 
-    >>> from ipfml import image_processing
+    >>> from ipfml import processing
     >>> import numpy as np
     >>> arr = np.arange(11)
-    >>> arr_normalized = image_processing.normalize_arr(arr)
+    >>> arr_normalized = processing.normalize_arr(arr)
     >>> arr_normalized[1]
     0.1
     '''
@@ -189,14 +192,14 @@ def normalize_arr(arr):
 def normalize_arr_with_range(arr, min, max):
     '''
     @brief Normalize data of 1D array shape
-    @param array - array data of 1D shape
+    @param arr - array data of 1D shape
 
     Usage :
 
-    >>> from ipfml import image_processing
+    >>> from ipfml import processing
     >>> import numpy as np
     >>> arr = np.arange(11)
-    >>> arr_normalized = image_processing.normalize_arr_with_range(arr, 0, 20)
+    >>> arr_normalized = processing.normalize_arr_with_range(arr, 0, 20)
     >>> arr_normalized[1]
     0.05
     '''
@@ -208,18 +211,20 @@ def normalize_arr_with_range(arr, min, max):
 
     return output_arr
 
+
 def normalize_2D_arr(arr):
     """
     @brief Return array normalize from its min and max values
-    @param 2D numpy array
+    @param arr - 2D numpy array
+    @return normalized 2D array
 
     Usage :
 
     >>> from PIL import Image
-    >>> from ipfml import image_processing
+    >>> from ipfml import processing
     >>> img = Image.open('./images/test_img.png')
-    >>> img_mscn = image_processing.rgb_to_mscn(img)
-    >>> img_normalized = image_processing.normalize_2D_arr(img_mscn)
+    >>> img_mscn = processing.rgb_to_mscn(img)
+    >>> img_normalized = processing.normalize_2D_arr(img_mscn)
     >>> img_normalized.shape
     (200, 200)
     """
@@ -234,6 +239,7 @@ def normalize_2D_arr(arr):
 
     return f(arr)
 
+
 def rgb_to_mscn(image):
     """
     @brief Convert RGB Image into Mean Subtracted Contrast Normalized (MSCN)
@@ -242,9 +248,9 @@ def rgb_to_mscn(image):
     Usage :
 
     >>> from PIL import Image
-    >>> from ipfml import image_processing
+    >>> from ipfml import processing
     >>> img = Image.open('./images/test_img.png')
-    >>> img_mscn = image_processing.rgb_to_mscn(img)
+    >>> img_mscn = processing.rgb_to_mscn(img)
     >>> img_mscn.shape
     (200, 200)
     """
@@ -257,17 +263,19 @@ def rgb_to_mscn(image):
 
     return metrics.gray_to_mscn(im)
 
-def rgb_to_grey_low_bits(image, bind=15):
+
+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
 
     Usage :
 
     >>> from PIL import Image
-    >>> from ipfml import image_processing
+    >>> from ipfml import processing
     >>> img = Image.open('./images/test_img.png')
-    >>> low_bits_grey_img = image_processing.rgb_to_grey_low_bits(img)
+    >>> low_bits_grey_img = processing.rgb_to_grey_low_bits(img, 5)
     >>> low_bits_grey_img.shape
     (200, 200)
     """
@@ -275,26 +283,28 @@ def rgb_to_grey_low_bits(image, bind=15):
     img_arr = np.array(image)
     grey_block = np.array(color.rgb2gray(img_arr)*255, 'uint8')
 
-    return metrics.get_low_bits_img(grey_block, bind)
+    return metrics.get_low_bits_img(grey_block, nb_bits)
+
 
-def rgb_to_LAB_L_low_bits(image, bind=15):
+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
 
     Usage :
 
     >>> from PIL import Image
-    >>> from ipfml import image_processing
+    >>> from ipfml import processing
     >>> img = Image.open('./images/test_img.png')
-    >>> low_bits_Lab_l_img = image_processing.rgb_to_LAB_L_low_bits(img)
+    >>> low_bits_Lab_l_img = processing.rgb_to_LAB_L_low_bits(img, 5)
     >>> low_bits_Lab_l_img.shape
     (200, 200)
     """
 
     L_block = np.asarray(metrics.get_LAB_L(image), 'uint8')
 
-    return metrics.get_low_bits_img(L_block, bind)
+    return metrics.get_low_bits_img(L_block, nb_bits)
 
 def rgb_to_LAB_L_bits(image, interval):
     """
@@ -304,9 +314,9 @@ def rgb_to_LAB_L_bits(image, interval):
     @return Numpy array with reduced values
 
     >>> from PIL import Image
-    >>> from ipfml import image_processing
+    >>> from ipfml import processing
     >>> img = Image.open('./images/test_img.png')
-    >>> bits_Lab_l_img = image_processing.rgb_to_LAB_L_bits(img)
+    >>> bits_Lab_l_img = processing.rgb_to_LAB_L_bits(img, (2, 6))
     >>> bits_Lab_l_img.shape
     (200, 200)
     """
@@ -314,97 +324,3 @@ def rgb_to_LAB_L_bits(image, interval):
     L_block = np.asarray(metrics.get_LAB_L(image), 'uint8')
 
     return metrics.get_bits_img(L_block, interval)
-
-# TODO : Check this method too...
-def get_random_active_block(blocks, threshold = 0.1):
-    """
-    @brief Find an active block from blocks and return it (randomly way)
-    @param 2D numpy array
-    @param threshold 0.1 by default
-    """
-
-    active_blocks = []
-
-    for id, block in enumerate(blocks):
-
-        arr = np.asarray(block)
-        variance = np.var(arr.flatten())
-
-        if variance >= threshold:
-            active_blocks.append(id)
-
-    r_id = random.choice(active_blocks)
-
-    return np.asarray(blocks[r_id])
-
-
-# TODO : check this method and check how to use active block
-def segment_relation_in_block(block, active_block):
-    """
-    @brief Return bêta value to quantity relation between central segment and surrouding regions into block
-    @param 2D numpy array
-    """
-
-    if block.ndim != 2:
-        raise "Numpy array dimension is incorrect, expected 2."
-
-
-    # getting middle information of numpy array
-    x, y = block.shape
-
-    if y < 4:
-        raise "Block size too small needed at least (x, 4) shape"
-
-    middle = int(y / 2)
-
-    # get central segments
-    central_segments = block[:, middle-1:middle+1]
-
-    # getting surrouding parts
-    left_part = block[:, 0:middle-1]
-    right_part = block[:, middle+1:]
-    surrounding_parts = np.concatenate([left_part, right_part])
-
-    std_sur = np.std(surrounding_parts.flatten())
-    std_cen = np.std(central_segments.flatten())
-    std_block = np.std(block.flatten())
-
-    std_q = std_cen / std_sur
-
-    # from article, it says that block if affected with noise if (std_block > 2 * beta)
-    beta = abs(std_q - std_block) / max(std_q, std_block)
-
-    return beta
-
-### other way to compute MSCN :
-# TODO : Temp code, check to remove or use it
-
-def normalize_kernel(kernel):
-    return kernel / np.sum(kernel)
-
-def gaussian_kernel2d(n, sigma):
-    Y, X = np.indices((n, n)) - int(n/2)
-    gaussian_kernel = 1 / (2 * np.pi * sigma ** 2) * np.exp(-(X ** 2 + Y ** 2) / (2 * sigma ** 2))
-    return normalize_kernel(gaussian_kernel)
-
-def local_mean(image, kernel):
-    return signal.convolve2d(image, kernel, 'same')
-
-def local_deviation(image, local_mean, kernel):
-    "Vectorized approximation of local deviation"
-    sigma = image ** 2
-    sigma = signal.convolve2d(sigma, kernel, 'same')
-    return np.sqrt(np.abs(local_mean ** 2 - sigma))
-
-def calculate_mscn_coefficients(image, kernel_size=6, sigma=7/6):
-
-    # check if PIL image or not
-    img_arr = np.array(image)
-
-    C = 1/255
-    kernel = gaussian_kernel2d(kernel_size, sigma=sigma)
-    local_mean = signal.convolve2d(img_arr, kernel, 'same')
-    local_var = local_deviation(img_arr, local_mean, kernel)
-
-    return (img_arr - local_mean) / (local_var + C)
-

+ 5 - 3
setup.py

@@ -12,16 +12,18 @@ class BuildTestCommand(setuptools.command.build_py.build_py):
 
     # run tests using doctest
     import doctest
-    from ipfml import image_processing
+    from ipfml import processing
     from ipfml import metrics
+    from ipfml import filters
 
-    doctest.testmod(image_processing)
+    doctest.testmod(processing)
     doctest.testmod(metrics)
+    doctest.testmod(filters)
 
     setuptools.command.build_py.build_py.run(self)
 
 setup(name='IPFML',
-      version='0.1.5',
+      version='0.1.6',
       description='Image Processing For Machine Learning',
       long_description=readme(),
       classifiers=[