Parcourir la source

Add of utils normalization methods

Jerome Buisine il y a 5 ans
Parent
commit
64e90944f1
3 fichiers modifiés avec 52 ajouts et 2 suppressions
  1. 2 0
      README.md
  2. 49 1
      ipfml/image_processing.py
  3. 1 1
      setup.py

+ 2 - 0
README.md

@@ -27,6 +27,8 @@ This project contains modules.
     - 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*
+    - normalize_arr(arr): *Normalize array values*
+    - normalize_arr_with_range(arr, min, max): *Normalize array values with specific min and max values*
 
 - **metrics** : *Metrics computation of PIL image*
     - get_SVD(image): *Transforms PIL Image into SVD*

+ 49 - 1
ipfml/image_processing.py

@@ -181,4 +181,52 @@ def divide_in_blocks(image, block_size):
             current_block = image_array[begin_x:(begin_x + width), begin_y:(begin_y + height)]
             blocks.append(Image.fromarray(current_block.astype('uint8'), mode))
 
-    return blocks
+    return blocks
+
+    
+def normalize_arr(arr):
+    '''
+    @brief Normalize data of 1D array shape
+    @param array - array data of 1D shape
+
+    Usage :
+
+    >>> from ipfml import image_processing
+    >>> import numpy as np
+    >>> arr = np.arange(11)
+    >>> arr_normalized = image_processing.normalize_arr(arr)
+    >>> arr_normalized[1]
+    0.1
+    '''
+
+    output_arr = []
+    max_value = max(arr)
+    min_value = min(arr)
+
+    for v in arr:
+         output_arr.append((v - min_value) / (max_value - min_value))
+    
+    return output_arr
+
+
+def normalize_arr_with_range(arr, min, max):
+    '''
+    @brief Normalize data of 1D array shape
+    @param array - array data of 1D shape
+
+    Usage :
+
+    >>> from ipfml import image_processing
+    >>> import numpy as np
+    >>> arr = np.arange(11)
+    >>> arr_normalized = image_processing.normalize_arr_with_range(arr, 0, 20)
+    >>> arr_normalized[1]
+    0.05
+    '''
+    
+    output_arr = []
+
+    for v in arr:
+        output_arr.append((v - min) / (max - min))
+    
+    return output_arr

+ 1 - 1
setup.py

@@ -23,7 +23,7 @@ class BuildTestCommand(setuptools.command.build_py.build_py):
     setuptools.command.build_py.build_py.run(self)
 
 setup(name='IPFML',
-      version='0.0.8',
+      version='0.0.9',
       description='Image Processing For Machine Learning',
       long_description=readme(),
       classifiers=[