Professional Documents
Culture Documents
Image Processing
Image Processing
The square structuring element ‘A’ fits in the object we want to select, the ‘B’
intersects the object and ‘C’ is out of the object.
The zero-one pattern defines the configuration of the structuring element. It’s
according to the shape of the object we want to select.
The center of the structuring element identifies the pixel being processed.
source
Dilation/ source
Erosion / source
Image –
'gif' GIF 87a and 89a Files
Manipulation Operations:
Image Manipulation refers to a process of bringing changes to a digitized
image for transforming it to a desired image.
The changes are made possible by resorting to image processing.
Image manipulation is utilized to create magazine covers and albums from
photographs.
A single photograph may be modified to suit the requirement, or several
photographs can be combined to form a collage.
Currently, there are numerous software applications ranging from
professional applications to basic imaging software.
2.Convert the grey scale image to binary with a threshold of your choice.
Output Image:
Input:
Output:
Blurring an Image:
Blurring an image can be done by reducing the level of noise in the image
by applying a filter to an image.
Image blurring is one of the important aspects of image processing.
The ImageFilter class in the Pillow library provides several standard image
filters.
Simple blur
Box blur
Gaussian blur
Simple blur:
It applies a blurring effect on to the image as specified through a specific kernel
or a convolution matrix.
Syntax:
filter(ImageFilter.BLUR)
Example:
blurImage = OriImage.filter(ImageFilter.BLUR)
blurImage.show()
#Save blurImage
blurImage.save('images/simBlurImage.jpg')
Original image:
Blurred image:
Box blur:
In this filter, we use ‘radius’ as parameter. Radius is directly proportional to the
blur value.
Syntax:
ImageFilter.BoxBlur(radius)
Where,
Radius − Size of the box in one direction.
Radius 0 − means no blurring & returns the same image.
RRadius 1 &minnus; takes 1 pixel in each direction, i.e. 9 pixels in total.
Example:
#Import required Image library
from PIL import Image,
#Open existing image
OriImage = Image.open('images/boy.jpg')
OriImage.show()
#Applying BoxBlur filter
boxImage = OriImage.filter(ImageFilter.BoxBlur(5))
boxImage.show()
#Save Boxblur image
boxImage.save('images/boxblur.jpg')
Output:
Original Image:
Blurred Image:
Gaussian Blur:
This filter also uses parameter radius and does the same work as box blur
with some algorithmic changes.
In short, changing the radius value, will generate different intensity of
‘Gaussianblur’ images.
Syntax
ImageFilter.GaussianBlur(radius=2)
Where,
Radius – Blur radius
Example
Output:
Original Image:
Blurred Image:
Edge Detection:
Edge detection is a technique of image processing used to identify points
in a digital image with discontinuities, simply to say, sharp changes in the
image brightness.
These points where the image brightness varies sharply are called the
edges (or boundaries) of the image.
There are various methods in edge detection, and the following are some of
the most commonly used methods-
This uses a filter that gives more emphasis to the centre of the filter. It is one of
the most commonly used edge detectors and helps reduce noise and provides
differentiating, giving edge response simultaneously. The following are the
filters used in this method-
The following shows the before and after images of applying Sobel edge
detection-
The following are the original minion image and the image after applying this
method.
Reducing the size of an Image:
Syntax: Image.resize(size, resample=0)
Parameters:
size – The requested size in pixels, as a 2-tuple: (width, height).
resample – An optional resampling filter. This can be one of PIL. Image.
NEAREST (use nearest neighbour), PIL. Image. ...
Returns type: An Image object.
Image Used:
Program:
# Importing Image class from PIL module
from PIL import Image
# Opens a image in RGB mode
im = Image.open(r"C:\Users\System-Pc\Desktop\ybear.jpg")
# Size of the image in pixels (size of original image)
# (This is not mandatory)
width, height = im.size
# Setting the points for cropped image
left = 4
top = height / 5
right = 154
bottom = 3 * height / 5
# Cropped image of above dimension
# (It will not change original image)
im1 = im.crop((left, top, right, bottom))
newsize = (300, 300)
im1 = im1.resize(newsize)
# Shows the image in image viewer
im1.show()
Output: