0% found this document useful (0 votes)
27 views

(1 - 1) Image Processing (Part 1)

Here are the steps to convert an RGB image to grayscale using the luminance formula: 1. Define the luminance weights as a 1x3 matrix: weights = np.array([0.2126, 0.7152, 0.0722]) 2. Multiply the image array along the last axis (color channels) by the weights: gray = image @ weights 3. The result gray is the grayscale version of the image. We can compare it to the result of skimage.color.rgb2gray to check it matches.

Uploaded by

Nada Fasola
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)
27 views

(1 - 1) Image Processing (Part 1)

Here are the steps to convert an RGB image to grayscale using the luminance formula: 1. Define the luminance weights as a 1x3 matrix: weights = np.array([0.2126, 0.7152, 0.0722]) 2. Multiply the image array along the last axis (color channels) by the weights: gray = image @ weights 3. The result gray is the grayscale version of the image. We can compare it to the result of skimage.color.rgb2gray to check it matches.

Uploaded by

Nada Fasola
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
You are on page 1/ 23

IMAGE

PROCESSING
-Preparation-
Nada Fitrieyatul Hikmah
Requirements
• Install Python 3.6
• Scikit-image ➔ 0.15
• Numpy ➔ 1.12
• Scipy ➔ 1.0
• Matplotlib ➔ 2.1
• Jupyter Notebook ➔ 4.0
• Scikit-learn ➔ 0.18
Scikit-image
• Scikit-image is an
image processing
library that
implements
algorithms,
provides a well-
documented API in
the Python
programming
language.
Installing scikit-image
• Go to : https://scikit-image.org/
Installing SciPy
• SciPy is a Python-based
ecosystem of open-source
software for mathematics,
science, and engineering.
• Open :
https://anaconda.org/anacon
da/scipy
Installing Matplotlib
• Matplotlib is a python 2D
plotting library which
produces publication quality
figures in a variety of
hardcopy formats and
interactive environments
across platforms.
• Open :
https://anaconda.org/anaco
nda/matplotlib
Install Numpy
• Go to : https://numpy.org/install/
• The only prerequisite for NumPy is Python itself. If you don’t
have Python yet and want the simplest way to get started, we
recommend you use the Anaconda Distribution - it includes
Python, NumPy, and other commonly used packages for
scientific computing and data science.
Installing Scikit-learn
• Scikit-learn is a free software machine learning library for the Python programming language. It
features various classification, regression and clustering algorithms including support vector
machines, random forests, gradient boosting, k-means and DBSCAN, and is designed to
interoperate with the Python numerical and scientific libraries NumPy and SciPy.
• Go to : https://scikit-learn.org/stable/install.html
Image are Arrays
Nada Fitrieyatul Hikmah
Images are numpy arrays

• Images are represented in


scikit-image using standard
numpy arrays.
• The simplest image we can
make is a 2-dimestional
matrix :
“Real-world” images
Standard test image module from skimage : https://scikit-image.org/docs/dev/api/skimage.data.html

Next question is….


How we represent color arrays??
What would we need in order to
represent a color image??
Color Image
• A color image is a 3D
array, where the last
dimension has size 3
and represents the red,
green, and blue
channels.
Image just Numpy arrays
• These are just NumPy arrays. E.g., we can make a red square
by using standard array slicing and manipulation:
Displaying images using matplotlib

For more on plotting, see the Matplotlib documentation and pyplot API.
Data Types and Image Values (1)
• In literature, one finds different conventions for representing
image values:

• scikit-image supports both conventions--the choice is determined by


the data-type of the array.
Data Types and Image Values (2)
• Example 1 : I generate two valid images

The library is designed in such a way


that any data-type is allowed as input,
as long as the range is correct (0-1 for
floating point images, 0-255 for
unsigned bytes, 0-65535 for unsigned
16-bit integers).
Image I/O (1)
• Mostly, we won't be using input images from the scikit-image example
data sets. Those images are typically stored in JPEG or PNG format.
Since scikit-image operates on NumPy arrays, any image reader library
that provides arrays will do. Options include imageio, matplotlib, pillow,
etc.
• scikit-image conveniently wraps many of these in the io submodule, and
will use whichever of the libraries mentioned above are installed:
Image I/O (2)
• We also have the ability to load multiple images or multi-layer
TIFF (Tag Image File Format) images ➔is called image
collection.
Image I/O (3)
Note : Enumerate?
• Enumerate gives us each element in a container, along with its
position.
Visualizing RGB
Channels (1)
• Display the different color channels of the
image along (each as a gray-scale image).
Visualizing RGB Channels : what is color
combination?
Exercise : Convert to Grayscale
• The relative luminance of an image is the intensity of light coming
from each point. Different colors contribute differently to the
luminance: it's very hard to have a bright, pure blue, for example. So,
starting from an RGB image, the luminance is given by:

• Use Python matrix multiplication, @, to convert an RGB image to a


grayscale luminance image according to the formula above.

• Compare your results to that obtained with skimage.color.rgb2gray.

You might also like