Dip Oj
Dip Oj
Oishi Jyoti
Lecturer
Dept. of ECE, RUET
Reference Book
Morphological operations are a set of operations that process images based on shapes. In a morphological
operation, each pixel in the image is adjusted based on the value of other pixels in its neighborhood.
They apply a structuring element to an input image and generate an output image.
Structuring element: A structuring element is a matrix that identifies the pixel in the image being
processed and defines the neighborhood used in the processing of each pixel. You typically choose a
structuring element the same size and shape as the objects you want to process in the input image.
Dilation: Erosion:
a) Full match- 1 a) Full match- 1
b) Partial match -1 b) Partial match -0
c) No match- 0 c) No match- 0
Example or Dilation and Erosion
Have a look at the following example
0 0 0 0 0 0 1
0 0 1 1 0 0 1
0 1 1 1 1 0 1
0 0 1 1 0 0
0 0 1 0 0 0
0 0 0 0 0 0
Problem: A⊕B Problem: A⊖B
0 0 1 1 0 0 0 0 0 0 0 0
0 1 1 1 1 0 0 0 0 0 0 0
0 1 1 1 1 0 0 0 1 1 0 0
0 1 1 1 1 0 0 0 1 0 0 0
0 0 1 1 0 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0 0 0
Problem 1
0 0 0 0 0 0 1
0 0 1 1 0 0 1
0 1 1 1 1 0 1
0 0 1 1 0 0
0 0 0 0 0 0
0 0 0 0 0 0
a) A dilated by B
b) Ac eroded by B
Opening and Closing
Opening is generally used to restore or recover the original image to the maximum
possible extent.
Closing is generally used to smoother the contour of the distorted image and fuse back
the narrow breaks and long thin gulfs.
The combination of Opening and Closing is generally used to clean up artifacts in the
segmented image before using the image for digital analysis.
( After
opening)
( After (Opening
closing) followed
by closing)
Opening and Closing
Opening :
Properties of Opening are:
1. XoY is a subset (subimage of X)
2. If X is a subset of Z then XoY is a subset of ZoY
3. (XoY)oY = XoY
Closing:
Properties of Closing are:
1. X is a subset subimage of X.Y
2. (X.Y).Y = X.Y
Problem 2
1 1 1 0 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 0 1 1 1 1 1 1
a) A opened by B
b) A closed by B
Hit-or-Miss Transformation
⮚ Conceptually hit-or-miss transformation is mainly tool for shape
detection/presence.
⮚ The concept forwards with starting with small shape or sub-set of the
main input image.
⮚ In figure ‘A’ is an input image, C,D,E are some objects on the
image (sub-set of A).
⮚ We want to find any shape is present in the image or not
⮚ Suppose we want to find the existence of D into the image A
⮚ Several steps are shown as in the figure
Hit-or-Miss Transformation
As the local background of the sub image D is obtained as [W-D]. This can be written as B=(B1 and B2). Where
B1=D is formed for the elements of the foreground and B2=W-D which is for background elements.
Here D is mainly a structuring element. This hit-or-miss concept can be written in of erosion and dilation as the
following
Hit-or-Miss Transformation
Structuring element in this operation:
⮚ The structuring element used in the hit-and-miss is a slight extension to the type that has been introduced for
erosion and dilation
⮚ It can contain both foreground and background pixels i.e. both ones and zeros
Hit-or-Miss Transformation
⮚ The output is the result of implementing the four kernel/structuring element separately and merging the four of
the intermediate outputs.
Hit-or-Miss Transformation
0 0 0 0 0 0 0 0 0 0 0 1 0
0 1 1 1 1 1 0 0 1 0 0 0 0
0 1 1 1 1 1 0 0 1 0 0 0 0
0 1 1 1 1 1 0
B1 B2
0 1 1 1 1 1 0
0 1 1 1 1 1 0
0 0 0 0 0 0 0
A 0 0 0 0 0 0 0
0 1 1 1 1 1 0
0 1 1 1 1 1 0
0 1 1 1 1 1 0
0 1 1 1 1 1 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
Hit-or-Miss Transformation
An Example of heat-or-miss: Calculating the values of a binary image
1 1 1 1 1 1 1 0 0 0 0 0 0 0
1 0 0 0 0 0 1 1 1 1 1 1 1 1
1 0 0 0 0 0 1 1 0 0 0 0 0 1
1 0 0 0 0 0 1 1 0 0 0 0 0 1
1 0 0 0 0 0 1 1 1 0 1 0 1 1
1 0 0 0 0 0 1 1 0 0 0 0 0 1
1 1 1 1 1 1 1 1 0 0 0 0 0 1
Hit-or-Miss Transformation
An Example of heat-or-miss: Calculating the values of a binary image
0 0 0 0 0 0 0
0 1 1 1 1 1 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
Hit-or-Miss Transformation
Checking your understanding: Solve the following
1 0 0 1 1 1 0
B1 = Last 3by3 part of A
1 0 0 0 1 0 0 B2 = Compliment of B1
1 0 0 0 1 1 1
Now find,
1 1 0 0 1 0 0
0 1 0 1 0 1 0 Verify your answer with,
0 1 0 1 1 1 1
0 1 0 1 1 1 1
A
Hit-or-Miss Transformation
Checking your understanding: Solve the following
A
Hit-or-Miss Transformation
Checking your understanding: Solve the following
0 0 0 0 0 0 0
Now find, the corner of the image.
0 1 1 1 1 1 0
0 1 1 1 1 1 0
0 1 1 1 1 0 0
⨯ 1 ⨯ ⨯ 1 ⨯ ⨯ 0 0 0 0 ⨯
0 1 1 1 0 0 0
0 1 1 1 1 0 1 1 0 0 1 1
0 1 1 0 0 0 0
0 0 ⨯ ⨯ 0 0 ⨯ 1 ⨯ ⨯ 1 ⨯
0 0 0 0 0 0 0
B1 B2 B3 B4
A
Hit-or-Miss Transformation
Checking your understanding: Solve the following
0 0 0 0 0 0 0 0
Now find, HMT.
0 0 1 1 1 0 0 0
0 0 1 1 1 0 0 0
0 0 0 1 1 1 0 0
⨯ 1 ⨯
0 0 0 1 1 1 0 0
1 1 1
0 0 1 1 1 1 0 0
⨯ 1 ⨯
0 0 1 1 1 1 0 0
B1
0 0 0 0 0 0 0 0
A
Hit-or-Miss Transformation
Checking your understanding: Solve the following
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 1 1 0 1 1 1 0 1 1 1 0 0 0
0 0 1 1 0 1 1 1 0 1 1 1 1 0 0
0 0 1 1 0 1 1 1 0 1 1 1 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
A
Boundary Extraction
Boundary Extraction: Boundary Extraction is a Digital Image Process to extract edges from a binary image. It has
also been used as the basis for extracting edges on grayscale and color images.
⮚ The process includes two major steps
⮚ Erode the input image using any kernel of any size
⮚ Then performing the set different of the eroded image and the original input image results in the image with
boundary extracted
⮚ A 3X3 kernel extracts the most sophisticated boundary of one pixel thickness
⮚ Increase in kernel size will increase the boundary thickness.
⮚ Mathematical definition of boundary extraction can be written as
β(A) = A - (A Ɵ B)
⮚ Here B is the structuring element
Boundary Extraction
Approach of boundary extraction
Kernel (B)
⮚ This technique helps to eliminate error from image like spots and damaged regions
⮚ To extract shellute from captured images
Connected Component Extraction
Connected Component: To find out all pixel which are connected with a initial known value.
⮚ Similar way like boundary filling algorithm
Mathematically be written as X[k] = (X[k-1] ⊕ B) ∩ A where k=1,2,3,4…….
• Here X0 =p , Terminates at X[k] = = = X[k-1]
Consider the following image and structuring element. Then find out the connected component in the image.
1 1 1 0 0 0 0 1 1 1
1 0 1 0 0 0 0 1 1 1
1 1 1 0 0 1 1 1 1 1
1 1 0 0 0 1 1
1 1 0 0 1 1 1
1 0 1 1 0 0 1
0 0 1 1 1 1 1
Other algorithms
➢ Thinning
➢ Thickening
➢ Skeleton
➢ Pruning
Thinning
➢ To remove selected foreground pixels from binary images
➢ Reduces the area of shape from every side of the image
➢ It also an application of hit-or-miss transform
➢ It an iterative method
➢ Mathematically can derived as
• Thinning of a set A of foreground pixels by a structuring element B, can be defined in terms of the hit-or-miss
transform:
1 1 0 0 0 0 0 1 1 1 × ×
1 1 1 1 1 1 1 1 0 0 × 1 × 1 1 1 1
1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 × × 1 1
1 1 1 1 1 1 1 1 0 0
B1 B2 …………… B8
1 1 1 0 0 1 1 1 0 0
❖ Similarity
1. Thresholding
2. Region growing
3. Region split
Image Segmentation
⁂ Point Detection
- Done using sharpening filters. (Laplacian kernel)
Image Segmentation
⁂ Point Detection
Image Segmentation
⁂ Line Detection
- We use 2nd order derivatives which result in a thinner line than first
derivative.
Image Segmentation
⁂ Line Detection
Image Segmentation
⁂ Edge Detection
- Used frequently for segmenting image based on abrupt changes in intensity
- Thicker lines : Robert-cross, Prewitt, Sobel Operators (First derivative)
- Thinner line : Laplacian(2nd Order)
- Maximum Edge strength in a predetermine directions : Kirsch Compass
- Canny Edge Detection
Image Segmentation
0 1 1 -1 -1 0
⁂ Edge Detection
-1 0 1 -1 0 1
-1 -1 0 0 1 1
0 1 2 -2 -1 0
-1 0 1 -1 0 1
-2 -1 0 0 1 2
Better noise
suppression
Image Segmentation
Image Segmentation
0 -1 0 -1 -1 -1
-1 4 -1 -1 8 -1
Second order kernels (The Laplacian)
0 -1 0 -1 -1 -1
Canny Edge Detection
Noise Reduction
Gradient Calculation
Non-Maximum Suppression
Double Thresholding
Hysteresis
Canny Edge Detection
Noise Reduction
Since edge detection is susceptible to noise in the image, first step is to remove the
noise.
Canny Edge Detection
Gradient Calculation
Smoothens image is filtered with a sobel kernel in both X and Y direction to get
derivatives.
Canny Edge Detection
Non-Maximum Suppression
The final image should have thin edges. Thus, we must perform non-maximum
suppression to thin out the edges.
The algorithm goes through all the points on the gradient intensity matrix and finds the
pixels with the maximum value in the edge directions.
Canny Edge Detection
Double Thresholding
More than maxVal = edges,
less than minVal = not edges
Canny Edge Detection
Hysteresis
Connected with ‘sure-edges’ pixel is considered to be part of edges.
Image Segmentation of Gray Image
⁂ In bi-level thresholding, image is segmented into two different regions.
⁂ The pixels with gray values greater than a certain value T are classified as object pixels, and
the others with gray values lesser than T are classified as background pixels.
⁂ Gray scale image contains pixel value within 0 to 255.
Image Segmentation of Gray Image
WaterShed Algorithm
⁂ The watershed is a classical algorithm used for segmentation, for separating
different objects in an image.
WaterShed Algorithm
⁂ Watershed : A watershed is the area of the land that drains to a particular
points along a stream
WaterShed Algorithm
⁂ Algorithm –
1. Start with pixels with lowest possible
values.
2. For each pixel intensity –
>> If there is adjacent pixel within one
region, add the pixel to that region.
>> Else if there is adjacent pixel which is
adjacent to more region, mark as boundary.
>> Else start new region
Watershed Algorithm
General Segmentation :
Watershed Algorithm
Watershed Segmentation :
Computer Graphics : Line Algorithm
DDA : Digital Differential Analyzer DDA algorithm is the simple line generation algorithm
which is explained step by step here.
❑ Step 1: Input the two endpoints of the line segment, (x1,y1) and (x2,y2).
❑ Step 2: Calculate the difference between the x-coordinates and y-coordinates of the endpoints
as dx and dy respectively.
❑ Step 3: Calculate the slope of the line as m = dy/dx.
❑ Step 4: Set the initial point of the line as (x1,y1).
❑ Step 5: If 0<m ≤ 1, x=x1+1, y=y1+m
If -1 ≤ m < 0, x=x1-1, y=y1-m
If m>1, x=x1+(1/m), y=y1+1
If m<-1, x=x1-(1/m), y=y1-1
❑ Step 6: Plot the pixel at the calculated (x,y) coordinate.
❑ Step 7: Repeat steps 5 and 6 until the endpoint (x2,y2) is reached.
Computer Graphics : Line Algorithm
Bresenham : The Bresenham algorithm is another incremental
scan conversion algorithm. The big advantage of this algorithm
is that, it uses only integer calculations.
4) After confirming that the line is partially inside the window, then we find the intersection with the
boundary of the window. By using the following formula:-
Slope:- m= (y2-y1)/(x2-x1)
a) If the line passes through top or the line intersects with the top boundary of the window.
x = x + (y_wmax – y)/m
y = y_wmax
b) If the line passes through the bottom or the line intersects with the bottom boundary of the window.
x = x + (y_wmin – y)/m
y = y_wmin
c) If the line passes through the left region or the line intersects with the left boundary of the window.
y = y+ (x_wmin – x)*m
x = x_wmin
Cohen Sutherland Algorithm
d) If the line passes through the right region or the line intersects with the right boundary of the
window.
y = y + (x_wmax -x)*m
x = x_wmax
5) Now, overwrite the endpoints with a new one and update it.
6) Repeat the 4th step till your line doesn’t get completely clipped
Image Compression
Image compression is a process applied to a graphics file to minimize its size in bytes
without degrading image quality below an acceptable threshold.
By reducing the file size, more images can be stored in a given amount of disk or
memory space
Types:
1. Lossy
2. Lossless
Lossy Compression
Run–length encoding (RLE) is a simple form of lossless data compression that runs on
sequences with the same value occurring many consecutive times. It encodes the
sequence to store only a single value and its count.
WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWW
WWWWWWWWWWWWWWBWWWWWWWWWWWWWW
With a run-length encoding (RLE) data compression algorithm applied to the above
hypothetical scan line, it can be rendered as 12W1B12W3B24W1B14W.
V.V.I
Huffman Coding
Initial Message:
V.V.I
Huffman Coding
Initial Message:
Each character occupies 8 bits. There are a total of 15 characters in the above string.
Thus, a total of 8 * 15 = 120 bits.
Calculate the frequency of letter
V.V.I
Huffman Coding
Sort the characters in increasing order of the frequency. These are stored in a priority
queue Q.
V.V.I
Huffman Coding
A 5 11 5*2 = 10
B 1 100 1*3 = 3
C 6 0 6*1 = 6
D 3 101 3*3 = 9
V.V.I
Lossless Compression
Lossless compression means that you reduce the size of an image without any quality
loss.
Removes unnecessary metadata from JPEG and PNG files
Lossless image formats:
GIF
PNG
BMP
Wavelet Compression
Wavelet compression offers an approach that allows one to reduce the size of the data
while at the same time improving its quality through the removal of high-frequency
noise components.
Steps:
1. Digitize the source image to a signal
2. Decompose the signal into a sequence
3. Use thresholding to modify the wavelet
4. Use quantization to new sequence
5. Apply entropy encoding (RLE, Huffman) to compress
Fractal Compression
Fractal compression uses the properties of fractal objects for compression. It is a lossy
compression.
Fractal objects resemble the main object. So, by removing the similar objects the
image can be compressed.
Topics
Blur
Smooth
Sharp
Intensity Transformation
Zooming
Concave and Convex hull
THANK YOU