(Ebook) Raspberry Pi Image Processing Programming: Develop Real-Life Examples with Python, Pillow, and SciPy by Ashwin Pajankar ISBN 9781484227305, 1484227301 all chapter instant download
(Ebook) Raspberry Pi Image Processing Programming: Develop Real-Life Examples with Python, Pillow, and SciPy by Ashwin Pajankar ISBN 9781484227305, 1484227301 all chapter instant download
com
OR CLICK HERE
DOWLOAD EBOOK
ebooknice.com
ebooknice.com
ebooknice.com
(Ebook) Raspberry PI Computer Vision Programming by
Pajankar, Ashwin ISBN 9781784398286, 1784398284
https://ebooknice.com/product/raspberry-pi-computer-vision-
programming-55322632
ebooknice.com
https://ebooknice.com/product/instant-raspberry-pi-the-beginner-s-
guide-to-raspberry-pi-setup-47486426
ebooknice.com
https://ebooknice.com/product/practical-linux-with-raspberry-pi-os-
quick-start-34608638
ebooknice.com
https://ebooknice.com/product/raspberry-pi-by-example-55322468
ebooknice.com
https://ebooknice.com/product/learn-raspberry-pi-programming-with-
python-54981222
ebooknice.com
TECHNOLOGY IN AC TION™
Raspberry Pi
Image Processing
Programming
Develop Real-Life Examples with
Python, Pillow, and SciPy
—
Ashwin Pajankar
Raspberry Pi
Image Processing
Programming
Develop Real-Life Examples with
Python, Pillow, and SciPy
Ashwin Pajankar
Raspberry Pi Image Processing Programming: Develop Real-Life Examples with Python,
Pillow, and SciPy
Ashwin Pajankar
Nashik, Maharashtra, India
ISBN-13 (pbk): 978-1-4842-2730-5 ISBN-13 (electronic): 978-1-4842-2731-2
DOI 10.1007/978-1-4842-2731-2
Library of Congress Control Number: 2017936370
Copyright © 2017 by Ashwin Pajankar
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part
of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations,
recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission
or information storage and retrieval, electronic adaptation, computer software, or by similar or
dissimilar methodology now known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol
with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only
in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of
the trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are
not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject
to proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of
publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for
any errors or omissions that may be made. The publisher makes no warranty, express or implied, with
respect to the material contained herein.
Managing Director: Welmoed Spahr
Lead Editor: Celestin Suresh John
Technical Reviewer: Lentin Joseph
Editorial Board: Steve Anglin, Pramila Balan, Laura Berendson, Aaron Black,
Louise Corrigan, Jonathan Gennick, Robert Hutchinson, Celestin Suresh John,
Nikhil Karkal, James Markham, Susan McDermott, Matthew Moodie, Natalie Pao,
Gwenan Spearing
Coordinating Editor: Sanchita Mandal
Copy Editor: Kezia Endsley
Compositor: SPi Global
Indexer: SPi Global
Artist: SPi Global
Distributed to the book trade worldwide by Springer Science+Business Media New York,
233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505,
e-mail [email protected], or visit www.springeronline.com. Apress Media, LLC is a
California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc
(SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.
For information on translations, please e-mail [email protected], or visit www.apress.com.
Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional
use. eBook versions and licenses are also available for most titles. For more information, reference
our Special Bulk Sales–eBook Licensing web page at www.apress.com/bulk-sales.
Any source code or other supplementary materials referenced by the author in this text are
available to readers at www.apress.com. For detailed information about how to locate your book’s
source code, go to www.apress.com/source-code/. Readers can also access source code at
SpringerLink in the Supplementary Material section for each chapter.
Index���������������������������������������������������������������������������������������������� 123
iii
Contents
v
■ Contents
vi
■ Contents
Python 3������������������������������������������������������������������������������������������������ 29
The Differences Between Python 2 and Python 3�������������������������������������������������� 30
Why Use Python 3��������������������������������������������������������������������������������������������������� 31
Conclusion��������������������������������������������������������������������������������������������� 39
■
■Chapter 3: Getting Started������������������������������������������������������������ 41
Image Sources�������������������������������������������������������������������������������������� 41
Using the Webcam�������������������������������������������������������������������������������������������������� 42
The Pi Camera Module�������������������������������������������������������������������������������������������� 44
Using Python 3 for Digital Image Processing���������������������������������������� 46
Working with Images���������������������������������������������������������������������������������������������� 47
Conclusion��������������������������������������������������������������������������������������������� 50
■
■Chapter 4: Basic Operations on Images��������������������������������������� 51
Image Module���������������������������������������������������������������������������������������� 51
Splitting and Merging Image Channels������������������������������������������������������������������� 51
Image Mode Conversion����������������������������������������������������������������������������������������� 53
Image Blending������������������������������������������������������������������������������������������������������� 53
Resizing an Image�������������������������������������������������������������������������������������������������� 55
vii
■ Contents
Rotating an Image�������������������������������������������������������������������������������������������������� 56
Crop and Paste Operations������������������������������������������������������������������������������������� 57
Copying and Saving Images to a File���������������������������������������������������������������������� 58
Knowing the Value of a Particular Pixel������������������������������������������������������������������ 58
ImageChops Module������������������������������������������������������������������������������ 59
ImageOps Module��������������������������������������������������������������������������������� 61
Conclusion��������������������������������������������������������������������������������������������� 63
■
■Chapter 5: Advanced Operations on Images�������������������������������� 65
The ImageFilter Module������������������������������������������������������������������������ 65
The ImageEnhance Module������������������������������������������������������������������� 74
Color Quantization��������������������������������������������������������������������������������� 76
Histograms and Equalization����������������������������������������������������������������� 77
Histogram Equalization������������������������������������������������������������������������������������������� 78
Conclusion��������������������������������������������������������������������������������������������� 79
■
■Chapter 6: Introduction to Scientific Python�������������������������������� 81
The Scientific Python Stack������������������������������������������������������������������ 81
Installing the SciPy Stack��������������������������������������������������������������������������������������� 82
A Simple Program��������������������������������������������������������������������������������������������������� 82
Simple Image Processing��������������������������������������������������������������������������������������� 83
Introduction to NumPy�������������������������������������������������������������������������������������������� 84
Matplotlib���������������������������������������������������������������������������������������������������������������� 86
Image Channels������������������������������������������������������������������������������������� 89
Conversion Between PIL Image Objects
and NumPy ndarrays����������������������������������������������������������������������������� 91
Conclusion��������������������������������������������������������������������������������������������� 92
viii
■ Contents
■
■Chapter 7: Transformations and Measurements�������������������������� 93
Transformations������������������������������������������������������������������������������������ 93
Measurements�������������������������������������������������������������������������������������� 95
Conclusion��������������������������������������������������������������������������������������������� 98
■
■Chapter 8: Filters and Their Application��������������������������������������� 99
Filters���������������������������������������������������������������������������������������������������� 99
Low-Pass Filters��������������������������������������������������������������������������������������������������� 100
High-Pass Filters�������������������������������������������������������������������������������������������������� 105
Fourier Filters������������������������������������������������������������������������������������������������������� 108
Conclusion������������������������������������������������������������������������������������������� 110
■
■Chapter 9: Morphology, Thresholding, and Segmentation���������� 111
Distance Transforms���������������������������������������������������������������������������� 111
Morphology and Morphological Operations����������������������������������������� 113
Structuring Element���������������������������������������������������������������������������������������������� 113
Various Morphological Operations������������������������������������������������������������������������ 113
Grayscale Morphological Operations�������������������������������������������������������������������� 115
Index���������������������������������������������������������������������������������������������� 123
ix
About the Author
xi
About the Technical
Reviewer
xiii
■ About the Technical Reviewer
He also reviewed one book about the Robot Operating System called Effective
Robotics Programming Using ROS (https://www.packtpub.com/hardware-and-
creative/effective-robotics-programming-ros-third-edition).
Lentin and his team were also winners of the HRATC 2016 challenge conducted
as part of ICRA 2016. He was also a finalist in the ICRA 2015 challenge, HRATC
(see http://www.icra2016.org/conference/challenges/).
xiv
Acknowledgments
Writing a book is a journey that I am glad I undertook. First, I want to thank my wife
Kavitha, without whose support the journey would never have been possible. The journey
spanned a few months but the experience will last a lifetime. I had my wife Kavitha with
me onboard this journey and I wish to express my deepest gratitude to her. Without her
unwavering support and affection, I couldn’t have pulled it off.
I am grateful to the community of professionals, students, trainers, and teachers
who, with their continual bombardment of queries, impelled me to learn more, simplify
my knowledge and findings, and place it neatly in the book. This book is for all of them.
I want to thank my friends and colleagues—the practitioners from the industry and
experts from academia—for their good counsel and filling me in with the knowledge
on the latest in the fields of single board computers, computer vision, digital image
processing, and Python.
I want to thank the technical reviewer for his vigilant reviews, suggestions,
corrections, and expert opinion.
I consider myself very fortunate for the editorial assistance provided by Apress
Media. This is my second book with Apress and collaborating with them on both the
books has been fabulous. I am thankful to Celestin Suresh John, Senior Manager, Editorial
Acquisition, Apress and Springer Science and Business Media Company, for giving me a
long-desired opportunity to collaborate and write for Apress. I also want to acknowledge
Sanchita Mandal, coordinating editor, Anila Vincent, development editor, and the team
of associates from Apress Media who adeptly guided me through the entire process of
preparation and publication.
xv
Introduction
xvii
■ Introduction
xviii
■ Introduction
Where Next?
I endeavored to unleash the power of digital image processing libraries for Python 3 as an
aid to the Raspberry Pi community. I recommend you read the book from cover to cover
without skipping any of the chapters, text, code examples, or exercises.
I wish you well in exploring Python and Raspberry Pi!
xix
CHAPTER 1
Introduction to Single
Board Computers and
Raspberry Pi
We will start this exciting journey exploring the scientific domain of digital image
processing with Raspberry Pi. To begin the journey, you must be comfortable with the
basics of single board computers (SBCs) and with Raspberry Pi. This chapter discusses
the definition, history, and philosophy behind SBCs. It compares SBCs to regular
computers. Then it moves toward the most popular and best selling SBC of all time, the
Raspberry Pi. By the end of this chapter, you will have adequate knowledge to set up your
own Raspberry Pi independently. This chapter aims to make you comfortable with the
basic concepts of SBCs and Raspberry Pi setup.
2
Chapter 1 ■ Introduction to Single Board Computers and Raspberry Pi
History of SBCs
Dyna-Micro was the first true SBC. It was based on the Intel C8080A and used Intel’s first
EPROM, the C1702A. The Dyna-Micro was rebranded and marketed by E&L Instruments
of Derby, CT in 1976 as the MMD-1 (Mini-Micro Designer 1). It became famous as
the leading example of microcomputers. SBCs were very popular in the earlier days of
computing, as many home computers were actually SBCs. However, with the rise of PCs,
the popularity of SBCs declined. Since 2010, there has been a resurgence in the popularity
of SBCs due to their lower production costs.
Apart from the MMD-1, here are a few other popular historical SBCs:
• The BBC Micro was built around an MOS technology 6502A
processor running at 2MHz.
• The Ferguson Big Board II was a Zilog Z80-based computer
running at 4MHz.
• The Nascom was another Zilog Z80-based computer.
SBC Families
Based on the manufacturers and designers, the SBCs are grouped into families, models,
and generations. Here are a few popular SBC families:
• Raspberry Pi by the Raspberry Pi Foundation
• Banana Pi and Banana Pro
• Intel Edison and Galileo
• CubieBoard
• BeagleBone and BeagleBoard
3
Chapter 1 ■ Introduction to Single Board Computers and Raspberry Pi
The Raspberry Pi
The Raspberry Pi is a family of credit card-sized SBCs developed in the United
Kingdom by the Raspberry Pi Foundation. The Raspberry Pi Foundation formed
in 2009. The aim behind developing Raspberry Pi was to promote the teaching of
basic computer science in schools and developing countries by providing a low-cost
computing platform.
Raspberry Pi Foundation’s Raspberry Pi was released in 2012. It was a massive
hit and sold over two million units in two years. Subsequently, the Raspberry Pi
Foundation revised versions of the Raspberry Pi. They also released other accessories
for the Pi.
You can find more information about the Raspberry Pi foundation on the Raspberry
Pi Foundation’s web site at https://www.raspberrypi.org.
The product page for Raspberry Pi's current production models and other
accessories is at https://www.raspberrypi.org/products.
I have written, executed, and tested all the code examples in this book on Raspberry
Pi Models B+, 2B, and 3B. Raspberry Pi 3 Model B (also known as 3B) is the most recent
model of Raspberry Pi. Table 1-2 lists the specifications of the Raspberry Pi 3, Model B.
Figure 1-1 shows the top view of Raspberry Pi 3 Model B. The components relevant
to this book are labeled in the image.
4
Chapter 1 ■ Introduction to Single Board Computers and Raspberry Pi
You can get more Information on Raspberry Pi 3 Model B by visiting the product
page at https://www.raspberrypi.org/products/raspberry-pi-3-model-b.
Raspberry Pi Setup
You have to set up Raspberry Pi before you can use it for exploration and adventure. This
section explains in detail how to set it up. As mentioned earlier, I am using Raspberry Pi 3
Model B for this setup. The setup process is exactly same for Raspberry Pi 2 Model B and
Raspberry Pi 1 Model B+. Here is the list of hardware materials to be procured for the setup.
5
Chapter 1 ■ Introduction to Single Board Computers and Raspberry Pi
Required Hardware
The following hardware is required to set up the Raspberry Pi.
Raspberry Pi
You need to use Raspberry Pi 3 Model B or Raspberry Pi 2 Model B or Raspberry Pi 1
Model B+ for the setup.
Computer
A Windows computer or laptop with an Internet connection is required. You need to use
a computer to prepare a microSD card with a Raspbian OS image for the Pi.
I/O Devices
A standard USB keyboard and a USB mouse are required.
microSD Card
A microSD card (see Figure 1-3) with at least 8GB of storage is needed. You’ll use the card
for secondary storage for the Pi. A card of Class 10 is recommended as the data transfer
speed with class 10 is great. I recommend using at least an 8GB card to be on the safe side.
Choosing a 16GB card will be adequate for most of the use cases.
6
Chapter 1 ■ Introduction to Single Board Computers and Raspberry Pi
Power Supply
For all the Raspberry Pi models, a 5V Micro USB power supply unit (PSU) is required. The
recommended current capacity of the PSU for Raspberry Pi 3 Model B is 2.5 amp. For all
the other models, a 2 amp PSU is more than enough.
You can find Raspberry Pi's official power supply (see Figure 1-4) at
https://thepihut.com/products/official-raspberry-pi-universal-power-supply.
Card Reader
You also need a card reader. Many laptops have a built-in SD card reader.
If the laptop or the card reader works with an SD card only, you need a additional
microSD-to-SD card adapter. Figure 1-5 shows a card reader and an adapter.
7
Chapter 1 ■ Introduction to Single Board Computers and Raspberry Pi
Monitor
You need an HDMI or VGA monitor.
For an HDMI monitor, you need an HDMI male-to-male cable (see Figure 1-6). It is
typically packaged with the HDMI monitor.
8
Chapter 1 ■ Introduction to Single Board Computers and Raspberry Pi
For the VGA monitor, you need a VGA cable (see Figure 1-7). This too is usually
packaged with the VGA monitor.
If you are using a VGA monitor, you need an HDMI to VGA adapter (see Figure 1-8),
because Raspberry Pi has an HDMI port only for the video output.
9
Chapter 1 ■ Introduction to Single Board Computers and Raspberry Pi
This approach allows you to access to the configuration files like /boot/config.txt
before booting. You might have to modify the configuration files in a few cases
(we will discuss that soon) before booting up the Pi. The default Raspbian image has two
partitions, called boot and system. Be sure to use at least a 16GB microSD card for the Pi
considering any possible future upgrades to the OS.
WinZip or WinRaR
You need a file extraction utility. Download WinZip (http://www.winzip.com/win/
en/index.htm) or WinRaR (http://www.win-rar.com/download.html). Install the one
you chose.
10
Chapter 1 ■ Introduction to Single Board Computers and Raspberry Pi
If you see the warning message shown in Figure 1-10, toggle the write protection
notch of the card reader or the SD card adapter (or both). Then click the Write button
again.
Figure 1-11 shows the warning message that will be displayed. Click Yes to continue.
11
Chapter 1 ■ Introduction to Single Board Computers and Raspberry Pi
Once the OS image has been written to the SD card, the message in Figure 1-12 will
be displayed. Click OK.
This means the Raspbian OS has been flashed to the microSD card.
■■Note This step is a must if you are planning to use a VGA monitor. You should skip this
step if you are using an HDMI monitor.
You need to change the contents of the config.txt file to get the Pi working with
VGA monitors. You will learn more about config.txt later in this chapter.
Insert the microSD card into the card reader again and browse it in Windows
Explorer. In Windows Explorer, it will be represented as a removable media drive
called boot.
Open the config.txt file and make the following changes to it:
• Change #disable_overscan=1 to disable_overscan=1
• Change #hdmi_force_hotplug=1 to hdmi_force_hotplug=1
• Change #hdmi_group=1 to hdmi_group=2
• Change #hdmi_mode=1 to hdmi_mode=16
• Change #hdmi_drive=2 to hdmi_drive=2
• Change #config_hdmi_boost=4 to config_hdmi_boost=4
Save the file after making these changes. The microSD card is now ready for the Pi
and for a VGA monitor.
12
Chapter 1 ■ Introduction to Single Board Computers and Raspberry Pi
Booting Up the Pi
Let's boot the Pi up with the prepared microSD card. The steps for that are as follows.
13
Chapter 1 ■ Introduction to Single Board Computers and Raspberry Pi
For all the models of Raspberry Pi with the quad-core processor, the boot screen will
resemble Figure 1-14.
Once the Pi boots up, the monitor displays the desktop, as shown in Figure 1-15.
14
Chapter 1 ■ Introduction to Single Board Computers and Raspberry Pi
Configuring the Pi
You need to configure the Pi for further use. Let’s do that.
On the desktop, there is a taskbar. In the taskbar, you’ll see the icon shown in
Figure 1-16.
Click the icon to open the LXTerminal window, as shown in Figure 1-17.
15
Chapter 1 ■ Introduction to Single Board Computers and Raspberry Pi
Then navigate to the boot options, which are highlighted in Figure 1-19.
16
Chapter 1 ■ Introduction to Single Board Computers and Raspberry Pi
In the Internationalization Options section, change the time zone and the WiFi
country (see Figure 1-21). Change the keyboard layout to US.
Once you’re done, go back to the the main screen and click Finish, as shown in
Figure 1-22.
17
Chapter 1 ■ Introduction to Single Board Computers and Raspberry Pi
It will ask if you want to reboot at this point, as shown in Figure 1-23. Choose Yes.
The Raspbian OS
An operating system is the set of basic programs and utilities that make a computer work.
It is an interface between the user and the computer. Raspbian is a free operating system
based on the popular Linux distribution, Debian. Raspbian is optimized for the Raspberry
Pi family of SBCs. It is even ported to the other similar SBCs like Banana Pro.
Raspbian has more than 35,000 packages and lots of pre-compiled software
bundled for easy installation and use on the Raspberry Pi. The first build of Raspbian
was completed in June of 2012. Raspbian is still under active development and updated
very frequently. Visit the Raspbian home page at https://www.raspbian.org and the
Raspbian documentation page at https://www.raspbian.org/RaspbianDocumentation
for more information on Raspbian.
18
Chapter 1 ■ Introduction to Single Board Computers and Raspberry Pi
Since the Raspberry Pi does not have a BIOS, the various system configuration
parameters that are normally stored and modified using the BIOS are instead stored in a
text file called config.txt.
The Raspberry Pi config.txt file is on the boot partition of the Raspberry Pi. It is
normally accessible as /boot/config.txt from Linux. However, from Windows and Mac
OS, it is seen as a file in the accessible part of the microSD card. The accessible part of the
card is labeled as boot. As you learned earlier in this chapter, you must edit the /boot/
config.txt file if you want to connect it to a VGA display.
On Raspberry Pi, you can edit this file with the following command in the
LXTerminal:
■■Note nano is a simple and easy-to-learn text-based text editor for Linux. Visit its home
page at https://www.nano-editor.org to learn more about it. I find it easier to use than
the vi or vim editors.
WiFi
Raspberry Pi 3 Model B has built-in WiFi. For all the other models of Pi, you need to use a
USB WiFi adapter.
Once the USB WiFi adapter is attached to the Pi, take a backup of the /etc/network/
interfaces file using the following command:
The original /etc/network/interfaces file is safe this way, and it can be restored if
something goes wrong.
Now create a new /etc/network/interfaces file as follows:
19
Chapter 1 ■ Introduction to Single Board Computers and Raspberry Pi
Type the lines from Listing 1-1 into that new file.
auto lo
iface lo inet loopback
auto wlan0
allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-ssid "ASHWIN"
wpa-psk "internet"
In Listing 1-1, replace ASHWIN with the SSID of your WiFi network and replace
internet with the password of your WiFi network. Save the file by pressing Ctrl+X and
then y.
Run the following command to restart the networking service:
If you followed the steps correctly, the Pi should be connected to the WiFi network
and to the Internet (provided that the WiFi network is connected to the Internet, of
course).
To verify connectivity with the Internet, use the following command:
20
Chapter 1 ■ Introduction to Single Board Computers and Raspberry Pi
To determine the IP address of Pi, use the ifconfig command. Check the output for
wlan0. It will appear as follows:
Ethernet
You can also connect the Pi to a LAN network. Based on the LAN switch’s settings, you
can allocate an IP address to the Pi statically or dynamically.
Static IP Address
If the LAN network allocates IP addresses statically, configure the /etc/network/
interfaces file as shown in Listing 1-2.
auto lo
iface lo inet loopback
auto eth0
allow-hotplug eth0
iface eth0 inet static
# Your static IP
address 192.168.0.2
# Your gateway IP
gateway 192.168.0.1
netmask 255.255.255.0
# Your network address family
network 192.168.0.0
broadcast 192.168.0.255
21
Chapter 1 ■ Introduction to Single Board Computers and Raspberry Pi
In the file shown in Listing 1-2, the parameters address, gateway, netmask, network,
and broadcast are based on the LAN’s configuration. Check the manual of the LAN
switch or router. If you are working for an organization, then check with the network
administrator for these parameters.
Dynamic IP Address
This is an easy one. If the LAN has DHCP capability, configure the /etc/network/
interfaces file as shown in Listing 1-3.
auto lo
iface lo inet loopback
auto eth0
allow-hotplug eth0
iface eth0 inet dhcp
This will configure the Pi to acquire the IP address automatically with DHCP.
■■Note All the information needed for network setup on Debian and its derivatives can be
found at https://wiki.debian.org/NetworkConfiguration.
Updating the Pi
Pi must be connected to the Internet in order to update it successfully.
22
Chapter 1 ■ Introduction to Single Board Computers and Raspberry Pi
First, update the system’s package list by entering the following command in the
LXTerminal:
apt-get update downloads the package lists from the respective remote repositories
and updates them in the local computer so that information on the newest versions of
packages and their dependencies is available for the installation and update. It should be
run before running the install or upgrade command.
Next, upgrade all the installed packages to their latest versions using this command:
apt-get dist-upgrade fetches new versions of the packages on the local machine
that are marked for upgrade. It also detects and installs any dependencies. It might also
remove obsolete packages.
Doing this regularly will keep your Raspbian OS up to date. After entering these
commands, it will take a while to update the OS, because these commands fetch the data
and the packages from remote repositories.
■■Note sudo apt-get --help will list all the options associated with apt-get.
Updating raspi-config
In raspi-config, go to the advanced options (see Figure 1-24) and choose Update.
23
Chapter 1 ■ Introduction to Single Board Computers and Raspberry Pi
Conclusion
This chapter introduced the concept and philosophy of SBCs. You also learned about a
popular family of SBCs, Raspberry Pi. Now you can confidently move ahead with further
exploration. In the next chapter, you will learn a few things about Python and digital
image processing.
24
CHAPTER 2
In the last chapter, we explored the amazing world of single board computers and
Raspberry Pi. We booted up the Raspberry Pi, connected it to the Internet, and updated
the Raspbian OS.
In this chapter, we will get started with Python and the concepts of digital image
processing (DIP).
Let’s begin this chapter with an introduction to Python. I personally find Python
amazing and have been enchanted by it. Python is a simple yet powerful programming
language. When programmers use Python, it’s easy to focus on solving a given problem
as they do not have to worry about the syntax. Python perfectly fits the philosophy of
Raspberry Pi, which is programming for everyone. That’s why it’s the most preferred
programming platform for Raspberry Pi and many other SBCs.
A History of Python
Python was designed and conceived in the late 1980s. Its actual implementation was
started in late 1989 by Guido van Rossum in Centrum Wiskunde & Informatica (National
Research Institute for Mathematics and Computer Science) in the Netherlands. Python
is a successor to the ABC Programming Language, which itself was inspired by SETL. In
February of 1991, Van Rossum publically published the Python source code to the alt.
sources newsgroup. The name Python was inspired by the British television show Monty
Python’s Flying Circus. Van Rossum is a big fan of Monty Python.
Van Rossum is the principal author of the Python programming language. He plays
a central role in guiding the direction of the development, enhancement, and further
evolution of Python programming language. He holds the title Benevolent Dictator for Life
for Python. He currently (as of February 2017) works for Dropbox and dedicates almost
half of his time toward further development of the Python programming language.
The central philosophy of the Python programming language (the Zen of Python) is
explained in PEP-20 (PEP stands for Python Enhancement Proposal), which can be found
at https://www.python.org/dev/peps/pep-0020.
Features of Python
The following are the features of Python that have made it popular and beloved in the
programming community.
Simple
Python is a simple language with a minimalist approach. Reading a well written and good
Python program makes you think you are reading English text.
26
Chapter 2 ■ Introduction to Python and Digital Image Processing
Easy to Learn
Due to its simple and English-like syntax, Python is extremely easy to learn. That is
the prime reason that it is taught as the first programming language to high school
and university students who take introductory programming courses. An entire new
generation of programmers is learning Python as their first programming language.
Easy to Read
Unlike other high-level programming languages, Python does not obfuscate the code and
make it unreadable. The English-like structure of the Python code makes it easier to read
compared to the code written in other programming languages. This makes it easier to
understand and easier to learn compared to other high-level languages like C and C++.
Easy to Maintain
As Python code is easy to read, easy to understand, and easy to learn, anyone maintaining
the code becomes comfortable with the codebase very quickly. I can vouch for this from
personal experiences of maintaining and enhancing large legacy codebases which were
written in a combination of Bash and Python 2.
Open Source
Python is an open source project, which means its source code is freely available. You
can make changes to it to suit your needs and use the original and modified code in your
applications.
High-Level Language
While writing Python programs, you do not have to manage the low-level details like
memory management, CPU timings, and scheduling processes. All these tasks are
managed by the Python interpreter. You can write the code directly in the easy-to-
understand English-like syntax.
Portable
The Python interpreter has been ported to many OS platforms. Python code is also
portable. All the Python programs will work on the supported platform without requiring
many changes if you are careful enough to avoid system-dependent coding.
You can use Python on GNU/Linux, Windows, Android, FreeBSD, Mac OS, iOS,
Solaris, OS/2, Amiga, Palm OS, QNX, VMS, AROS, AS/400, BeOS, OS/390, z/OS, Psion,
Acorn, PlayStation, Sharp Zaurus, RISC OS, VxWorks, Windows CE, and PocketPC.
27
Chapter 2 ■ Introduction to Python and Digital Image Processing
Interpreted
Python is an interpreted language. Let’s take a look at what that means. Programs written
in high-level programming languages like C, C++, and Java are compiled first. This means
that they are first converted into an intermediate format. When we run the program, this
intermediate format is loaded from secondary storage (i.e., from the hard disk) to the
memory (RAM) by the linker/loader.
So, C, C++, and Java have a separate compiler and linker/loader. This is not the case
with Python. Python runs the program directly from the source code. You do not have to
bother compiling and linking to the proper libraries. This makes Python programs truly
portable, as you can copy the program to one computer from another and the program
runs fine as long as the necessary libraries are installed on the target computer.
Object-Oriented
Python supports procedure-oriented programming as well as object-oriented
programming paradigms.
All the object-oriented programming paradigms are implemented in Python.
In the object-oriented programming languages, the program is built around objects
that combine data and the related functionality. Python is a very simple but powerful
object-oriented programming language.
Extensible
One of the features of Python is that you can call C and C++ routines from the Python
programs. If you want the core functionality of the application to run faster, you can code
that part in C/C++ and call it in the Python program (C/C++ programs generally run faster
than Python).
Extensive Libraries
Python has an extensive standard library that comes pre-installed. The standard library
has all the essential features for a modern day programming language. It has provisions
for databases, unit testing (we will explore this later in this book), regular expressions,
multi-threading, network programming, computer graphics, image processing, GUI, and
other utilities. This is the part of Python’s batteries-included philosophy.
Apart from the standard library, Python has numerous and ever-growing sets of
third-party libraries. The list of these libraries can be found on the Python Package Index.
Robust
Python provides robustness by means of the ability to handle errors. The full stack trace of
the encountered errors is available and makes the life of the programmer more bearable.
The runtime errors are known as exceptions. The feature that handles these errors is
known as an exception handling mechanism.
28
Chapter 2 ■ Introduction to Python and Digital Image Processing
Rapid Prototyping
Python is used as a rapid prototyping tool. As you learned earlier, Python has extensive
libraries and is easy to learn, which has led many software architects to use it as a tool to
rapidly prototype their ideas into working models quickly.
Memory Management
In assembly language and in programming languages like C and C++, memory
management is the responsibility of the programmer. This is in addition to the task at
hand. This creates an unnecessary burden on the programmer. In Python, the Python
interpreter takes care of the memory management. This helps the programmers steer
clear of memory issues and focus on the task at hand.
Powerful
Python has everything in it that a modern programming language needs. It is used in
applications such as computer visioning, supercomputing, drug discovery, scientific
computing, simulation, and bioinformatics. Millions of programmers around the world
use Python. Many big organizations like NASA, Google, SpaceX, and Cisco use Python for
their applications and infrastructure.
Community Support
I find this to be the most appealing feature of Python. Recall that Python is open source.
It also has community of almost a million programmers throughout the world (probably
more, as today high school kids are learning Python too). There are also plenty of forums
on the Internet to support programmers who encounter a roadblock. None of my queries
related to Python have ever gone unanswered.
Python 3
Python 3 was released in 2008. The Python development team decided to do away with
some of the redundant features of Python, simplify some more features, rectify some
design flaws, and add a few much needed features.
It was decided that a major revision number was needed for this and the resultant
release would not be backward compatible. Python 2.x and 3.x were supposed to coexist
in parallel for the programmer community to have enough time to migrate their code and
the third-party libraries from 2.x to 3.x. Python 2.x code cannot be run as-is in most cases,
as there are significant differences between 2.x and 3.x.
29
Random documents with unrelated
content Scribd suggests to you:
The Project Gutenberg eBook of The plums of
New York
This ebook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it away
or re-use it under the terms of the Project Gutenberg License
included with this ebook or online at www.gutenberg.org. If you
are not located in the United States, you will have to check the
laws of the country where you are located before using this
eBook.
Author: U. P. Hedrick
Contributor: W. H. Alderman
Maxwell Jay Dorsey
O. M. Taylor
R. Wellington
Language: English
R. WELLINGTON
O. M. TAYLOR
W. H. ALDERMAN
M. J. DORSEY
Report of the New York Agricultural Experiment Station for the Year 1910
II
ALBANY
J. B. LYON COMPANY, STATE PRINTERS
1911
PLUMS.
Of all the stone-fruits plums furnish the greatest diversity of kinds.
Varieties to the number of two thousand, from fifteen species, are
now or have been under cultivation. These varieties give a greater
range of flavor, aroma, texture, color, form and size, the qualities
which gratify the senses and make fruits desirable, than any other of
our orchard fruits. The trees, too, are diverse in structure, some of
the plums being shrub-like plants with slender branches, while
others are true trees with stout trunks and sturdy branches; some
species have thin, delicate leaves and others coarse, heavy foliage.
In geographical distribution both the wild and the cultivated plum
encircle the globe in the North Temperate Zone, and the cultivated
varieties are common inhabitants of the southern temperate region,
the various plums being adapted to great differences in temperature,
moisture and soil in the two zones.
The great variety of plums and the variability of the kinds,
seemingly plastic in all characters, the general distribution of the
fruit throughout the zone in which is carried on the greatest part of
the world’s agriculture, and the adaptation of the several species and
the many varieties, to topographical, soil and climatic changes, make
this fruit not only one of much present importance but also one of
great capacity for further development. Of the plums of the Old
World the Domesticas, Insititias and probably the Trifloras have been
cultivated for two thousand years or more, while the work of
domesticating the wild species of America was only begun in the
middle of the last century. There are about fifteen hundred varieties
of the Old World plums listed in this work, and since the New World
plums are quite as variable, as great a variety or greater, since there
are more species, may be expected in America.
An attempt is made in The Plums of New York to review the plum
flora of this continent, but the species considered fall far short of
being all of the promising indigenous plums; not only are there more
to be described, but it is probable that species here described will in
some cases be sub-divided. The development of the pomological
plum-wealth of North America is but begun. Not nearly as much has
been done to develop the possibilities of the European plums in
America as in the case of the other tree-fruits. Probably a greater
percentage of the varieties of Old World plums commonly cultivated
came from across the sea, than of the varieties of any other of the
orchard-fruits which have been introduced. Much remains to be done
in securing greater adaptability of foreign plums to American
conditions. Native and foreign plums are also being hybridized with
very great advantage to pomology.
The Plums of New York is written largely with the aim of furthering
the development of plums in America, the possibilities of which are
indicated in the preceding paragraph. With this end in view the first
task is to name and discuss briefly the characters of plums whereby
species and varieties are distinguished, with a statement, so far as
present knowledge permits, of the variability of the different
characters. It is absolutely essential that the plum-grower have
knowledge, especially if he aspires to improve the fruit by breeding,
of the characters of the plants with which he is to work. These are in
the main as follows:
All species and some horticultural varieties have more or less
characteristic trees. Making due allowance for environment—food,
moisture and light—many plum groups can be readily distinguished
by the general aspect of the plant. Of the gross characters of trees,
size is usually most characteristic. A species, for example, is either
shrubby or tree-like. Yet under varying environment, size of plant
and of the parts of the plant, are probably the first to change. Habit
of growth is nearly as important as size and varies but little under
changing conditions. A species or variety may be upright, spreading,
drooping or round-topped in growth; head open or dense; the tree
rapid or slow-growing. Hardiness is a very important diagnostic
character, plums being either hardy, half-hardy or tender. Both
species and varieties respond in high degree to the test of hardiness,
the range for varieties, of course, falling within that of the species.
Productiveness, regularity of bearing, susceptibility to diseases and
insects, and longevity of tree are all characters having value for
species and varieties and with the exception of the first named, are
little subject to variation.
The thickness, smoothness, color and manner of exfoliation of the
outer bark and the color of the inner bark have considerable value in
determining species but are little used in determining horticultural
groups. It is well recognized that all plums have lighter colored bark
in the South than in the North. The branches are very characteristic
in several species. The length, thickness and rigidity of the branch
and the length of its internodes should be considered, while the
direction of the branch, whether straight or zigzag, are very valuable
determining characters and relatively stable ones, seeming to
change for most part only through long ranges of climatic conditions.
So, too, the arming of a branch with spines or spurs and the
structure of such organs are important. The color, smoothness,
amount of pubescence, direction, length, thickness and the
appearance of the lenticels, the presence of excrescences on the
branchlets of the first and second year’s growth and the branching
angle, are all worthy of consideration though quite too much has
been made of these characters, especially of pubescence, in
determining species, for they are all extremely variable.
1. P. HORTULANA MINERI 2. P. AMERICANA 3. P. CERASIFERA
4. P. DOMESTICA 5. P. INSITITIA 6. P. HORTULANA
7. P. MUNSONIANA 8. P. NIGRA 9. P. TRIFLORA
The size, shape and color of leaf-buds and of their outer and inner
scales and the margins of the scales differ in different species.
Possibly the most evident, and therefore readiest means of
identifying species, at least, is by the leaves. It is true that leaves
are very variable but always within limits, and either individually or
collectively in giving the general aspect to a tree they are
characteristic. Modifications of leaves most often occur in very young
plants, those growing in bright sunshine or deep shade and on
sprouts or suckers, but none of these are usually sufficient to
mislead as to species. Leaf-size and leaf-form are the first characters
to be noted in determining a plum but these are closely followed in
value by leaf-color, leaf-surface, leaf-thickness and leaf-margin. Leaf-
size is variable, depending much upon the conditions noted above
but leaf-form varies but little in the several species. So, too, the color
of leaves is very constant throughout a species, for both surfaces,
though impossible to describe accurately in words and very difficult
to reproduce in color-printing. There is a marked difference in
autumnal tints not only of species but of varieties but these are not
very constant in any one location and must vary greatly under
different environments. The thickness of the leaves of the several
species is a distinctive character. Species of plums have very
different leaf-surfaces as regards reticulation, rugoseness,
pubescence and coriaceousness, all of these characters being quite
constant, though it is to be noted that roughness of leaves and
pubescence are increased by exposure to the sun and by the
influence of some soils. There is, indeed, considerable variation in
the pubescence of the leaves of all species of plums in different
parts of the country and probably too much has been made of
pubescence as a determining character.
The margins of leaves are very characteristic of species and
scarcely vary under normal conditions if the teeth at the middle of
the sides be taken rather than those toward the base or apex, these
very often being crowded, reduced or wanting. The presence of
glands, their position, size, shape and color, help to characterize
several species and seem to be fairly constant guides. Some species
and a great number of varieties have the distinguishing marks of
gland-like prickles tipping the serrations in the leaf-margins. Length,
thickness, rigidity and pubescence of petiole have some taxonomic
value. Stipules usually offer no distinguishing marks other than those
mentioned under leaves.
The blossoms of plums are very characteristic, giving in flowering
time a distinctive aspect to all species and distinguishing some
horticultural varieties. The flowers of all the species are borne in
clusters, differing in number of individuals, according to the species;
so, too, the flowers in the different species vary in size, color, in
length of their peduncles, and in pubescence, especially of the calyx.
Flower-characters are constant, taking them as a whole, yet there
are some variations that must be noted. One of the most marked of
these is in the time of appearance of the flowers; in the South they
appear before the leaves but in the North with the leaves. On the
grounds of this Station there are notable exceptions to the latter
statement, with varieties of species showing considerable variation in
this regard. There are some remarkable variations within species as
regards size and color of the corolla and glands and pubescence of
the calyx, depending upon the environment of the plant; but on the
whole these characters are very constant. The fragrance of the
flowers of plums varies from a delicate, agreeable odor to one that is
quite disagreeable in some species as in Americana; the odor seems
to be a constant character.
Of all structures of the plum the fruit is most variable, yet fruits
are sufficiently distinct and constant, especially within species, to
make their characters very valuable in classification. Species,
whether wild or cultivated, may be distinguished in greater or less
degree by the period of ripening of the fruits, though in this regard
the cultivated varieties of the several species vary greatly and in the
wild state trees of native plums in the same locality, even in the
same clump, may vary in ripening as much as from two to four
weeks. Species are distinguished by size, shape, color, flesh, flavor
and pit among the grosser characters of the structure and by
amount of bloom, stem, cavity, apex, suture and skin among the
minor characters. The fruit is usually the first part of the plant to
respond to changed conditions.
Characters derived from seed structures are generally accounted
of much value by botanists in determining species. Such is the case
with plums. This Station has a collection of stones of over three
hundred cultivated varieties of plums and some specimens of nearly
all the different species. The stones illustrated in the color-plates in
this book show that this structure is quite variable in size, shape, in
the ends, surfaces, grooves and ridges, even within a species;
nevertheless in describing the several hundred forms of plums for
The Plums of New York the stone has been quite as satisfactory, if
not the most satisfactory, of any of the organs of this plant for
distinguishing the various species and varieties.
The reproductive organs of plums afford several characters and
would seem to offer means of distinguishing botanical and
horticultural groups, but they are so variable in both cultivated and
wild plants as to be very misleading. Not only do these organs differ
very often in structure but also in ability to perform their functions.
Bailey[1] has called attention to the remarkable self-sterility of some
varieties of the native species of plums, due to the impotency of the
pollen upon flowers of the same variety. C. W. H. Heideman[2] made
some very interesting observations on what he considers distinct
forms of the flowers of the Americana plums, describing for this
species all of the six possible variations of flowers enumerated by
Darwin in his Different Forms of Flowers in Plants of the Same
Species. Heideman thinks that other species of Prunus exhibit similar
variations. Waugh[3] made the pollination of plums a subject of
careful and extended study and found much variation in the pistils of
plants of the same species, insufficient pollen in some plants, pollen
impotent on the stigma of the same flower, and considerable
difference in the time of maturity of pollen and stigma in some
plums, especially the Americana plums. These variations, most
important to the plum-grower, are of more or less use in identifying
plums.
After the discussion of the characters of plums we may pass to a
detailed description and discussion of the species of plums which
now contribute or may contribute cultivated forms to the pomology
of the country either for their fruits or as stocks upon which to grow
other plums. The following conspectus shows as well as may be the
relations of the species of plums to each other.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebooknice.com