LABORATORY
ACTIVITY 1
(DIGITAL IMAGE
PROCESSING)
By: VERA A. PANAGUITON
OUTLINE:
Image Processing
Types of Images
Installation and adding packages
What is OpenCV?
Required Libraries
Image blur, grayscale, canny
Read Images, Videos and Webcams
Using Google Colab
What is Image Processing
Image processing is IMAGE + PROCESSING
What is an Image?
Image is a collection of PIXELS.
Each pixel is like an array of numbers.
These numbers determine the color of the pixel.
Three types of images:
Each kind of image has few attributes attached to it like number of channels and depth .
Number of channels : Defines the dimension of array , each pixel is.
Depth : Defines the maximum bit size of the number which is stored in the array
How an image is represented in memory
10 x 10 image of a number 3
Each image is represented by a set of pixels i.e. a matrix of
pixel values. For a grayscale image, the pixel values range
from 0 to 255 and they represent the intensity of that pixel.
- For instance, if you have an image of 10 x 10
dimensions, it would be represented by a matrix of 10
pixels (width) x 10 pixels (height) (a total of 100-pixel
values).
- Image quality based on pixels:
VGA = 640 x 480
HD = 1280 x 720
FHD = 1920 x 1080
4K = 3840 x 2160
If you are dealing with a colored image, it would have three
channels - Red, Green, and Blue (RGB). Therefore, there
would be three such matrices for a single image.
Grayscale
28 = 256
0 255
RGB
RGB VGA = 640 x 480 x 3
Installation
(PyCharm)
Installation
Install PyCharm
After installing,
open PyCharm
Create Project
Add OpenCV
Add Numpy
Add Matplotlib
Create
Project Project
Created
Install packages and libraries
Click the
+ button
File -> Settings -> Python Interpreter
Add OpenCV package
Search for
opencv-python
After
installation
close the
window.
Select opencv-python
and click the Install
Package button
What is OpenCV?
It stands for ‘Open Source Computer Vision Library’ .
OpenCV is an Image Processing library created by Intel and maintained by Willow
Garage.
It has C++, C, and Python interfaces running on Windows, Linux, Android and Mac.
Basic Modules.
cv : Main OpenCV functions, Image processing and vision algorithms.
cvaux : Auxiliary (experimental) OpenCV functions.
cxcore : Data structures, linear algebra support, XML support drawing functions and
other algorithms.
highgui : GUI functions, Image and Video I/O.
Note: Depending on what your program implements you wish to use, you should
include corresponding modules.
Some Required Libraries
Numpy is an array manipulation library, used for linear algebra,
Fourier transform, and random number capabilities.
Pandas is a library for data manipulation and data analysis.
CV2 is a library for computer vision tasks.
Skimage is a library which supports image processing
applications on python.
Matplotlib is a library which generates figures and provides
graphical user interface toolkit.
Add python file
Right click on
your project
(DIP)
New -> Python File
Add folder and images
Right click on your project -> New -> Directory
You can add image directly to the
folder created, just look for the
path of your project.
Finding Image Details
Import package
Run your
Load image program
Print Properties or
Output:
or
CTRL + SHIFT + F10
Display the image
imshow()
first parameter is the name of the
window, second is the image.
waitKey() values:
0 – infinite delay, 1000 – 1 second
Resize/rescale the image
Create function to rescale.
or
To resize the image
Convert to Grayscale
cvtColor()
Convert color
RGB in openCV is BGR
Splitting an image into individual channels
Image Blur
Canny Image
Write an image
Use the function cv2.imwrite to
save an image in the working
directory.
First argument is the file name,
second is the image you want to
save.
Read Video
VideoCapture() parameter can be the number of your
camera, webcam is 0, or the path of the video file
Use while to read
video frame per frame
Means the keyboard
letter q to exit.
Resize Video
To rescale live video
use capture.set()
Using Google Colab
Go to this link You can type your
codes here.
https://colab.research.google.com
You can create New What is Colaboratory?
Notebook here. Colaboratory, or "Colab" for short,
allows you to write and execute
Python in your browser, with:
- Zero configuration required
- Free access to GPUs
- Easy sharing
Click the play button
to run your program.
Read an image form a URL
Search for an image. Left-click
one of the returned images,
then right-click on the full
image, and then select "Copy
Image Address".
Upload an Image
Choose the image then it will
automatically be uploaded, just wait
for the 100% done.
Just click the + Code to insert code
cell after uploading the image then
type another line of codes.
Another Example
Laboratory Activity
Create 5 python files based on the sample
codes (resize, image blur, … ).
Upload it in the LMS, including your
image.
- END -