lFinalGroup-8

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 62

Image and Video Compression

Morphological Image Processing

Presented to : Presented by :
Mahbubun Nahar Rayhan Mahmud Kabir Sanzid
Assistant Professor Somya Akter Smrity
Shariful Islam
Md. Ashikur Rahman Ashik
Sumon Parvez
Malobika Yesmin Tithi

Department of Computer Science and Engineering


Jatiya Kabi Kazi Nazrul Islam University
Trishal, Mymensingh
1
Contents
 Image and Video Compression
 Morphological Image Processing
 Boundary Extraction
 Hole Filling
 Convex Hull
 Thinning and Thickening
 Skeletons and Pruning
 Dilation and Erosion
 Opening and Closing

2
Image
Compression
Introduction to Image Compression
 Image compression is the art and science of reducing the amount of data required to
represent an image.

 It is commercially successful and widely used in digital image processing.

 Everyone who owns a digital camera, surfs the web, or streams movies over the Internet
benefits from image compression algorithms and standards.

 This presentation will introduce the fundamentals of image compression, including


frequently used techniques and industry standards, and conclude with an introduction to
digital image watermarking.

3
Image
Fundamentals of Data Compression Compressio
n
Key Concepts

Data vs Information:
• Data are the means to convey information.
• Different amounts of data can represent the same information.

Relative Data Redundancy:


• Defines how much redundant data a representation contains.
• Calculated using R=1-(1/C) where C=b/b'.

Compression Ratio:
• Compression ratio (C) is defined as the ratio of the original size to the compressed size.

4
Image
Types of Data Redundancies Compressi
on
Principal Types
Coding Redundancy:
• Occurs when using more bits than necessary to represent information.

Spatial and Temporal Redundancy:


• Occurs due to correlation between pixels in an image or consecutive frames in a video.

Irrelevant Information:
• Information that is ignored by the human visual system or extraneous to the intended use of the image.

5
Image
Compressio
n
Coding Redundancy
 Coding redundancy is addressed by assigning shorter code words to
frequently occurring intensity values.

 The average number of bits required can be minimized by using


variable-length coding.

 Example formulas include Lavg = Σ l(k) * Pr(k) for average length


and MNLavg for total bits required for an MXN image.

6
Image
Compressi
on
Spatial and Temporal Redundancy

• Spatial redundancy exploits the similarity between neighboring pixels, while


temporal redundancy takes advantage of similarities across frames in a video.

• Compression is achieved by transforming the 2D intensity array into a more efficient


format, such as run-length encoding for spatial redundancy.

7
Image
Compression
Irrelevant Information
 Irrelevant information refers to data omitted without loss of perceived
image quality.

 For example, a homogeneous field of gray can be represented by its


average intensity alone, significantly reducing data size without
noticeable loss.

8
Image
Compressio
n
Image Information Measurement

Entropy:
• The average information per source output.
• Measured in bits/pixel using the formula Ĥ = -Σp(k)log₂P(k).

Shannon's First Theorem:


• Also known as the noiseless coding theorem, it assures that the optimal
coding can represent the image with average entropy per pixel.

9
Image
Compression
Image Compression Models

• An image compression system comprises an encoder and a decoder.

• The encoder performs compression by removing redundancies through


mapping, quantization, and symbol coding.

• The decoder reverses these steps to reconstruct the image.

• Compression can be lossless or lossy depending on whether the


reconstruction is exact.

10
Image
Compression
Image Formats and Compression Standards

• Image formats define how image data is arranged and the type of
compression used.

• Image compression standards define the procedures for compressing and


decompressing images.

• Examples include JPEG, PNG for still images, and MPEG, H.264 for video.

11
Image
Compression
Digital Image Watermarking

• Digital image watermarking is the process of inserting visible or invisible data


into images, such as copyright information.

• This is essential for protecting intellectual property and ensuring image


authenticity.

12
Video
Compressio
n
Video Compression

 Video compression is the process of reducing the file size


of a video file by reducing the amount of data needed to
represent its content, but without losing too much visual
information.
 Video compression is based on two principles:

I. Spatial redundancy
II. Temporal redundancy

13
Video
Compressi
on
Types of Video Compression

 There are two types of video compression:


I. Lossy video compression: Reduces file size by discarding some data
quality. This type of compression is often used in video streaming, video
conferencing, and video sharing platforms.
II. Lossless video compression: Retains all the original data, allowing for
perfect reconstruction of the video and audio.

14
Video
Compression
Necessity of Video Compression

 Raw video contains an immense amount of data.


 Communication and storage capabilities are limited & expensive.
 Enables faster loading, quicker uploads, and seamless streaming with minimal
buffering.
 Reduces infrastructure costs for data storage, bandwidth, and hosting.
 Enabling communication between devices made by different manufacturer.

15
Video
Compressi
on
Video Compression Techniques

 Video compression can be done using any of the following techniques:


I. Lossy compression and Lossless compression
II. Intra-frame and inter-frame compression
III. Spatial and temporal compression
IV. Moving Picture Experts Group (MPEG)

16
Video
Compressi
on
Video Compression Formats
 Some of the most popular formats for compressing video include:

• H.264 (MPEG-4 AVC): Short for Advanced Video Coding, it's the most
common compression format today & it offers high-quality video at low file
sizes.
• H.265 (HEVC): Short for High Efficiency Video Coding, it's the successor
to H.264. It often produces better quality video at smaller file sizes than
H.264.
• VP8: Open-sourced by Google, it's mainly used for short looping video
formats, as an alternative to GIFs.

17
Video
Compressio
n
Video Compression Formats

VP9: Invented by Google, VP9 is a free and open-source competitor to


H.265 and successor to VP8. It's ideal for streaming above Full HD video
but adoption is still slow.
AV1: Short for AOMedia Video 1, it's meant to be a successor to VP9.
Netflix is a major champion of this technology, recently rolling it out to its
TV video player.
FLV: Short for Flash Video, ‌made for use with Adobe Flash. Adobe stopped
supporting Flash due to security flaws in the software.

18
Video
Compressi
on
Application of Video Compression

 Cable TV distribution
 Interactive communications
 Digital storage media
 Video-on-demand
 Broadcasting

19
Video
Compression
Advantages of Video Compression

 Reduced File Size


 Faster Uploads and Downloads
 Improved Streaming Performance
 Cost Efficiency
 File transferring is faster

20
Video
Compression
Disadvantages of Video Compression

 Compilation need to be done again for compression


 Errors may occur while transmitting data
 The byte or pixel relationship is unknown
 Need to decompress the previous data

21
Video
Compression
Huffman Coding
Huffman coding is a lossless data compression technique widely used in image processing to
reduce the size of images while retaining all original information. It is especially effective in
scenarios where data has a skewed probability distribution, like grayscale images or image
histograms.

Steps of Huffman Coding:


Analyze Image Data: Compute the frequency of pixel intensities in the image.
Construct Huffman Tree: Build a binary tree where frequent values get shorter codes.
Generate Huffman Codes: Assign unique, prefix-free binary codes to each intensity.
Encode the Image: Replace pixel values with their corresponding Huffman codes.
Store/Transmit Data: Save or send the compressed data along with the Huffman tree.
Decode the Image: Reconstruct the image using the Huffman tree and compressed data.

22
Video
Compression
Example of Huffman Coding

23
Video
Compression
Golomb Coding
Golomb coding is a lossless data compression technique commonly used for encoding
sequences of integers. It is particularly efficient for data with a geometric distribution (i.e.,
when smaller values are more frequent). It works by dividing integers into two parts using a
divisor (also called a parameter, typically denoted as mmm) and then encoding each part
separately.

24
Video
Compression
Arithmetic Coding
Arithmetic coding is a lossless compression technique used to efficiently encode data by
representing entire messages as a single fractional number between 0 and 1. It is
particularly effective for image compression because it can achieve high compression
ratios by exploiting the statistical properties of image data.

Steps in Image Compression

Symbol Frequency Analysis:


For a grayscale image, count how often each pixel intensity (0–255) occurs.
Calculate probabilities, e.g., Pixel 0: 20%, Pixel 1: 50%, Pixel 2: 30%.

Construct Probability Intervals:


Pixel 0 → [0.0, 0.2)
Pixel 1 → [0.2, 0.7)
25
Video
Compression
LWZ Coding
For a sequence of pixel values [1, 2, 0]:
Pixel 1 → [0.2, 0.7).
Pixel 2 → Narrow to [0.56, 0.7).
Pixel 0 → Narrow to [0.56, 0.568).

Final Output:
Encode the interval [0.56, 0.568) as a single number, e.g., 0.565.

Decoding:
Reverse the process by mapping the number back through the probability intervals.

26
Video
Compression
LWZ Coding
LZW (Lempel-Ziv-Welch) coding is a lossless data compression algorithm widely used in
image file formats like GIF and TIFF. It is based on dictionary-based encoding, where
sequences of data are replaced with shorter codes that represent entire strings of symbols.

Steps in Image Compression with LZW


input image data: ABABABABA A: 1, B: 2
Read symbol sequences:
Sequence "A" → Output code 1.
Sequence "B" → Output code 2.
Sequence "AB" → Not in the dictionary → Add it as 3, output code 1.
Sequence "BA" → Not in the dictionary → Add it as 4, output code 2.
Continue similarly...
Compressed Output:
[1, 2, 3, 4]
27
Video
Compression
Run-Length Coding
Run-Length Coding (RLC) is a simple and effective lossless compression technique used to
compress data with repeating patterns, such as sequences of identical pixel values in
images. It works by replacing consecutive occurrences of a value (run) with a single value
and the count of its repetitions.
How Run-length Coding work:
Scan the Data: Traverse the image data row by row or pixel by pixel.
Identify Runs: Group consecutive identical pixel values into runs.
Encode Runs: Replace each run with a pair.
Store Compressed Data: Save the sequence of encoded pairs as the compressed output.
Decode for Reconstruction: Expand each pair back into the original sequence to decompress
the image.

28
Video
Compression
One Dimensional CCIT Compression
The CCITT (Consultative Committee for International Telephony and Telegraphy) 1D
compression method, also known as Modified Huffman Coding, is a lossless compression
technique commonly used for black-and-white images in fax transmission. It encodes binary
images (1-bit per pixel) by exploiting the frequent runs of black or white pixels.

Example of CCIT:

Input Binary Data: 0000000000111111111110000000


Runs:
White run: 10 pixels → Code: 0000110111
Black run: 9 pixels → Code: 0000011000
White run: 7 pixels → Code: 0000111000
Encoded Output: 0000110111 0000011000 0000111000

29
Video
Compression
Lossless Predictive Coding

Lossless predictive coding is a compression technique where the value of each pixel (or data point)
is predicted based on the values of neighboring pixels. The difference between the actual value
and the predicted value, called the residual (or error), is stored instead of the original value. Since
the residuals are often smaller and less variable, they can be compressed more efficiently.

Example:

Original Pixel Values: [100, 105, 110, 115, 120]


Prediction (Previous Pixel): [100 (first pixel), 100, 105, 110, 115]
Residuals: [100 - 0, 105 - 100, 110 - 105, 115 - 110, 120 - 115] = [100, 5, 5, 5, 5]
Reconstruction: [100, 100 + 5, 105 + 5, 110 + 5, 115 + 5] = [100, 105, 110, 115, 120]

30
Boundary
Extraction
Boundary Extraction

The boundary of set A, denoted by B(A ), can be


obtained by:
 Eroding A by a suitable structuring element B
 Performing the set difference between A and its erosion

The figure illustrates the mechanics of boundary extraction. Here


(a) Set, A, of foreground pixels.
(b) Structuring element.
(c) A eroded by B.
(d) Boundary of A.
Fig 1. Mechanics of boundary extraction

Reference: Digital_Image_Processing,_4th Edition-Rafael Gonzalez 31


Boundary
Extraction
Boundary Extraction

Figure 2 further illustrates the use of


Eq. using a 3x3 structuring element of
1’s.
 Foreground pixels (1’s) in white
 Background pixels (0’s) in black
 Boundary in Fig. 2 is one pixel thick

Fig 2(a). A binary Image Fig 2(b). Result of using


equation

Reference: Digital_Image_Processing,_4th Edition-Rafael Gonzalez 32


Hole
Filling
Hole Filling

Definition:
 A background region
 Surrounded by a connected border of foreground pixels.
Objective:
 Replace all background pixels (holes) with foreground pixels
 Ensuring the enclosed regions are completely filled.
For example:
 Let A denote a set whose elements are 8-connected boundaries
 With each boundary enclosing a background region (i.e., a hole).
 Given a point in each hole, the objective is to fill all the holes with foreground elements (1’s).

33
Hole
Filling
Hole Filling

Set 𝐴 (Fig. a):


The shaded region represents the hole to be
filled. This set 𝐴 is entirely enclosed by a
connected boundary of foreground pixels in the
image 𝐼 (Fig. b).
Complement of 𝐼 (Fig. b):
The complement of the image 𝐼 (background) is
calculated. This ensures that the dilation
operation does not extend beyond the boundary
of the hole.
Structuring Element 𝐵 (Fig. c): Fig 3(a) Set A (shown Fig 3(c)
Fig 3(b)
shaded) contained in Structuring
A small symmetric structuring element 𝐵 Compliment of I.
image I. element B.
(usually a 3×3 square with the center as the
origin) is defined. This element is used in the
dilation operation. Reference: Digital_Image_Processing,_4th Edition-Rafael Gonzalez 34
Hole Filling
Hole Filling

Initialization (Fig. d):


 X is an array of the same size as 𝐼.
 A single pixel inside the hole is set
to 1 to initialize the filling process.

Fig 3(d) Initial point


inside hole, set to 1.

35
Hole
Filling
Hole Filling

Fig 3(e)-(h). Various steps of the given equation.


36
Reference: Digital_Image_Processing,_4th Edition-Rafael Gonzalez
Hole
Filling
Hole Filling

Final Result (𝑋8​∪ I, Fig. i):


 The filled hole 𝑋8​is combined with the original image
𝐼 using a union operation (∪).
 The result is the original image with the hole
completely filled, including its boundary.

Fig 3(i) Final result [union of


(a) and (h)]

Reference: Digital_Image_Processing,_4th Edition-Rafael Gonzalez 37


Convex
Hull
Convex Hull

 A set A is said to be convex if any two elements can be joined by


a straight path and it does not go outside the set
 The convex hull 𝐻(𝑆) of a set 𝑆 is the smallest convex set that
contains 𝑆.
 The convex deficiency of 𝑆 is the difference between the convex
hull and the set: 𝐻(𝑆)−𝑆.

Reference: https://www.cis.rit.edu/class/simg782/lectures/lecture_04/lec782_05_04.pdf
38
Convex
Hull
Convex Hull

39
Convex
Hull
Convex Hull

40
Thinning
Thinning: Definition
 Thinning is a morphological operation that removes pixels from the boundaries of objects in a
binary image
 Thinning is a morphological operation applied to a set A of foreground pixels using a
structuring element B.
 It is defined using the hit-or-miss transform:
 A ⊗ B = A − (A ⊛ B) = A ∩ (A ⊛ B)^c

 To thin symmetrically, a sequence of structuring elements is used:


 {B} = {B^1, B^2, B^3, ..., B^n}

 The thinning process is applied iteratively as follows:


 A ⊗ {B} = (((A ⊗ B^1) ⊗ B^2) ...) ⊗ B^n

 This ensures symmetry in the thinning operation.

41
Thinning

Thinning

Fig : (a) Structuring elements. (b) Set A. (c) Result of thinning A with B1 (shaded). (d) Result of thinning A1 with B2.
(e)–(i) Results of thinning with the next six SEs. (There was no change between A7 and A8.) (j)–(k) Result of using
the first four elements again. (l) Result after convergence. (m) Result converted to m-connectivity.

42
Thinning

Thinning : Application
Character recognition (e.g., handwriting analysis).
Medical imaging (e.g., blood vessel detection).
Image analysis and pattern recognition.

43
Thickening
Thickening: Definition
 Thickening is the opposite of thinning. It adds pixels to the boundaries of
objects in a binary image.
 Thickening is the morphological dual of thinning and is defined as:
 A ⊙ B = A ∪ (A ⊛B)

 Thickening can also be expressed as a sequential operation:


 A ⊙ {B} = (((A ⊙ B^1) ⊙ B^2) ...) ⊙ B^n
 It is used to expand shapes while retaining their structure.

 Instead of using a separate algorithm, thickening is typically achieved by:


1. Complementing the set A to obtain A^c.
2. Thinning A^c using structuring elements.
3. Complementing the thinned set to produce the thickened result.

44
Thickening
Thickening

Fig : (a) Set A. (b) Complement of A. (c) Result of thinning the complement. (d) Thickened
set obtained by complementing (c). (e) Final result, with no disconnected points.

45
Thickening

Thickening : Application
Restoring objects after thinning in skeletonization.
Improving feature extraction where thicker objects are needed for
analysis.
Enhancing details in medical imaging or character recognition
systems

46
Skeleton

Skeleton: Definition

 Skeleton of a Set: The skeleton of a set A, denoted as S(A), is a simplified representation of A. It is


essentially a set of points that capture the shape and structure of A.

 Maximum Disk: A maximum disk is a disk centered at a point z in S(A) that is fully contained within A. It
is the largest such disk at that point.

 Skeleton Properties:
1.A point z belongs to S(A) if the maximum disk centered at z cannot be enlarged while still remaining
within A.
2 .A maximum disk touches the boundary of A at two or more points.

47
Skeleton

Skeleton

Skeleton Calculation:
 The skeleton can be calculated using a series of erosions and openings.

The skeleton is the union of subsets S_k(A), where k ranges from 0 to K.

Each S_k(A) is obtained by subtracting the opening of A by a structuring


element B from the erosion of A by repeated k times.

Fig: (a) Set A. (b) Various positions of maximum disks whose centers partially define the skeleton of A.
(c) Another maximum disk, whose center defines a different segment of the skeleton of A. (d) Complete
skeleton (dashed).

48
Skeleton

Skeleton : Application
 Character recognition (e.g., Optical Character Recognition or OCR).
 Medical imaging (e.g., for analyzing structures like blood vessels, bones, etc.).
 Shape analysis in machine vision or industrial inspection.

49
Pruning

Pruning: Definition
It refines binary images by removing unnecessary branches, often cleaning up skeletal structures.

Purpose: To clean up the skeleton by removing unwanted artifacts.

How it Works: It identifies and removes small, irrelevant branches from the skeletonized
image.

Fig: A binary image before and after pruning

50
Pruning

Pruning: Application
Optical Character Recognition (OCR).
Medical image analysis (e.g., blood vessel detection).
Feature extraction in machine vision

51
Dilation
Dilation

 Dilation adds pixels to the boundaries of objects in an image


 With A and B as sets in , the dilation of A by B, denoted is defined
as

52
Dilation
Example: Using dilation to repair broken characters in an image.

Fig: Image Fig: Dilation of A by B Fig: Elongated Fig: Dilation of A by


I SE this element.

53
Erosion
Erosion

 A morphological operation that shrinks the boundaries of objects in an


image.

 With A and B as sets in , the erosion of A by B, denoted A⊖ B ,is defined


as

 But B has to be contained in A is equivalent to B not sharing


any common elements with the background we can express
erosion equivalently as

54
Erosion
Example:Using erosion to remove image components.

Fig: Image I, Fig: Erosion of A Fig: Elongated SE Fig: Erosion of A


by B by B.

55
Opening
Opening

 Opening generally smoothes contour of the distorted image and fuse back
the narrow breaks and long thin gulfs.
 The opening of set A by structuring element B, denoted by is
defined as

 the opening of A by B is the union of all the translations of B such that B


fits entirely within A can be written in equation form as

where,
U denotes the union of the sets inside the braces

56
Opening
Example

Fig: Translations of B fig: Opening of A by B


Fig: Image Fig: Structuring
while being contained in A.
I element, B.

57
Closing
Closing

 Closing generally fuses narrow breaks and long thin gulfs,


eliminates small holes, and fills gaps in the contour.
 the closing of set A by structuring element B, denoted
is defined as
 The boundary of the closing is determined by the furthest
points B could reach without going inside any part of A.
we can write the closing of A by B as

58
Closing
Example

Fig: Translations of B fig: Closing of A by B


Fig: Image I Fig: Structuring such that B does not
element, B. overlap any part of A

59
Ref..
References
1. Gonzalez, Rafael. Digital Image Processing. 4th Edition.
2. "Digital Image Processing, 3rd Edition" [PDF]. Available at:
https://dl.ebooksworld.ir/motoman/Digital.Image.Processing.3rd.Edition.www.EBooksWorld.ir.pdf.
3. GeeksforGeeks. "Python Morphological Operations in Image Processing | Closing (Set-2)." Available at:
https://www.geeksforgeeks.org/python-morphological-operations-in-image-processing-closing-set-2/.
4. Scaler Topics. "Erosion and Dilation in Image Processing." Available at:
https://www.scaler.com/topics/erosion-and-dilation-in-image-processing/.
5. GetStream.io. "Video Compression Glossary." Available at: https://getstream.io/glossary/video-compression/.
6. ImageKit.io. "Video Compression Techniques." Available at: https://imagekit.io/blog/video-compression-techniques/.
7. K.D.K. College of Engineering. "Compression." Available at:
https://www.kdkce.edu.in/pdf/RAB-8ETRX-DCE-U3-COMPRESSION.pdf.
8. CIS Rochester Institute of Technology. "Lecture 4: Image Processing" [PDF]. Available at:
https://www.cis.rit.edu/class/simg782/lectures/lecture_04/lec782_05_04.pdf.
9. GeeksforGeeks. "Different Morphological Operations in Image Processing." Available at:
https://www.geeksforgeeks.org/different-morphological-operations-in-image-processing/.
10. GeeksforGeeks. "How to Find Interior and Exterior Skeleton of Binary Images Using MATLAB." Available at:
https://www.geeksforgeeks.org/how-to-find-interior-and-exterior-skelton-of-binary-images-using-matlab/.
11. The AI Learner. "Thinning and Thickening." Available at:
https://theailearner.com/2019/07/31/thinning-and-thickening/.

60
ACK.
Acknowledgements

We are grateful to
 Mahbubun Nahar ma’am (Course Teacher)
 Our classmates
 Our teachers of CSE, JKKNIU
 Department of CSE, JKKNIU

61
End
The End

62

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy