Parcourir la source

Documentation updated

Jerome Buisine il y a 5 ans
Parent
commit
7a5ee7fb68
6 fichiers modifiés avec 79 ajouts et 140 suppressions
  1. 19 22
      README.md
  2. 7 8
      README.rst
  3. 44 49
      ipfml/image_processing.py
  4. 9 0
      ipfml/metrics.py
  5. 0 59
      ipfml/tf_model_helper.py
  6. 0 2
      setup.py

+ 19 - 22
README.md

@@ -20,34 +20,31 @@ Modules
 
 This project contains modules.
 
-- **img_processing** : *PIL image processing part*
-    - fig2data(fig): *Convert a Matplotlib figure to a 3D numpy array with RGB channels and return it*
-    - fig2img(fig): *Convert a Matplotlib figure to a PIL Image in RGB format and return it*
+- **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*
     - normalize_arr(arr): *Normalize array values*
     - normalize_arr_with_range(arr, min, max): *Normalize array values with specific min and max values*
-    - rgb_to_mscn(image): *Convert RGB Image into Mean Subtracted Contrast Normalized (MSCN) using only gray level*
-
-- **metrics** : *Metrics computation of PIL 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*
-
-- **ts_model_helper** : *contains helpful function to save or display model information and performance of tensorflow model*
-    - save(history, filename): *Function which saves data from neural network model*
-    - show(history, filename): *Function which shows data from neural network model*
+    - 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 Image into SVD*
+    - get_SVD_U(image): *Transforms Image into SVD and returns only 'U' part*
+    - get_SVD_s(image): *Transforms Image into SVD and returns only 's' part*
+    - get_SVD_V(image): *Transforms Image into SVD and returns only 'V' part*
+    - get_LAB(image): *Transforms Image into LAB*
+    - get_LAB_L(image): *Transforms Image into LAB and returns only 'L' part*
+    - get_LAB_A(image): *Transforms Image into LAB and returns only 'A' part*
+    - get_LAB_B(image): *Transforms Image into LAB and returns only 'B' part*
+    - get_XYZ(image): *Transforms Image into XYZ*
+    - 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*
 
 All these modules will be enhanced during development of the project
 

+ 7 - 8
README.rst

@@ -19,18 +19,20 @@ Modules
 
 This project contains modules.
 
-- **img_processing** : *PIL image processing part*
+- **img_processing** : *Image processing part*
     - fig2data(fig): *Convert a Matplotlib figure to a 3D numpy array with RGB channels and return it*
     - fig2img(fig): *Convert a Matplotlib figure to a PIL Image in RGB format and return it*
     - 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*
     - normalize_arr(arr): *Normalize array values*
     - normalize_arr_with_range(arr, min, max): *Normalize array values with specific min and max values*
-    - rgb_to_mscn(image): *Convert RGB Image into Mean Subtracted Contrast Normalized (MSCN) using only gray level*
-
-- **metrics** : *Metrics computation of PIL image*
+    - 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*
@@ -43,10 +45,7 @@ This project contains modules.
     - 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*
-
-- **ts_model_helper** : *contains helpful function to save or display model information and performance of tensorflow model*
-    - save(history, filename): *Function which saves data from neural network model*
-    - show(history, filename): *Function which shows data from neural network model*
+    - 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
 

+ 44 - 49
ipfml/image_processing.py

@@ -9,35 +9,6 @@ import cv2
 
 from scipy import signal
 
-def fig2data(fig):
-    """
-    @brief Convert a Matplotlib figure to a 3D numpy array with RGB channels and return it
-    @param fig a matplotlib figure
-    @return a numpy 3D array of RGB values
-    """
-    # draw the renderer
-    fig.canvas.draw()
- 
-    # Get the RGBA buffer from the figure
-    w,h = fig.canvas.get_width_height()
-    buf = np.fromstring(fig.canvas.tostring_rgb(), dtype=np.uint8)
-    buf.shape = (w, h, 3)
- 
-    # canvas.tostring_argb give pixmap in ARGB mode. Roll the ALPHA channel to have it in RGBA mode
-    buf = np.roll(buf, 3, axis=2)
-    return buf
-    
-def fig2img(fig):
-    """
-    @brief Convert a Matplotlib figure to a PIL Image in RGB format and return it
-    @param fig a matplotlib figure
-    @return a Python Imaging Library (PIL) image : default size (480,640,3)
-    """
-    # put the figure pixmap into a numpy array
-    buf = fig2data(fig)
-    w, h, d = buf.shape
-    return Image.frombytes("RGB", (w, h), buf.tostring())
-
 def get_LAB_L_SVD(image):
     """
     @brief Returns Singular values from LAB L Image information
@@ -130,7 +101,7 @@ def divide_in_blocks(image, block_size, pil=True):
     >>> from ipfml import image_processing
     >>> from ipfml import metrics
     >>> image_values = np.random.randint(255, size=(800, 800, 3))
-    >>> blocks = divide_img_in_blocks(image_values, (20, 20))
+    >>> blocks = divide_in_blocks(image_values, (20, 20))
     >>> len(blocks)
     1600
     >>> blocks[0].width
@@ -240,12 +211,45 @@ 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
+
+    Usage :
+    
+    >>> from PIL import Image
+    >>> from ipfml import image_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_normalized.shape
+    (200, 200)
+    """
+
+    # getting min and max value from 2D array
+    max_value = arr.max(axis=1).max()
+    min_value = arr.min(axis=1).min()
+    
+    # lambda computation to normalize
+    g = lambda x : (x - min_value) / (max_value - min_value)
+    f = np.vectorize(g)
+    
+    return f(arr)
 
-# TODO : add test to this method
 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 
+
+    Usage :
+
+    >>> from PIL import Image
+    >>> from ipfml import image_processing
+    >>> img = Image.open('./images/test_img.png')
+    >>> img_mscn = image_processing.rgb_to_mscn(img)
+    >>> img_mscn.shape
+    (200, 200)
     """
 
     # check if PIL image or not
@@ -264,11 +268,19 @@ def rgb_to_mscn(image):
 
     return structdis
 
-# TODO : add test to this method...
 def rgb_to_grey_low_bits(image, bind=15):
     """
     @brief Convert RGB Image into grey image using only 4 low bits values
     @param 3D RGB image numpy array or PIL RGB image 
+
+    Usage :
+
+    >>> from PIL import Image
+    >>> from ipfml import image_processing
+    >>> img = Image.open('./images/test_img.png')
+    >>> low_bits_grey_img = image_processing.rgb_to_grey_low_bits(img)
+    >>> low_bits_grey_img.shape
+    (200, 200)
     """
 
     img_arr = np.array(image)
@@ -341,23 +353,6 @@ def segment_relation_in_block(block, active_block):
 
     return beta
 
-def normalize_2D_arr(arr):
-    """
-    @brief Return array normalize from its min and max values
-    @param 2D numpy array
-    """
-
-    # getting min and max value from 2D array
-    max_value = arr.max(axis=1).max()
-    min_value = arr.min(axis=1).min()
-    
-    # lambda computation to normalize
-    g = lambda x : (x - min_value) / (max_value - min_value)
-    f = np.vectorize(g)
-    
-    return f(arr)
-
-
 ### other way to compute MSCN :
 # TODO : Temp code, check to remove or use it
 

+ 9 - 0
ipfml/metrics.py

@@ -274,6 +274,15 @@ def get_low_bits_img(image, bind=15):
     @param image to convert
     @bind optional : bits to keep using & Bitwise operator
     @return Numpy array with reduced values
+
+    Usage :
+
+    >>> 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.shape
+    (200, 200, 3)
     """
     
     img_arr = np.array(image)

+ 0 - 59
ipfml/tf_model_helper.py

@@ -1,59 +0,0 @@
-# module filewhich contains helpful display function
-
-# avoid tk issue
-import matplotlib
-#matplotlib.use('agg')
-import matplotlib.pyplot as plt
-
-def save(history, filename):
-    '''
-    @brief Function which saves data from neural network model
-    @param history : tensorflow model history
-    @param filename : information about model filename
-    @return nothing
-    '''
-    # summarize history for accuracy
-    plt.plot(history.history['acc'])
-    plt.plot(history.history['val_acc'])
-    plt.title('model accuracy')
-    plt.ylabel('accuracy')
-    plt.xlabel('epoch')
-    plt.legend(['train', 'test'], loc='upper left')
-    plt.savefig(str('%s_accuracy.png' % filename))
-
-    # clear plt history
-    plt.gcf().clear()
-
-    # summarize history for loss
-    plt.plot(history.history['loss'])
-    plt.plot(history.history['val_loss'])
-    plt.title('model loss')
-    plt.ylabel('loss')
-    plt.xlabel('epoch')
-    plt.legend(['train', 'test'], loc='upper left')
-    plt.savefig(str('%s_loss.png' % filename))
-
-def show(history, filename):
-    '''
-    @brief Function which shows data from neural network model
-    @param history : tensorflow model history
-    @param filename : information about model filename
-    @return nothing
-    '''
-    # summarize history for accuracy
-    plt.plot(history.history['acc'])
-    plt.plot(history.history['val_acc'])
-    plt.title('model accuracy')
-    plt.ylabel('accuracy')
-    plt.xlabel('epoch')
-    plt.legend(['train', 'test'], loc='upper left')
-    plt.show()
-
-    # summarize history for loss
-    plt.plot(history.history['loss'])
-    plt.plot(history.history['val_loss'])
-    plt.title('model loss')
-    plt.ylabel('loss')
-    plt.xlabel('epoch')
-    plt.legend(['train', 'test'], loc='upper left')
-    plt.show()

+ 0 - 2
setup.py

@@ -14,11 +14,9 @@ class BuildTestCommand(setuptools.command.build_py.build_py):
     import doctest
     from ipfml import image_processing
     from ipfml import metrics
-    from ipfml import tf_model_helper
 
     doctest.testmod(image_processing)
     doctest.testmod(metrics)
-    doctest.testmod(tf_model_helper)
 
     setuptools.command.build_py.build_py.run(self)