ipfml.processing¶
Functions to quickly extract reduced information from image
Functions
divide_in_blocks (image, block_size[, pil]) |
Divide image into equal size blocks |
fusion_images (images[, pil]) |
Fusion array of images into single image |
get_LAB_L_SVD (image) |
Returns Singular values from LAB L Image information |
get_LAB_L_SVD_U (image) |
Returns U SVD from L of LAB Image information |
get_LAB_L_SVD_V (image) |
Returns V 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_mscn_coefficients (image) |
Compute the Mean Substracted Constrast Normalized coefficients of an image |
rgb_to_LAB_L_bits (image, interval) |
Returns only bits from LAB L canal specified into the interval |
rgb_to_LAB_L_low_bits (image[, nb_bits]) |
Convert RGB Image into Lab L channel image using only 4 low bits values |
rgb_to_grey_low_bits (image[, nb_bits]) |
Convert RGB Image into grey image using only 4 low bits values |
rgb_to_mscn (image) |
Convert RGB Image into Mean Subtracted Contrast Normalized (MSCN) |
rotate_image (image[, angle, pil]) |
Rotate image using specific angle |
-
ipfml.processing.
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 import processing >>> from ipfml import metrics >>> image_values = np.random.randint(255, size=(800, 800, 3)) >>> blocks = 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 = metrics.get_LAB_L(img_l) >>> blocks_L = divide_in_blocks(L, (100, 100)) >>> len(blocks_L) 4 >>> blocks_L[0].width 100
-
ipfml.processing.
fusion_images
(images, pil=True)[source]¶ Fusion array of images into single image
Parameters: - images – array of images (PIL Image or Numpy array)
- pil – block type returned as PIL Image (default True)
Returns: merged image from array of images
Raises: ValueError
– if images is not an array or is emptyNumpyShapeComparisonException
– if images array contains images with different shapes
Example:
>>> import numpy as np >>> from ipfml import processing >>> image_values_1 = np.random.randint(255, size=(800, 800, 3)) >>> image_values_2 = np.random.randint(255, size=(800, 800, 3)) >>> merged_image = processing.fusion_images([image_values_1, image_values_2], pil=False) >>> merged_image.shape (800, 800, 3)
-
ipfml.processing.
get_LAB_L_SVD
(image)[source]¶ Returns Singular values from LAB L Image information
Parameters: image – PIL Image or Numpy array Returns: U, s, V information obtained from SVD compression using Lab Example:
>>> from PIL import Image >>> from ipfml import processing >>> img = Image.open('./images/test_img.png') >>> U, s, V = processing.get_LAB_L_SVD(img) >>> U.shape (200, 200) >>> len(s) 200 >>> V.shape (200, 200)
-
ipfml.processing.
get_LAB_L_SVD_U
(image)[source]¶ Returns U SVD from L of LAB Image information
Parameters: image – PIL Image or Numpy array Returns: U matrix of SVD compression Example:
>>> from PIL import Image >>> from ipfml import processing >>> img = Image.open('./images/test_img.png') >>> U = processing.get_LAB_L_SVD_U(img) >>> U.shape (200, 200)
-
ipfml.processing.
get_LAB_L_SVD_V
(image)[source]¶ Returns V SVD from L of LAB Image information
Parameters: image – PIL Image or Numpy array Returns: V matrix of SVD compression Example:
>>> from PIL import Image >>> from ipfml import processing >>> img = Image.open('./images/test_img.png') >>> V = processing.get_LAB_L_SVD_V(img) >>> V.shape (200, 200)
-
ipfml.processing.
get_LAB_L_SVD_s
(image)[source]¶ Returns s (Singular values) SVD from L of LAB Image information
Parameters: image – PIL Image or Numpy array Returns: vector of singular values Example:
>>> from PIL import Image >>> from ipfml import processing >>> img = Image.open('./images/test_img.png') >>> s = processing.get_LAB_L_SVD_s(img) >>> len(s) 200
-
ipfml.processing.
get_mscn_coefficients
(image)[source]¶ Compute the Mean Substracted Constrast Normalized coefficients of an image
Parameters: image – PIL Image, Numpy array or path of image
Returns: MSCN coefficients
Raises: FileNotFoundError
– If image is set as str path and image was not foundValueError
– If image numpy shape are not correct
Example:
>>> from PIL import Image >>> import numpy as np >>> from ipfml import processing >>> image_values = Image.open('./images/test_img.png') >>> mscn_coefficients = processing.get_mscn_coefficients(image_values) >>> mscn_coefficients.shape (200, 200)
-
ipfml.processing.
rgb_to_LAB_L_bits
(image, interval)[source]¶ Returns only bits from LAB L canal specified into the interval
Parameters: - image – image to convert using this interval of bits value to keep
- interval – (begin, end) of bits values
Returns: 2D Numpy array with reduced values
>>> from PIL import Image >>> from ipfml import processing >>> img = Image.open('./images/test_img.png') >>> bits_Lab_l_img = processing.rgb_to_LAB_L_bits(img, (2, 6)) >>> bits_Lab_l_img.shape (200, 200)
-
ipfml.processing.
rgb_to_LAB_L_low_bits
(image, nb_bits=4)[source]¶ Convert RGB Image into Lab L channel image using only 4 low bits values
Parameters: - image – 3D RGB image Numpy array or PIL RGB image
- nb_bits – optional parameter which indicates the number of bits to keep (default 4)
Returns: 2D Numpy array with low bits information kept
Example:
>>> from PIL import Image >>> from ipfml import processing >>> img = Image.open('./images/test_img.png') >>> low_bits_Lab_l_img = processing.rgb_to_LAB_L_low_bits(img, 5) >>> low_bits_Lab_l_img.shape (200, 200)
-
ipfml.processing.
rgb_to_grey_low_bits
(image, nb_bits=4)[source]¶ Convert RGB Image into grey image using only 4 low bits values
Parameters: - image – 3D RGB image Numpy array or PIL RGB image
- nb_bits – optional parameter which indicates the number of bits to keep (default 4)
Returns: 2D Numpy array with low bits information kept
Example:
>>> from PIL import Image >>> from ipfml import processing >>> img = Image.open('./images/test_img.png') >>> low_bits_grey_img = processing.rgb_to_grey_low_bits(img, 5) >>> low_bits_grey_img.shape (200, 200)
-
ipfml.processing.
rgb_to_mscn
(image)[source]¶ Convert RGB Image into Mean Subtracted Contrast Normalized (MSCN)
Parameters: image – 3D RGB image Numpy array or PIL RGB image Returns: 2D Numpy array with MSCN information Example:
>>> from PIL import Image >>> from ipfml import processing >>> img = Image.open('./images/test_img.png') >>> img_mscn = processing.rgb_to_mscn(img) >>> img_mscn.shape (200, 200)
-
ipfml.processing.
rotate_image
(image, angle=90, pil=True)[source]¶ Rotate image using specific angle
Parameters: - image – PIL Image or Numpy array
- angle – Angle value of the rotation
- pil – block type returned as PIL Image (default True)
Returns: Image with rotation applied
Example:
>>> from PIL import Image >>> import numpy as np >>> from ipfml import processing >>> image_values = Image.open('./images/test_img.png') >>> rotated_image = processing.rotate_image(image_values, 90, pil=False) >>> rotated_image.shape (200, 200, 3)