MMC Module3
MMC Module3
DEPARTMENT OF
ELECTRONICS AND COMMUNICATION ENGINEERING
Accredited by NBA, New Delhi
MULTIMEDIA COMMUNICATION
BEC613A
VI SEMESTER
MODULE 3 NOTES
Prepared by,
Mrs. MEGHANA M N
Assistant Professor
Dept. of ECE
MIT Thandavapura
DEPARTMENT OF
ELECTRONICS AND COMMUNICATION ENGINEERING
Accredited by NBA, New Delhi
MODULE 3 CONTENTS
• Introduction
• Compression principles
• text compression
• image Compression (Chapter 3 of Text1)
Text Book 1: Multimedia Communications –Fred Halsall, Pearson Education,2001,ISBN-978813170994
MODULE 3
TEXT AND IMAGE COMPRESSION
1. INTRODUCTION
• Compression: Compression in multimedia refers to the process of reducing the size of digital
multimedia files, which is first applied to the source information prior to its transmission.
• Compression is done to:
1. Reduce the volume of information to be transmitted text, fax, and images.
2. Reduce the bandwidth required for the transmission of speech, audio, and video.
2. COMPRESSION PRINCIPLES
• Based on the following compression principles there are 5 compression algorithms:
1. Source encoders and destination decoders
2. Lossless and lossy compression
3. Entropy encoding
4. Source encoding
Figure 1: Source encoder / destination decoder (a) Software only; (b) Special processor hardware
• Statistical encoding uses this property by using the set of variable length codewords with the shortest
codewords used to represent the most frequently occurring symbols.
• When variable-length codewords used in order for the decoding operation to be carried out correctly it
is necessary to ensure that a shorter codeword in the set does not form the start of a longer codeword
otherwise, the decoder will interpret the string on the wrong codeword boundaries.
• Prefix property in the codeword set avoids the above problem.
• Example of encoding scheme to use prefix property is Huffman encoding algorithm.
• The theoretical minimum average number of bits that are required to transmit a particular source
stream is known as the Entropy of the source and computed using Shannon formula:
#
𝐸𝑛𝑡𝑟𝑜𝑝𝑦: 𝐻 = − , 𝑃! 𝑙𝑜𝑔" 𝑃!
!$%
, 𝑁! 𝑃!
!$%
• Efficiency is calculated by ratio of the entropy of the source to the average number of bits per
codeword.
1 PROBLEM
A statistical encoding algorithm is being considered for the transmission of a large number of long text
files over a public network. Analysis of the file contents has shown that each file comprises only the six
different characters M, F, Y, N, 0, and 1 each of which occurs with a relative frequency of occurrence of
0.25, 0.25, 0.125, 0.125, 0.125, and 0.125 respectively. If the encoding algorithm under consideration uses
the following set of codewords:
M = 10, F = 11, Y= 010, N = 011, 0 = 000, 1 = 001
compute:
(i) the average number of bits per codeword with the algorithm,
(i) the entropy of the source,
(iii) the minimum number of bits required assuming fixed-length codewords.
Solution:
(i) Average number of bits per codeword is given by:
# &
𝐻 = − ∑#!$% 𝑃! 𝑙𝑜𝑔" 𝑃! = − ∑&!$% 𝑃! 𝑙𝑜𝑔" 𝑃! = − B220.25 𝑙𝑜𝑔" (0.25)> + 4(0.125 𝑙𝑜𝑔" (0.125)C =
2.5
(iii) Since there are 6 different characters, using fixed-length code-words would require a
minimum of 3 bits (8 combinations).
(b)
Figure 2: Transform coding: (a) Example pixel pattern (b) DCT transform principles
• Spatial frequency is a rate of change in magnitude as one traverses the matrix. For any particular
image, there will be a mix of different spatial frequencies whose amplitudes are determined by the
relate changes in magnitude of the pixels.
• It is true if, matrix been scanned in either, the horizontal or vertical direction, which provides the
horizontal and vertical frequency components of the image.
• In practice, Human eye is less sensitive to the higher spatial frequency components associated with an
Downloaded by Nimisha Alex (alexnimisha1997@[Link])
lOMoARcPSD|58243556
3. TEXT COMPRESSION
• 3 different types of text – Unformatted, formatted and hypertext are represented as strings of
characters from selected a defined set of strings and alphanumeric characters are distributed with
additional control characters.
• Since compression algorithm involved with the text must be lossless, Entropy encoding (statistical
encoding) methods are used compression.
• Statistical encoding method: There are 2 types of coding used for texts:
1. Use single character as the basis of deriving an optimum set of codewords.
Ex.: Huffman and arithmetic coding algorithm
2. Use variable-length strings of characters
Ex.: Lempel-Ziv (LZ) algorithm
• There are 2 types of coding of text:
1. Static coding: Using static coding an optimum set of variable length codewords is derived with
the shortest codewords used to have more frequently occurring characters. Using this information,
instead of using fixed-length codewords, an optimum set of variable-length codewords is derived
with the shortest codewords used; to represent the most frequently occurring characters. The
resulting set of codewords are then used for all subsequent transfers involving this particular type
of text. This approach is known as static coding.
2. Dynamic coding (adaptive coding): optimum set of codewords likely to vary from one transfer to
another. To allow for this possibility, the codeword set that is used to transfer a particular text
Downloaded by Nimisha Alex (alexnimisha1997@[Link])
lOMoARcPSD|58243556
string is derived as the transfer takes place. This is done by building up knowledge of both the
characters that are present in the text and their relative frequency of occurrence dynamically as the
characters are being transmitted. This approach is known as dynamic or adaptive coding.
• Text compression algorithms using statistical encoding technique are as follows:
1. Static Huffman coding
2. Dynamic Huffman coding
3. Arithmetic coding
4. Lempel-Ziv coding
5. Lempel-Ziv-Welsh coding
(a)
(b)
Figure 3: Huffman tree code construction (a) Final tree with codes (b) Tree derivatives
• To illustrate how the Huffman code tree in Figure 3(a) is determined, we must calculate the frequency
of occurrence of each character.
• Figure 3(b) shows the characters listed in a column in decreasing (weight) order. We derive the tree as
follows:
Ø The first two leaf nodes at the base of the list - Cl and D1 - are assigned to the (1) and (0)
branches respectively of a branch node.
Ø The two-leaf node are then replaced by a branch node whose weight is the sum of the weights of
the two leaf nodes ie. 2.
Ø A new column is then formed containing the new branch node combined with the remaining
nodes from the first column, again arranged in their correct weight order. This procedure is
repeated until only two nodes remain.
• To derive the resulting codewords for each character, we start with the character in the first column
and then proceed to list the branch numbers. 0 or 1 - as they are encountered. Thus, for character A the
first (and only) branch number is (1) in the last column while for C the first is (1) then (0): branch
node 2 and finally (0) at branch node 4.
• The actual codewords, however, start at the root and not the leaf node hence they are the reverse these
bit sequences. The Huffman tree can then be readily constructed from the set of codewords.
• Table of codewords are available at the receiver and also had corresponding ASCII codeword received
bit stream is held in the variable BIT-STREAM.
• Variable CODEWORD are used to hold the bits in each codeword while it is being constructed.
• From the flow chart as shown in figure 4, once the codeword is identified corresponding ASCII
codeword is written into the variable RECEIVE_BUFFER.
• Procedure - repeats until all the bits in the received string have been processed.
1 PROBLEM
A series of message is to be transferred between two computers over a PSTN. The message comprises
just the character A to H with the probability of each character is as follows: A, B = 0.25, C, D
=0.14, E, F, G and H= 0.055.
a) Use Shannon’s formula to derive the minimum average number of bits per character.
b) Use Huffman coding to derive a codeword set.
c) Derive the average number of bits per codeword set and compare it with
1. Entropy of the message
Downloaded by Nimisha Alex (alexnimisha1997@[Link])
lOMoARcPSD|58243556
Solution:
a) Shannon’s formula states:
Entropy: 𝐻 = − ∑(!$% 𝑃! 𝑙𝑜𝑔" 𝑃! 𝑏𝑖𝑡𝑠 𝑝𝑒𝑟 𝑐𝑜𝑑𝑒𝑤𝑜𝑟𝑑
H = - (2(0.25 log2 0.25) + 2(0.14 log2 0.14) + 4(0.055 log2 0.055))
H = 2.714 bits per codeword
(b)
Requirement
• Copy of the dictionary is held by both the encoder and the decoder standard word processing package
to be used.
• For transmission of text can be relatively inefficient if the text to be transmitted comprises only a
small subset of the words stored in the dictionary.
1 PROBLEM
The LZ algorithm is to be used to compress a text file prior to its trans-mission. If the average number
of characters per word is 6, and the dictionary used contains 4096 words, derive the average
compression ratio that is achieved relative to using 7-bit ASCIl codewords.
Solution:
• In general, a dictionary with an index of n bits can contain up to 2n entries. Now 4096 = 212 and hence
an index of 12 bits is required.
• Using 7-bit ASCIl codewords and an average of 6 characters per word requires 7 * 6 = 42 bits.
• Hence the first word in the example text is sent by the encoder using the index of each of the four
characters T, h, i, and s.
• At this point, when the encoder reads the next character from the string - the first space (SP) character -
it determines that this is not an alphanumeric character.
• Similarly, the decoder, on receipt of the first indices/codewords, reads the character stored at each
index and commences to reconstruct the text.
• When it determines that the fifth character is a space character, it interprets this as a word delimiter and
proceeds to store the word This in its dictionary. The content in the dictionary of encoder and decoder
is as shown in the figure 6 (a).
• For example, in an application that uses 128 characters in the basic character set, then both the encoder
and decoder would start with, say, 256 entries in the dictionary. This requires an index/codeword
length of 8 bits and the dictionary would provide space for the 128 characters in the character set and a
further 128 locations for words that occur in the text.
• Should this number of locations become insufficient, on detecting this the encoder and decoder would
double the size of their dictionary to 512 locations. Clearly, this necessitates an index length of 9 bits
codewords.
• The procedure is shown in diagrammatic form in Figure 6 (b). In this example it is assumed that the
last entry in the existing table at location 255 is the word fish and the next word in the text that is not
currently in the dictionary is pond.
Figure 6: LZW compression algorithm (a)Basic operation (b) Dynamically extending the no. of entries in the dictionary
4. IMAGE COMPRESSION
• Images can be:
Ø Computer generated graphical images
Ø Digitized Images
Figure 7: GIF compression principles (a)Basic operational mode (b) Dynamic mode using LZW coding
• GIF allows the image transfer over the network in an interlaced mode.
• This can be used to transfer images over either low bit rate channels or the Internet which provides a
variable transmission rate.
• From this the compressed image data is organized, so that decompressed image is built up in a
progressive way as the data arrives this is done by dividing the compressed data by 4 groups as shown
in figure 8:
1. Contains 1/8 of total compressed image data
2. Contains a further 1/8
3. Contains a further 1/4
4. Contains the last remaining 1/2
Ø Optional feature for Group 3 facsimile machines when used here, EOL code at the end of each
(compressed) line has an additional tag bit added.
Ø If, it is a binary 1, then the next line has been encoded using T4 coding scheme.
Ø If, it is a binary 0, then the next line has been encoded using T6 coding scheme (known as MMR
coding). 2-D coding: Alternative name is MMR coding (Modified Modified READ coding) since,
it identifies black and white run-lengths by comparing adjacent scan lines.
• T4 and T6:
Ø Use data compression technique with the compression ratios in excess of 10:1 are common with
most document pages.
Ø There are 2 tables of codewords produced based on the relative frequency of occurrence of the
number of contiguous white and black pels found in a scanned line.
1. Termination-codes table: contains codeword for white or black run-lengths of from 0 to 63
pels in steps of 1 pel.
2. Make-up codes table: contains codewords for white or black run-lengths that are multiples of
64 pels.
• Over scanning technique used in which all lines start with a minimum of one white pel so, here
receiver knows the first codeword always relates to white pels and then alternates between black and
white.
• EOL (End-of-line) code is used to enable the receiver to regain synchronism each scanned line is
transmitted with EOL code.
• It is known as 2D coding scheme since it identifies black and white run-lengths by comparing adjacent
scan lines.
• READ stands for Relative Element Address Designated and is the modified version of earlier scheme.
• It uses the fact that most scanned lines differ from the previous line by only a few pels.
• Ex.: If a line contains a black-run hen the next line will normally contain the same run plus or minus
up to 3 pels.
• Run-lengths associated with a line are identified by comparing the line contents known as coding line
(CL) with the immediately Preceding line is known as the reference line (RL).
• Assumption: First reference line is assumed to be an imaginary all-white line and the first lien proper
is encoded relative to this.
• Run lengths associated with a coding line can be identified as one of 3 possibilities of modes relative
to the reference line.
• 3 modes are identified by the position of the next run-length - in the reference line (b1b2) relative to
the start and end of the next pair of run-lengths in the coding line (a0a1 and a1a2).
• The 3 modes are:
1. Pass mode
2. Vertical mode
3. Horizontal mode
1. Pass mode
• Run-length in the reference line (b1b2) is to the left of the next run-length in the coding line (a1a2)
i.e., b2 is to the left of a1.
• For this mode - run-length b1b2 is coded using the codewords. It is as shown in figure 9(a).
2. Vertical mode
• Run-length in the reference line (b1b2) overlaps the next run-length in the coding line (a1a2) by a
maximum of plus or minus 3 pels.
• For this mode just the difference run-length a1b1 is coded Most codewords are in this category. It is as
shown in figure 9(b).
3. Horizontal mode
• Run-length - in the reference line (b1b2) overlaps the run-length (a1a2) by more than plus or minus 3
pels.
• For this mode two run-lengths a0a1 and a1a2 are coded using the codewords. It is as shown in figure
9(c).
Figure 9: Run-length possibilities: (a) Pass mode. (b) Vertical mode. (c) Horizontal mode.
• A flowchart of the coding procedure is shown in Figure 10. The first a0 is set to an imaginary white
pel before the first pel of the line and hence the first a0a1, run-length will be a0a1 - 1.
• If during the coding of a line a1, a2, b1, or b2 are not detected, then they are set to an imaginary pel
positioned immediately after the last pel on the respective line.
• Once the first/next position of a0 has been determined, the positions of a1, a2, b1 and b2 for the next
codeword are located.
• The mode is then determined by computing the position of b2 relative to a1. If it is to the left, this
indicates pass mode.
• If it is not to the left, then the magnitude of a1 b1 is used to determine whether the mode is vertical or
horizontal.
• The codeword for the identified mode is then computed and the start of the next codeword position, a0
updated to the appropriate position.
• This procedure repeats alternately between white and black runs until the end of the line is reached.
• This is an imaginary pel positioned immediately after the last pel of the line and is assumed to have a
different color from the last pel.
• The current coding line then becomes the new reference line and the next scanned line the new coding
line.
2. Forward DCT
• Normally, each pixel value is quantized using 8 bits which produces a value in the range 0 to 255 for
the intensity/luminance values - R, G, B, or Y and a value in the range -128 to +127 for the two
chrominance values - Cb and Cr.
• In order to compute the (forward) DCT, however, all the values are first centered around zero by
subtracting 128 from each intensity/luminance value.
• Then, if the input 2D matrix is represented by: P[x, y] and the transformed matrix by F[i, j], the DCT of
each 8 x 8 block of values is computed using the expression:
) )
1 (2𝑥 + 1)𝑖𝜋 (2𝑦 + 1)𝑗𝜋
𝐹 [𝑖, 𝑗] = 𝑐(𝑖)𝑐(𝑗) ,. , 𝑃[𝑥, 𝑦]𝑐𝑜𝑠 . 𝑐𝑜𝑠
4 16 16
*$+ ,$+
3. Quantization
• Quantization is the process of mapping continuous or large sets of values to a smaller, discrete set of
values.
• The JPEG standard includes two default quantization table values: one for use with the luminance
coefficients and the other for use with the two sets of chrominance coefficients it also allows for
customized table to be used and sent with the compressed image.
4. Entropy encoding
• The entropy encoding stage comprises 4 steps: vectoring, differential encoding, run-length encoding,
and Huffman encoding.
1. Vectoring: The various entropy encoding algorithms operate on a 1D string of values. Hence before
we can apply any entropy encoding to the set of values in the matrix, we must first represent the
values in the form of a 1D vector. This operation is known as vectoring. If we scanned the matrix
using a line-by-line approach, the presence of the large number of zeros in the quantized matrix, a
zig-zag scan of the matrix is used.
2. Differential encoding: The most efficient type of compression with the information structure is
differential encoding since this encodes only the difference between each pair of values in a string
rather than their absolute values.
3. Run-length encoding: To exploit this feature, the AC coefficients are encoded in the form of a string
of pairs of values. Each pair is made up of (skip, value) where skip is the number of zeros in the run
and value the next non-zero coefficient. Also, that the value field is encoded in the form SSS/ value.
4. Huffman encoding: when we described the encoding of digitized documents, significant levels of
compression can be obtained by replacing long strings of binary digits by a string of much shorter
codewords, the length of each codeword being a function of its relative frequency of occurrence.
Normally, a table of codewords is used with the set of codewords precomputed using the Huffman
coding algorithm.
5. Frame building
• The role of the frame builder is to encapsulate all the information relating to an encoded image/picture
in the frame format is hierarchical. At the top level, the complete frame-plus-header is encapsulated
between a start-of-frame and an end-of-frame delimiter which allows the receiver to determine the start
and end of all information relating to a complete image / picture.
• The frame header contains a number of fields that include:
Ø The overall width and height of the image in pixels
Ø The type of components that are used to represent the image (CLUT, R/G/B, Y/ Cb/Cr)
Ø The digitization format used (4:2:2, 4:2:0)
• At the second level, a frame consists of a number of components each of which is known as a scan.
These are also preceded by a header which contains fields that includes:
Ø The identity of the components (R/G/B)
Ø the number of bits used to digitize each component
Ø The quantization table of values that have been used to encode each component.
• Hence the time to carry out the decoding function is similar to that used to perform the encoding.
• On receipt of the encoded bitstream the frame decoder first identifies the control information and tables
within the various headers.
• It then loads the contents of each table into the related table and passes the control information to the
image builder.
• It then starts to pass the compressed bitstream to the Huffman decoder which carries out the
corresponding decompression operation using either the default or the preloaded table of codewords.
• The two decompressed streams containing the DC and AC coefficients of each block are then passed to
the differential and run-length decoders respectively.
• The resulting matrix of values is then dequantized using either the default or the preloaded values in the
quantization table.
• Each resulting block of 8 x 8 spatial frequency coefficients is passed in turn to the inverse DCT which
transforms them back into their spatial form using the expression:
) )
1 (2𝑥 + 1)𝑖𝜋 (2𝑦 + 1)𝑗𝜋
𝐹 [𝑖, 𝑗] = 𝑐(𝑖)𝑐(𝑗) ,. , 𝑃[𝑥, 𝑦]𝑐𝑜𝑠 . 𝑐𝑜𝑠
4 16 16
*$+ ,$+
• The image builder then reconstructs the original image from the blocks using the control information
passed to it by the frame decoder.
• Finally, as with the GIF, it is also possible to encode and rebuild the images in a progressive way by
first sending an outline of the image and then progressively adding more detail to it.
• This can be achieved in the following ways:
1. progressive mode: in this mode, first the DC and low-frequency coefficients of each block are sent
and then the higher-frequency coefficients.
2. Hierarchical mode: in this mode, the total image is first sent using a low resolution - for example
320 x 240 then at a higher resolution such as 640 x 480.
signal, Y.
• The four alternative forms of representation are shown in Figure 13.
Figure 13: Image/block preparation (a) Image preparation (b) Block preparation
• Once the source image format has been selected and prepared, the set of values in each matrix are
compressed separately using the DCT.
• Before performing the DCT on each matrix, however, a second step known as block preparation is
carried out.
• This is necessary since to compute the transformed value for each position in a matrix requires the
values in all the locations of the matrix to be processed.
• It would be too time consuming to compute the DCT of the total matrix in a single step so each matrix
is first divided into a set of smaller 8 x 8 submatrices.
• Each is known as a block and, as we can see in part (b) of the figure, these are then fed sequentially to
the DCT which transforms each block separately.
FORWARD DCT
• Normally, each pixel value is quantized using 8 bits which produces a value in the range 0 to 255 for
the intensity/luminance values - R, G, B, or Y and a value in the range -128 to +127 for the two
chrominance values - Cb and Cr.
• In order to compute the (forward) DCT, however, all the values are first centered around zero by
subtracting 128 from each intensity/luminance value.
• Then, if the input 2D matrix is represented by: P[x, y] and the transformed matrix by F[i, j], the DCT of
each 8 x 8 block of values is computed using the expression:
) )
1 (2𝑥 + 1)𝑖𝜋 (2𝑦 + 1)𝑗𝜋
𝐹 [𝑖, 𝑗] = 𝑐(𝑖)𝑐(𝑗) ,. , 𝑃[𝑥, 𝑦]𝑐𝑜𝑠 . 𝑐𝑜𝑠
4 16 16
*$+ ,$+
QUANTIZATION
• Quantization is the process of mapping continuous or large sets of values to a smaller, discrete set of
values.
• The JPEG standard includes two default quantization table values: one for use with the luminance
coefficients and the other for use with the two sets of chrominance coefficients it also allows for
customized table to be used and sent with the compressed image.
• An example set of threshold values is given in the quantization table shown in Figure 14 together with
set of DCT coefficients and their corresponding quantized values.
• The computation of the quantized coefficients involves rounding the quotients to the nearest integer
value.
• The threshold values used, in general, increase in magnitude with increasing spatial frequency.
• The DC coefficient in the transformed matrix is largest.
• Many of the higher frequency coefficients are zero.
ENTROPY ENCODING
• The entropy encoding stage comprises 4 steps: vectoring, differential encoding, run-length encoding,
and Huffman encoding.
1. Vectoring: The various entropy encoding algorithms operate on a 1D string of values, that is, a
vector. The output of the quantization stage is a 2D matrix of values. Hence before we can apply any
entropy encoding to the set of values in the matrix, we must first represent the values in the form of
a 1D vector. This operation is known as vectoring. If we scanned the matrix using a line-by-line
approach, the presence of the large number of zeros in the quantized matrix, a zig-zag scan of the
matrix is used as shown in Figure 15.
2. Differential encoding: The most efficient type of compression with the information structure is
differential encoding since this encodes only the difference between each pair of values in a string
rather than their absolute values. Hence in this application, only the difference in magnitude of the
DC coefficient in a quantized block relative to the value in the preceding block is encoded. In this
way, the number of bits required to encode the relatively large magnitudes of the DC coefficients is
reduced.
For example, if the sequence of DC coefficients in consecutive quantized blocks one per block was:
12, 13, 11, 11, 10, ...
the corresponding difference values would be:
12, 1, -2, 0, -1, ...
the first difference value always being encoded relative to zero. The difference values are then
encoded in the form (SSS, value) where the SSS field indicates the number of bits needed to encode
the value and the value field the actual bits that represent the value.
3. Run-length encoding: The remaining 63 values in the vector are the coefficients and, because of
the zig-zag scan, the vector contains long strings of zeros Within it. To exploit this feature, the AC
coefficients are encoded in the form of a string of pairs of values. Each pair is made up of (skip,
value) where skip is the number of zeros in the run and value the next non-zero coefficient. Hence
the 63 values in the vector would be encoded as:
(0,6) (0,7) (0,3) (0,3) (0,3) (0,2) (0,2) (0,2) (0,2) (0,0)
Note that the final pair (0,0) indicates the end of the string for this block and that all the remaining
coefficients in the block are zero. Also, that the value field is encoded in the form SSS/ value.
4. Huffman encoding: when we described the encoding of digitized documents, significant levels of
compression can be obtained by replacing long strings of binary digits by a string of much shorter
codewords, the length of each codeword being a function of its relative frequency of occurrence.
Normally, a table of codewords is used with the set of codewords precomputed using the Huffman
coding algorithm. The same approach is used to encode the output of both the differential and run-
length encoders.
FRAME BUILDING
• The JPEG standard includes a definition of the structure of the total bitstream relating to a particular
image/picture. This is known as a frame and its outline structure is shown in Figure 16.
• The role of the frame builder is to encapsulate all the information relating to an encoded image/picture
in the frame format is hierarchical. At the top level, the complete frame-plus-header is encapsulated
between a start-of-frame and an end-of-frame delimiter which allows the receiver to determine the start
and end of all information relating to a complete image / picture.
• The frame header contains a number of fields that include:
Ø The overall width and height of the image in pixels
Ø The type of components that are used to represent the image (CLUT, R/G/B, Y/ Cb/Cr)
Ø The digitization format used (4:2:2, 4:2:0)
• At the second level, a frame consists of a number of components each of which is known as a scan.
These are also preceded by a header which contains fields that includes:
Ø The identity of the components (R/G/B)
Ø the number of bits used to digitize each component
Ø The quantization table of values that have been used to encode each component.
Refer class notes for all problem from image block preparation to run-length coding