Image Processing

Image processing algorithms are used to perform functions such as image analysis, image editing, and computer vision.

Python Example

To download the code below, click here.

"""
image_processing_with_python.py
demonstrates selected PIL capabilities
an input test_image.jpg stored on the computer is required
"""

# Import image processing functions.
# PIL documentation can be found here: http://effbot.org/imagingbook/
from PIL import Image, ImageFilter

# Set parameters.
input_image_file = 'test_image.jpg'
image_sharpened_file = 'test_image_sharpened.jpg'
image_blurred_file = 'test_image_blurred.jpg'
file_type = 'JPEG'
image_blur_radius = 5

# Read the input image.
input_image = Image.open(input_image_file)

# Display the image.
input_image.show()

# Apply a convolution sharpening filter to the image.
# A descripiton of convolution matrices can be found here:
# https://en.wikipedia.org/wiki/Kernel_(image_processing)
input_image_sharpened = input_image.filter(ImageFilter.SHARPEN)

# Save the sharpened image.
input_image_sharpened.save(image_sharpened_file, file_type)

# Display the sharpened image.
input_image_sharpened.show()

# Apply a Gaussian blur filter to the image.
# A descriptioin of Gaussian blur can be found here:
# https://en.wikipedia.org/wiki/Gaussian_blur
input_image_blurred = input_image.filter(ImageFilter.GaussianBlur(radius=image_blur_radius))

# Save the blurred image.
input_image_blurred.save(image_blurred_file, file_type)

# Display the blurred image.
input_image_blurred.show()

# Split the image into red, green, blue.
# A description of the RGB color space can be found here:
# https://en.wikipedia.org/wiki/Color_spaces_with_RGB_primaries
red, green, blue = input_image.split()

# Display the color split black and white images.
red.show()
green.show()
blue.show()

# Display the EXIF (Exchangeable image file format) data embedded in the image.
# A description of Exif data can be found here:
# https://en.wikipedia.org/wiki/Exif
exif_data = input_image._getexif()
print(exif_data)

Output is below:

Image Exif Data

{36864: '0231', 37121: '\x01\x02\x03\x00', 40962: 4032, 40963: 3024, 36868: u'2020:04:18 14:44:07', 40965: 21521, 37382: (2459, 1000), 37383: 2, 41992: 0, 37385: 16, 41994: 0, 41996: 2, 41986: 0, 256: 3024, 271: u'Google', 37520: u'679742', 36881: u'-07:00', 37522: u'679742', 41987: 0, 41495: 2, 37380: (0, 6), 33434: (213, 1000000), 283: (72, 1), 33437: (173, 100), 41988: (0, 1), 41989: 27, 34850: 2, 40961: 1, 41990: 0, 34855: 62, 296: 2, 37381: (158, 100), 305: u'Google', 306: u'2020:04:19 14:07:52', 37377: (1220, 100), 41993: 0, 41729: '\x01', 37386: (4380, 1000), 41985: 1, 40960: '0100', 36882: u'-07:00', 282: (72, 1), 37378: (158, 100), 257: 4032, 34853: {0: '\x02\x02\x00\x00', 1: u'N', 2: ((37, 1), (47, 1), (4809, 100)), 3: u'W', 4: ((122, 1), (24, 1), (1911, 100)), 5: '\x01', 6: (1719, 100), 7: ((21, 1), (43, 1), (57, 1)), 11: (50424, 1000), 27: 'ASCII\x00\x00\x00fused', 29: u'2020:04:18'}, 36867: u'2020:04:18 14:44:07', 36880: u'-07:00', 37521: u'679742', 34665: 231, 274: 1, 272: u'Pixel 4 XL', 37379: (947, 100), 531: 1, 37500: 'HDRP\x02\xefd5m^p\x1e,\xea\xe3LWV\x88Y\xd7\xca,o\x87\xf1\xe4\xe5\xdf<\xbb5\x87w\x9aGf\xe0\x10\xe0\xba\xfb\xb6p\xd9\xa9\xbf\x1ea\xfe6[Nd!b\xa5\xd9\xbb\xfe\xfb7 \xba\xbb\xdb\xc2\xf2-((w\xa4Bq[\x97\xcen\xf4\x81\xd2\x1d\x83y\xc5\xe3\xf0\xabD\\r\xe50/\xf1qH\xed\x14\xb8\x8d\x18r\xd7\x9e5v\x9f\xf4\xb0\x99\x17\xf1\xfe\x12\xce\x017\xf7\x15\x14\x10vI)ER\xf3\xb8\x12\xdc-\x9b\x10\x95\x11\xbd \xb8K\xaa"r\x94^\xf9\xaa\xb9\x91WT\x89\xc2\xee\xb6bp\xc9(\xe4c\x08$\x04\x07g\x91[\xbcR\xe73\xf9?\x1dL*\x91=we\xbd4Zo\xc0j\x8d\xe1\xe6\x0c\xa2|\\\x8f\x94 \xc4b\xf2\xbf;!G\xb5^`m\xd1\xd5Z\xcf\x9b\'G/\xf9\xbf\x84\x87 \xd0\x0e\xbf\xcb\x10\xff&\x1c\x07\ .......


Original Input Image


Sharpened Image

Blurred Image


Red Split Image - dark is less red, light is more red

Green Split Image - dark is less green, light is more green

Blue Split Image - dark is blue red, light is more blue