You are on page 1of 13

ELE 492: Image Processing

Assoc. Prof. Seniha Esen Yüksel

Lecture: Practical Image Processing

Hacettepe University
Department of Electrical and Electronics Engineering

** Course slides are prepared using the book: Practical


Machine Learning and Image Processing
1
2
Anaconda for Windows
• Go to www.anaconda.com.
• Click Downloads on the top right side of the screen. Scroll
down and you will see two versions of Anaconda: Python
version 3.7 and Python version 2.7.
• In the Python 3.7 version box, select 64-Bit Graphical Installer
(select the 32-bit option, if your system is a 32-bit system).
• Wait for the download to finish, then double-click the
installation file.
• Finish the installation and restart your system.
• Now, open the Start menu, search for the Anaconda prompt,
and select it. A shell named Anaconda Prompt appears. Type
Jupyter Notebook inside the shell and you will see a screen
like the one displayed in Figure.
3
4
5
6
7
Python’s image processing library:
Scikit Learn

• import skimage

8
Uploading and Viewing an Image

9
Getting Image Resolution
• We have an image with a resolution of 1536 ×
2048, and it has three channels (because it is
in the RGB color format).

10
Looking at Pixel Values
#Getting Pixel Values
from skimage import io
import pandas as pd
img = io.imread('puppy.jpg')
df = pd.DataFrame(img.flatten())
filepath = 'pixel_values1.xlsx'
df.to_excel(filepath, index=False)

• import pandas as pd: renaming the imported module to pd.


• flatten function: converts the three dimensions of an RGB
image to a single dimension.
• Save that image in an excel file named pixel_values.xlsx.
• DataFramefunction converts a 1D array into an Excel-like
format, with rows and columns. 11
Converting Color Space
#Import libraries
from skimage import io
from skimage import color
from skimage import data
from pylab import *
#Read image
img = io.imread('puppy.jpg')
#Convert to HSV
img_hsv = color.rgb2hsv(img)
#Convert back to RGB
img_rgb = color.hsv2rgb(img_hsv)
#Show both figures
figure(0)
io.imshow(img_hsv)
figure(1)
io.imshow(img_rgb)

12
pylab
• We used one more module, called pylab.
• We import all the classes present inside pylab
by using *.
• We use pylab to see different figures in
different blocks.
• Then use the function figure to display more
than one image at a go.

13

You might also like