Week 4 Digital Image Processing
Week 4 Digital Image Processing
❖ Gray image
• For monochrome (gray) images, the brightness of each pixel is expressed by a numerical value.
• Usually in the range of 0 to 255, 0 for black, 255 for white, and other values for gray between black
and white.
❖ Color image
• Color images can be represented by two-dimensional matrices of Red, Green and Blue triples.
• Did you hear about RGB ?
• Normally, each value of a triple is between 0 and 255,
• 0 means that the corresponding primary color is not present in the pixel,
• and 255 means that the corresponding primary color is maximized in the pixel.
Digital Image (Cont.)
❖ Tool: Python-Pillow
• Python Imaging Library (PIL) is a free library for the Python programming language
that adds support for opening, manipulating, and saving many different image file
formats.
❖ Read (Open) and Show an image
• There are two general ways to display am image,
• The first method is using im.show() function in Pillow,
• however sometimes it may not work well in jupyter.
• The alternative method is using a third party library called matplotlib to display it.
3- Transformation: Crop, Rotate, and Resize images.
This part will tell you basic image transforms such as Crop, Rotate, Resize an image, etc.
❖ Crop an image
• If your image is too big or some parts of the image is useful, you can crop it. Here is an
example.
❖ Rotate an image
• If some images are not angeled properly, you may need to rotate them to make them look
better.
❖ Resize an image
• Sometime images are too large to process or need to cost lots of time to process, you can
resize images to make them more smaller.
4- Conversion: From RGB (or Color) to Grayscale images.
Pillow has its own conversion() method to convert images into different formats.
❖ Image binarization is the process of setting the gray value of the pixels on the image to 0 or 255,
• that is to say, the whole image presents an obvious black-and-white effect.
❖ In digital image processing, binary image plays a very important role.
• The binarization of an image greatly reduces the amount of data in the image, so that the
outline of the object can be highlighted.
❖ In Pillow, we use point() method to judge each pixel of an image, and set its gray value to 0 or
255 according to its relative size with the mean value, before converting it into a binary image.
6- Common Filtering: Smooth, Sharpen, Edge Enhancement
❖ Image filtering in Python mainly deals with image Smoothing, Sharpening and Edge
enhancement.
• You can regard it as a filter in a mobile photo processing app
❖ There are many kinds of filtering in Pillow, like Relief Filtering.
7- Advanced Filtering: Denoise
Some images have some noise which makes it difficult to evaluate, we can use some filters to
remove these noise.
❖ Here we give an example using Median Filter to remove noise in the image.
• The Median Filter is a nonlinear digital filtering technique, often used to remove noise from
an image or signal.
• Such noise reduction is a typical pre-processing step to improve the results for later
processing (for example, edge detection on an image).
• Median filtering is widely used in digital image processing because under certain conditions
it preserves edges while removing noise.
Note* You can try other filters to remove noise such as a Gaussian filter
7- Advanced Filtering: Denoise (Cont.)
Before After
8- Histogram
An image histogram is a type of histogram that acts as a graphical representation of the tonal
distribution in a digital image. It plots the number of pixels for each tonal value. By looking at the
histogram for a specific image a viewer will be able to judge the entire tonal distribution at a
glance.