Jungletronics
Published in

Jungletronics

Hi Python Computer Vision— PIL!

An Intro To Python Imaging Library #PyVisionSeries — Episode #00

print(‘Hello Python Computer Vision!’)Hello Python Computer Vision!
import numpy as np
import matplotlib.pyplot as ptl
%matplotlib inline
from PIL import Image
pic = Image.open(‘00_puppy.jpg’)
type(pic)PIL.JpegImagePlugin.JpegImageFile
pic_arr = np.asarray(pic)type(pic_arr)numpy.ndarray
pic_arr.shape(551, 789, 3)
ptl.imshow(pic_arr)
Fig 1. Note that when transforming into a NumPy array, we map the image automatically. Now each pixel is on our command! Perfect!
Fig 2. From Art Silkscreen Stock Illustrations — 546 Art Silkscreen Stock Illustrations, Vectors & Clipart — Dreamstime
pic_copy = pic_arr.copy()
# *R G B
# RED CHANNEL VALUES (0–255)
ptl.imshow(pic_copy[:,:,0], cmap=’gray’)
Fig 3. We are just mapping the image to show gray. If you were using screen printing techniques (silkscreen) you would probably use this filtered image to apply the red color (see that in carrots, the red color will be used a lot…)
# R *G B
# GREEN CHANNEL VALUES(0–255)
ptl.imshow(pic_copy[:,:,1], cmap=’gray’)
Fig 4. See that the green is painted on the grass, with a little more intensity on the puppy’s hind legs …
# R G *B
# BLUE CHANNEL VALUES(0–255)
ptl.imshow(pic_copy[:,:,2], cmap=’gray’)
Fig 5. We painted the entire iron structure behind the puppy in pure blue
# Got rid of Green Channel
pic_copy[:,:,1] = 0
ptl.imshow(pic_copy)
Fig 6. Two colors predominate here: red and blue; the green vanished!
# Got rid of Blue Channel
pic_copy[:,:,2] = 0
ptl.imshow(pic_copy)
Fig 7. Now only the red color.
ic_copy.shape
# Look!
pic_copy
(551, 789, 3)
print(“That’s it! Python support for opening, manipulating, and saving many different image file formats. See you in the next PyVisionSeries Episode!”)That's it! Python support for opening, manipulating, and saving many different image file formats. See you in the next PyVisionSeries Episode!
Fig 8. Please, let’s protect the Amazon Rain Forest for future generations! This is a paradise in terms of biodiversity! I lived in Rondonia, and you can clearly see the destructive trail of highway BR-364 (center-left)…

Credits & References:

Jose Portilla — Python for Computer Vision with OpenCV and Deep Learning — Learn the latest techniques in computer vision with Python, OpenCV, and Deep Learning!

Posts Related:

00 Episode#Hi Python Computer Vision — PIL! — An Intro To Python Imaging Library #PyVisionSeries

--

--

J of Jungle + 3 Plats Arduino/RPi/Pic = J3

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
J3

Hi, Guys o/ I am J3! I am just a hobby-dev, playing around with Python, Django, Lego, Arduino, Raspy, PIC, AI… Welcome! Join us!