S2-11_EAZC473_ Lossless Image Compression

download S2-11_EAZC473_ Lossless Image Compression

of 12

Transcript of S2-11_EAZC473_ Lossless Image Compression

  • 8/2/2019 S2-11_EAZC473_ Lossless Image Compression

    1/12

    WILP S2-11_EAZC473 Forums General Discussion Forum lossless image compression

    lossless ima ge comp ressionby KALLURI RAJESH . - Monday, 2 April 2012, 04:53 PM

    Friends,

    There is a repeated question in old question papers to apply lossless image compression on a

    table using predictor p6.

    I wasted around 3 hours to find some worked out solution but in vain ...

    if any body have some link please share with me ...

    Any body can solve the problem

    apply lossless image compression using predictor 6 for the table

    10 10 15

    10 15 20

    15 20 25

    Please solve ... its very imp guyz ...

    Reply

    Re: lossless image compre ssionby KALLURI RAJESH . - Tuesday, 3 April 2012, 12:29 PM

    any inputs ?

    Show parent | Reply

    Re: lossless imag e compr essionby SRIRAM R . - Tuesday, 3 April 2012, 12:40 PM

    http://taxila.bits-pilani.ac.in/mod/forum/discuss.php?d=4735

    follow this forum, should be the same way i guess !!!

    Show parent | Reply

    Re: lossless image compre ssionby ABHAY DUTT PAROHA . - Tuesday, 3 April 2012, 01:02 PM

    As per my understanding

    This question is related to lossless mode of JPEG (different from baseline JPEG).

    Steps to follow

    _EAZC473: lossless image compression http://taxila.bits-pilani.ac.in/mod/forum/discuss.php

    2 05-04-20

  • 8/2/2019 S2-11_EAZC473_ Lossless Image Compression

    2/12

    1. Predictor

    2. Entropy Encoding

    Predictor

    1. For each pixel a predictor (one of 7 possible) is used that best predicts the value

    contained in the pixel as a combination of up to 3 neighbouring pixels.

    2. The difference between the predicted value and the actual value (X) contained in the

    pixel is used as the predictive difference to represent the pixel.

    3. The predictor along with the predictive difference are encoded as the pixel's content.

    4. The series of pixel values are encoded using Huffman Coding.

    P1 A

    P2 B

    P3 C

    P4 A+B+C

    P5 A+floor[(B-C)/2]

    P6 B+floor[(A-C)/2]

    P7 floor[(A+B)/2]

    Structure (pixel structure)

    P P P P PP C B P P

    P A X P P

    P P P P P

    P P P P P

    A. The first pixel (0,0) will always use itself.

    B. Pixels at the first row always use P1.

    C. Pixel at the first column always use P2.

    D. The best of the 7 predictions is always chosen for any pixel

    So our image would be after predictor P6 (I am not sure about this...please verify once)P6 = B+floor[(A-C)/2]

    10 10 10

    10 10 17

    10 17 22

    then use entropy coding.

    Hope, I am clear.

    Show parent | Reply

    Re: lossless imag e compr essionby KALLURI RAJESH . - Tuesday, 3 April 2012, 02:12 PM

    Abhay,

    thank you ...

    i understand the procedure but only lack of confidence ... thats why i posted ... now i

    feel i am in correct line ..

    @sriram

    This is different sriram ...

    _EAZC473: lossless image compression http://taxila.bits-pilani.ac.in/mod/forum/discuss.php

    2 05-04-20

  • 8/2/2019 S2-11_EAZC473_ Lossless Image Compression

    3/12

    Show parent | Reply

    Re: lossless image compressionby ABHAY DUTT PAROHA . - Tuesday, 3 April 2012, 02:23 PM

    Hey Rajesh...I am not sure..same case with me also.. ..lack of confidence...Can

    u pls verify my procedure......Can u post some steps of Entropy Encoding after

    this?

    I think, w e cant apply entropy coding ( w hich w e use with DCT based

    compre ssion) because tha t encoding use DC ( predictive difference) and

    AC coefficients (Run length coding)

    Show parent | Reply

    Re: lossless image compr essionby SRIRAM R . - Tuesday, 3 April 2012, 02:50 PM

    Thank God. Guys i owe u all a drink !!

    Show parent | Reply

    Re: lossless imag e com pressionby ABHAY DUTT PAROHA . - Tuesday, 3 April 2012, 03:23 PM

    Hey Sriram... ...

    Can u explain

    entropy coding (w hich w e use w ith DCT based compression)

    for lossless JPEG ?

    Show parent | Reply

    Re: lossless image compr essionby TORTHI SUSMITHA . - Tuesday, 3 April 2012, 03:37 PM

    I suppose, we have to find out the difference matrix between the original

    matrix and the matrix obtained after applying prediction, find out the

    frequency of the characters in the resultant matrix and just apply huffman

    coding on that.

    Correct me if i am wrong.

    Show parent | Reply

    Re: lossless imag e com pression

    by KALLURI RAJESH . - Tuesday, 3 April 2012, 05:21 PM

    @torthi

    process is correct ... but here confusion is how to calculate the

    predicted matrix ... please share if you know

    @abhay

    i also got the same answer ... As per my understanding no need to

    apply any dc encoding ... but for ac coefficients, we can do zigzag scan

    and apply run length encoding (as said in text book ... i did not

    remember the procedure) ...

    _EAZC473: lossless image compression http://taxila.bits-pilani.ac.in/mod/forum/discuss.php

    2 05-04-20

  • 8/2/2019 S2-11_EAZC473_ Lossless Image Compression

    4/12

    Show parent | Reply

    Re: lossless imag e compr essionby TORTHI SUSMITHA . - Tuesday, 3 April 2012, 07:48 PM

    Okay.

    Here is my understanding..

    We need to apply lossless image compression using P6 on thebelow matrix

    10 10 15

    10 15 20

    15 20 25

    For P-6 predictor, the prediction is B+(A-C)/2

    Neighboring pixels in a lossless JPEG are assumed to be as given

    below

    ---|---|---|---|---

    | | C | B |

    ---|---|---|---|---

    | | A | X |

    ---|---|---|---|---

    So if you want to predict value for an element at X, we consider its

    neighboring pixels in the above form

    Now, in the matrix, say M, given,

    10 10 15

    10 15 20

    15 20 25

    If you consider element at (0,0) no A,B,C exists... hence this value

    doesnt change

    for element at

    (0,1) -> A=10, B and C dont exist --> apply the formula

    B+(A-C)/2, X value is 10/2=5

    (0,2) -> A=10, B and C dont exist -> X=10/2 = 5

    For elements at position

    (1,0) -> A and C don't exist, B=10 -> X=10

    (2,0) -> A and C don't exist, B=10 -> X=10

    (1,1) -> A=10, B=10, C=10 -> X= 10 + (10-10)/2 = 10(1,2) -> A=15, B=15, C=10 -> X= 15 + (15-10)/2 = 15 + 2.5 =

    17.5

    (2,1) -> A=15, B=15, C=10 -> X= 15 + (15-10)/2 = 17.5

    (2,2) -> A=20, B=20, C=15 -> X= 20 + (20-15)/2 = 20 + 2.5 =

    22.5

    So the predictor matrix , say P, will be

    10 5 5

    10 10 17.5

    _EAZC473: lossless image compression http://taxila.bits-pilani.ac.in/mod/forum/discuss.php

    2 05-04-20

  • 8/2/2019 S2-11_EAZC473_ Lossless Image Compression

    5/12

    10 17.5 22.5

    Now, my understanding is, we have to find the difference between

    M and P

    M-P gives, (not sure whether floor / ceil function is needed for

    decimal values)

    0 5 10

    0 5 2.5

    5 2.5 2.5

    and, we have to apply Huffman coding on the above matrix,

    considering the frequency of each character.

    0 --> freq = 2

    5 --> freq = 3

    2.5 --> freq = 3

    10 --> freq = 1

    I am not confident about the above step.. someone please confirm

    !!

    This is my understanding--- please let me know if i didnot

    understand the algorithm properly

    Show parent | Reply

    Re: lossless image compressionby ABHAY DUTT PAROHA . - Tuesday, 3 April 2012, 11:40 PM

    We need to apply lossless image compression using P6 on the

    below table - M

    10 10 15

    10 15 20

    15 20 25

    For P-6 predictor, the prediction is B+ f loor [ (A-C) / 2 ]

    ---|---|---|---|---

    | | C | B |

    ---|---|---|---|---

    | | A | X |

    ---|---|---|---|---

    Rules are below (I think, we need to apply below rulesduring our calculations)

    A. The first pixel ( 0,0 ) w ill alw ays use itself.

    B. Pixels at the first row alw ays use P1.

    C. Pixel at t he first colum n alw ays use P2.

    D. The best of the 7 pr edictions is alw ays chosen for any

    pixel

    P1 A

    P2 B

    _EAZC473: lossless image compression http://taxila.bits-pilani.ac.in/mod/forum/discuss.php

    2 05-04-20

  • 8/2/2019 S2-11_EAZC473_ Lossless Image Compression

    6/12

    P3 C

    P4 A+B+C

    P5 A+floor[(B-C)/2]

    P6 B+floor[(A-C)/2]

    P7 floor[(A+B)/2]

    So, the Predicator Table is - P

    10 10 10

    10 10 17

    10 17 22

    Difference : M-P

    0 0 5

    0 5 3

    5 3 3

    Huffman Coding

    Count(0) = 3

    Count(3) = 3Count(5) = 3

    Torthi..Can you please confirm? (I used rules also, that's why

    I am getting different matrix for P)

    Show parent | Reply

    Re: lossless image compr essionby TORTHI SUSMITHA . - Wednesday, 4 April 2012, 12:17 AM

    Hi,

    Are you sure we have to apply P1 and P2 on first row and

    first column always ???

    I was in an assumption that when P-6[=B+(A-C)/2] is

    used,

    for first row , the predicted values will be A/2

    for first column, the predicted values will be B (u can say

    P2)

    this is wat i understood from the text book..

    Please share the source where these rules are

    mentioned.. i haven't come across anything like this inthe text book... or not sure if i had missed that point...

    Also, are you sure, we have to use the FLOOR of the

    value ??

    btwn... i m Susmitha, Torthi is my surname.. ;)

    Show parent | Reply

    _EAZC473: lossless image compression http://taxila.bits-pilani.ac.in/mod/forum/discuss.php

    2 05-04-20

  • 8/2/2019 S2-11_EAZC473_ Lossless Image Compression

    7/12

    Re: lossless imag e com pressionby ABHAY DUTT PAROHA . - Wednesday, 4 April 2012, 09:45 AM

    Hi Sushmitha,

    I was assuming ur name as Torthi.. ...

    Here are the links

    Simon Fraser University Lectures

    http://www.cs.sfu.ca/CourseCentral/365/mark

    /material/notes/Chap4/Chap4.2/Chap4.2.html

    http://www.ecpe.nu.ac.th/paisarn/Multimedia/week2

    /M4L1.pdf

    http://www.technicaljournalsonline.com

    /jers/past%20issue/swapnillahudkar.pdf

    http://www.cs.clemson.edu/~jzwang/1201863

    /cpsc86303.pdf

    Can you please mention the text book where you

    read this?

    I am 100% sure about FLOOR value..

    Show parent | Reply

    Re: lossless ima ge compr essionby TORTHI SUSMITHA . - Wednesday, 4 April 2012, 09:50

    AM

    Cool...

    thanks a lot for the info...

    i was referring to T1 - prescribed text book..

    not sure if these points were mentioned there.. i

    dont remember reading these rules in the text

    book..

    Show parent | Reply

    Re: lossless image compressionby ABHAY DUTT PAROHA . - Wednesday, 4 April 2012,

    10:21 AM

    I came across one example also

    Source

    Image and video compression standards: algorithms

    and architectures

    By Vasudev Bhaskaran, Konstantinos

    Konstantinides

    _EAZC473: lossless image compression http://taxila.bits-pilani.ac.in/mod/forum/discuss.php

    2 05-04-20

  • 8/2/2019 S2-11_EAZC473_ Lossless Image Compression

    8/12

    Concept

    The prediction residual is computed modulo

    2 power 16. The residual is not directly

    Huffman Coded. Instead, it is expressed as

    pair of symbols : the category and the

    magnitude.

    1. The first symbol represents the number

    of bits needed to encode the magnitude.

    (Only this value is Huffman coded)

    Example: Prediction value for X is 42, then

    from table (see at last), we determine that

    this value belongs to category 6, that is we

    need an additional 6 bits to uniquely

    determine the value 42.

    2. The prediction residual is then mapped

    into 2 tuple (6, 6 bit code for 42)

    3. Category 6 is Huffman Coded and the

    compressed representation for the

    prediction residual consists of this Huffman

    codeword followed by this 6 bit

    representation for the magnitude.

    4. If the value of residual is positive: then

    code for magnitude is its direct binary

    representation.

    5. If the value of residual is negative: then

    code for the magnitude is one's complement

    of the absolute value

    Consider

    - - - | - - - | - - - | - - - | - - -

    | | C | B |

    - - - | - - - | - - - | - - - | - - -

    | | A | X |

    - - - | - - - | - - - | - - - | - - -

    Pixel values A=100, B=191, C=100 and

    X=180.

    Let Y = (A+B)/2; (which comes 145.5, butbecause we are using FLOOR, this will

    become 145)

    and the prediction residual is r = 145 - 180

    = -35.

    From Table , belongs to category 6.The

    binary number for 35 is 100011, and its

    one's complement is 011100. Thus, is

    represented as(6,011100). If the Huffman

    code for six is 1110, then is coded by the

    _EAZC473: lossless image compression http://taxila.bits-pilani.ac.in/mod/forum/discuss.php

    2 05-04-20

  • 8/2/2019 S2-11_EAZC473_ Lossless Image Compression

    9/12

    10-bitcodeword 1110011100. Without

    entropy coding, would require 16 bits.

    In the decoder, the category (that is, 6) is

    extracted first.Thus, the next six bits,

    011100, correspond to the magnitude of the

    residual.Since the most significant bit is

    zero, the residual is negative. After

    takingthe one's complement of 011100, the

    decoded value of the residual r is -35 . TheA and B bits have already been decoded;

    thus Y = 145, as before, and X = Y+35 =

    180

    Category Prediction Residual

    0 0

    1 -1, 1

    2 -3, -2, 2, 3

    3 -7, , -4, 4, , 7

    4 -15, , -8, 8, , 15

    5 -31, ,-16, 16, , 31

    6 -63, , -32, 32, , 63

    7 -127, ..., -64, 64, , 127

    8 -255, ..., -128, 128, ..., 255

    9 -511, ..., -256, 256, ..., 511

    10 -1023,..., -512, 512, ..., 1023

    11 -2047, ..., -1024, 1024, ..., 2047

    12 -4095, ..., -2048, 2048, ..., 4095

    13 -8191, ..., -4096, 4096, ..., 8191

    14-16383, ,-8192, 8192, ...,

    16383

    _EAZC473: lossless image compression http://taxila.bits-pilani.ac.in/mod/forum/discuss.php

    2 05-04-20

  • 8/2/2019 S2-11_EAZC473_ Lossless Image Compression

    10/12

    15-32767, ..., -16384, 16384, ...,

    32767

    16 32768

    Table: Prediction residual categories

    forlossless JPEG compression.

    Show parent | Reply

    Re: lossless imag e compr essionby TUSHAR PAWAR . - Tuesday, 3 April 2012, 06:41 PM

    Abhay

    thanks for solution

    can u pls explain how u get 17 and 22 after using p6 formula

    10 10 10

    10 10 17

    10 17 22

    Show parent | Reply

    Re: lossless image compressionby ABHAY DUTT PAROHA . - Tuesday, 3 April 2012, 11:42 PM

    Hey Tushar...see my solution above ur post...

    Show parent | Reply

    Re: lossless image compr essionby SHETH TEJAS NIXIT . - Wednesday, 4 April 2012, 08:17 PM

    thnaks abhay.. post was very helpfull

    Show parent | Reply

    Re: lossless image compressionby SARANG PADMAKAR GAIKI . - Tuesday, 3 April 2012, 11:47 PM

    Hello All

    Thanks for this.Even I was searching for such problems.However I have not

    understood the concepts. Can some one tell me the source for this.Have you

    gone thru lectures or it is better illustarted in book.Please let me know.

    Regards

    Sarang

    Show parent | Reply

    Re: lossless image compr essionby KALLURI RAJESH . - Wednesday, 4 April 2012, 10:33 AM

    _EAZC473: lossless image compression http://taxila.bits-pilani.ac.in/mod/forum/discuss.php

    12 05-04-20

  • 8/2/2019 S2-11_EAZC473_ Lossless Image Compression

    11/12

    abhay,

    thank you ...

    I am having only one doubt in the solution about this point ...

    Point says "it uses only previously encoded neighbors, the very first pixel

    I(0, 0) will have to use itself. Other pixels at the first row always use P1, at

    the first column always use P2."

    By this point ... do we have to apply the formula on predicted values or

    original values ?

    In the solution , We are doing on original values only ...

    Show parent | Reply

    Re: lossless imag e com pressionby ABHAY DUTT PAROHA . - Wednesday, 4 April 2012, 10:41 AM

    You will apply the formula on original values only. After that, you will

    get one differt matrix.

    After this, you need to calculate predictive residuals matrix

    Show parent | Reply

    Re: lossless imag e compr essionby DHEERAJ SHARMA . - Wednesday, 4 April 2012, 11:00 AM

    Appreciate your efforts for explanation Abhay.

    Show parent | Reply

    Re: lossless imag e compr essionby RAMYA N . - Wednesday, 4 April 2012, 03:07 PM

    Thanks a lot Abhay...

    Show parent | Reply

    Re: lossless imag e compr essionby PANKAJ RAWAL . - Wednesday, 4 April 2012, 11:10 PM

    Hi Abhay,

    If we need to apply formula only on original values.

    Then Value @ (0,2) i.e last row first column should apply P2->B

    prediction so its value as per original values should come as 15 and

    not 10.Please let me know if i am missing anything.

    Final result

    10 10 10

    10 10 17

    15 17 22

    Show parent | Reply

    _EAZC473: lossless image compression http://taxila.bits-pilani.ac.in/mod/forum/discuss.php

    12 05-04-20

  • 8/2/2019 S2-11_EAZC473_ Lossless Image Compression

    12/12

    An institution deemed to be a University estd. vide Sec.3 of the UGC

    Act,1956 under notification # F.12-23/63.U-2 of Jun 18,1964

    2011-2012 Centre for Software Development,SDET Unit, BITS-Pilani, India.

    Contact us : [email protected]

    Powered by Moodle

    _EAZC473: lossless image compression http://taxila.bits-pilani.ac.in/mod/forum/discuss.php