0% found this document useful (0 votes)
6 views38 pages

Python OpenCV: Image Processing Guide

Chapter 2 discusses the integration of Python with OpenCV for image processing, highlighting essential libraries such as NumPy, SciPy, and Matplotlib. It covers common image processing tasks, the advantages of using NumPy for array operations, and the functionalities of SciPy for scientific computations. Additionally, it introduces OpenCV as a powerful tool for computer vision, detailing its capabilities and core operations.

Uploaded by

Tharanis Waran
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views38 pages

Python OpenCV: Image Processing Guide

Chapter 2 discusses the integration of Python with OpenCV for image processing, highlighting essential libraries such as NumPy, SciPy, and Matplotlib. It covers common image processing tasks, the advantages of using NumPy for array operations, and the functionalities of SciPy for scientific computations. Additionally, it introduces OpenCV as a powerful tool for computer vision, detailing its capabilities and core operations.

Uploaded by

Tharanis Waran
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

CHAPTER 2

PYTHON AND OPENCV


Learning Outcomes :
Understand Python required packages and libraries
for OpenCV
a) Numpy and SciPy Libraries
b) Matplotlib
c) OpenCV
➢Today's world is full of data, and images form a significant part of
this data. However, before they can be used, these digital images
must be processed—analysed and manipulated to improve their
quality or extract some information that can be put to use.

➢Common image processing tasks include displays;


a) basic manipulations like cropping, flipping, rotating, etc.;
b) image segmentation, classification, and feature extractions;
c) image restoration; and
d) image recognition.
➢Python is an excellent choice for these types of image
processing tasks due to its growing popularity as a scientific
programming language and the free availability of many state-
of-the-art image processing tools in its ecosystem.

➢These Python libraries provide an easy and intuitive way to


transform images and make sense of the underlying data.
• Numerical Python, in short, NumPy, is an open-source
library. It is an incredible Python library for scientific
calculations. It also allows for accomplishing matrix
operations. NumPy is used to perform operations on
the array. As it works on an array, it permits us to
reorganize a large set of data.

• OpenCV resolves computer vision issues. It makes use


of NumPy to convert OpenCV array to and from NumPy
array. It performs many tasks including motion
tracking, gesture recognition, etc.
• Matplotlib is the most extensively used Data Visualization
library in Python programming. You can
generate plots, graphs, bar graphs, scatter
graphs, histograms, arrays etc. in a 2D form easily.

• It is an open-source library which is based on the concept of


NumPy which provides many effective numerical routines.
It can perform integration and linear algebra and has high-
level features for data manipulating and [Link] is
a key library for data processing.
• NumPy, is an open-source library. It is an incredible
Python library for scientific calculations. It also allows for
accomplishing matrix operations.
• NumPy is used to perform operations on the array. As it
works on an array, it permits us to reorganize a large set
of data.
Why is NumPy so popular?
NumPy is extremely popular because it dramatically improves the ease and
performance of working with multidimensional arrays. Some of Numpy's
advantages:
❑ Mathematical operations on NumPy’s ndarray objects are up to 50x faster
than iterating over native Python lists using loops. It offers an Indexing
syntax for easily accessing portions of data within an array.
❑ It contains built-in functions that improve quality of life when working with
arrays and math, such as functions for linear algebra, array
transformations, and matrix math.
❑ It requires fewer lines of code for most mathematical operations than
native Python lists.
Installation
To check if you already have NumPy installed in your Python installation (it
most likely is), run the following command:

If no error message is returned, that's a good sign NumPy is already


available. If you get an error message like
ModuleNotFoundError: No module named 'numpy'
List of useful NumPy functions
NumPy has numerous useful functions. You can see the full list of functions in
the NumPy docs
NumPy arrays : an n-dimensional data structure - is the
central object of the NumPy package.
Array in Numpy
• It is a table of elements (usually numbers), all of the same type, indexed by
a tuple of positive integers.
• In NumPy dimensions are called axes. The number of axes is rank.
• NumPy’s array class is called ndarray. It is also known by the alias array.
SciPy in Python is an open-source library used for solving mathematical,
scientific, engineering, and technical problems. It allows users to
manipulate the data and visualize the data using a wide range of high-level
Python commands. SciPy is built on the Python NumPy extention. SciPy is
also pronounced as “Sigh Pi.”
Why use SciPy
• SciPy contains varieties of sub packages which help to solve the most common
issue related to Scientific Computation.
• SciPy package in Python is the most used Scientific library only second to GNU
Scientific Library for C/C++ or Matlab’s.
• Easy to use and understand as well as fast computational power.
• It can operate on an array of NumPy library.

Install SciPy
SciPy consists of a collection of numerical
algorithms and domain-specific toolboxes
including signal processing, optimization,
statistics and much more.
SciPy sub-packages need to be imported
separately, for example:
• Matplotlib is the most extensively used Data Visualization
library in Python programming. You can
generate plots, graphs, bar graphs, scatter
graphs, histograms, arrays etc. in a 2D form easily.

Importing the library


To get matplotlib up and running in our environment, we need to
import it.
Matplotlib UI Menu
When matplotlib is used to create a plot, a User Interface (UI) and menu structure are
generated. The UI can be used to customize the plot, as well as to pan/zoom and toggle
various elements.
Matplotlib Line Plot
Matplotlib Pie Plot
Matplotlib Bar Plot
Numpy Array Plot
Matplotlib: Subplot
What Is Computer Vision?
• Computer Vision is an interdisciplinary field that deals with how computers
can be made to gain a high-level understanding from digital images or
videos.
• The idea here is to automate tasks that the human visual systems can do.
So, a computer should be able to recognize objects such as that of a face of
a human being or a lamppost or even a statue.
How Does A Computer Read An Image?
• Consider the below image:
• The computer reads any image as a
range of values between 0 and 255.
• For any color image, there are 3 primary
channels – Red, green and blue. How it
works is pretty simple.
• A matrix is formed for every primary
color and later these matrices combine
to provide a Pixel value for the
individual R, G, B colors.
• Each element of the matrices provide
data pertaining to the intensity of
brightness of the pixel.
As shown, the size of the image here can be calculated as B x A x 3.
Note: For a black-white image, there is only one single channel.
• OpenCV is a Python library which is designed to solve
computer vision problems. OpenCV was originally developed
in 1999 by Intel but later it was supported by Willow Garage.
• OpenCV supports a wide variety of programming languages
What is such as C++, Python, Java etc. Support for multiple platforms
OpenCV including Windows, Linux, and MacOS.
• OpenCV Python is nothing but a wrapper class for the
original C++ library to be used with Python. Using this, all of
the OpenCV array structures gets converted to/from NumPy
arrays.
• This makes it easier to integrate it with other libraries which
use NumPy. For example, libraries such as SciPy and
Matplotlib.
What will cover in OpenCV
GUI Features Image, Video, Drawing Function
Core Operation Basic operation
Arithmetic Operation
Image Processing Changing Color spaces, Geometric
Transformation of Images, Image
Thresholding, Smoothing Images,
Contours, Histograms
GUI Features
Image [Link], [Link], [Link]
Video [Link], [Link],
[Link], [Link]
Drawing Function [Link], [Link], [Link],
[Link]
Core Operation
Basic Operation [Link], [Link], [Link],
Arithmetic [Link], [Link], [Link]
Operation
Image Processing
Changing Color spaces, [Link](), [Link](), etc.
Geometric [Link], [Link],
[Link] and
Transformation of
[Link]
Images,
Image Thresholding, [Link] and
[Link].
Image Processing
Smoothing Images, blur()
GaussianBlur()
medianBlur()
bilateralFilter()
Contours, [Link](),
[Link]()
Histograms [Link](),
[Link]() etc.
THANKS YOU

You might also like