Parcourir la source

Update of image_processing divide_in_block function

Jerome Buisine il y a 5 ans
Parent
commit
139508ebd7
6 fichiers modifiés avec 19 ajouts et 25 suppressions
  1. 2 3
      README.md
  2. 1 3
      README.rst
  3. 7 0
      example.py
  4. 8 9
      ipfml/image_processing.py
  5. 0 9
      main.py
  6. 1 1
      setup.py

+ 2 - 3
README.md

@@ -6,7 +6,7 @@ Image Processing For Machine Learning package.
 How to use ?
 ------------
 
-To use, simply do::
+To use, simply do :
 
 ```python
 from PIL import Image
@@ -15,7 +15,6 @@ img = Image.open('path/to/image.png')
 s = image_processing.get_LAB_L_SVD_s(img)
 ```
 
-
 Modules
 -------
 
@@ -27,7 +26,7 @@ This project contains modules.
     - 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
+    - divide_in_blocks(image, block_size): *Divide image into equal size blocks*
 
 - **metrics** : *Metrics computation of PIL image*
     - get_SVD(image): *Transforms PIL Image into SVD*

+ 1 - 3
README.rst

@@ -6,7 +6,7 @@ Image Processing For Machine Learning package.
 How to use ?
 ------------
 
-To use, simply do::
+To use, simply do :
 
     >>> from PIL import Image
     >>> from ipfml import image_processing
@@ -32,12 +32,10 @@ This project contains modules.
     - 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*

+ 7 - 0
example.py

@@ -0,0 +1,7 @@
+from PIL import Image
+from ipfml import image_processing
+
+path = './images/test_img.png'
+img = Image.open(path)
+blocks = image_processing.divide_in_blocks(img, (10, 10))
+print(len(blocks))

+ 8 - 9
ipfml/image_processing.py

@@ -144,19 +144,18 @@ def divide_in_blocks(image, block_size):
     blocks = []
     mode = 'RGB'
 
-    # check input type (PIL Image or numpy array)
-    if type(image) is Image:
+    # check input type (PIL Image or numpy array) and convert it if necessary
+    if hasattr(image, 'filename'):
         image_array = np.array(image)
-        image_width = image.width
-        image_height = image.height
     else:
         image_array = image
 
-        if image.ndim != 3:
-            mode = 'L'
-            image_width, image_height = image.shape
-        else:
-            image_width, image_height, _ = image.shape
+    # check dimension of input image
+    if image_array.ndim != 3:
+        mode = 'L'
+        image_width, image_height = image_array.shape
+    else:
+        image_width, image_height, _ = image_array.shape
         
     # check size compatibility
     width, height = block_size

+ 0 - 9
main.py

@@ -1,9 +0,0 @@
-from PIL import Image
-from ipfml import image_processing
-
-path = '/home/jbuisine/Documents/Thesis/Development/NoiseDetection/img_train/final/appartAopt_00850.png'
-img = Image.open(path)
-blocks = image_processing.divide_in_blocks(img, (80, 80))
-print(len(blocks))
-
-blocks[60].show()

+ 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.7',
+      version='0.0.8',
       description='Image Processing For Machine Learning',
       long_description=readme(),
       classifiers=[