ipfml.processing.segmentation¶
All segmentation methods applied on images
Functions
divide_in_blocks (image, block_size[, pil]) |
Divide image into equal size blocks |
-
ipfml.processing.segmentation.
divide_in_blocks
(image, block_size, pil=True)[source]¶ Divide image into equal size blocks
Parameters: - image – PIL Image or Numpy array
- block – tuple (width, height) representing the size of each dimension of the block
- pil – block type returned as PIL Image (default True)
Returns: list containing all 2D Numpy blocks (in RGB or not)
Raises: ValueError
– If image_width or image_height are not compatible to produce correct block sizesExample:
>>> import numpy as np >>> from PIL import Image >>> from ipfml.processing import transform, segmentation >>> image_values = np.random.randint(255, size=(800, 800, 3)) >>> blocks = segmentation.divide_in_blocks(image_values, (20, 20)) >>> len(blocks) 1600 >>> blocks[0].width 20 >>> blocks[0].height 20 >>> img_l = Image.open('./images/test_img.png') >>> L = transform.get_LAB_L(img_l) >>> blocks_L = segmentation.divide_in_blocks(L, (100, 100)) >>> len(blocks_L) 4 >>> blocks_L[0].width 100