Results 1 to 3 of 3

Thread: How to take value on image to put into dictionary lzw

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2018
    Location
    Indonesia
    Posts
    13

    Question How to take value on image to put into dictionary lzw

    I am still confused what should be stored into the LZW dictionary in image compression, I just understand the concept of text compression but text compression is not what I want to use just for understanding only. following the concept of the compression text in the LZW algorithm:

    (Psuedocode)

    string s;
    char ch;
    ...

    s = empty string;
    while (there is still data to be read)
    {
    ch = read a character;
    if (dictionary contains s+ch)
    {
    s = s+ch;
    }
    else
    {
    encode s to output file;
    add s+ch to dictionary;
    s = ch;
    }
    }
    encode s to output file;

    Name:  lzw.gif
Views: 792
Size:  10.4 KB
    I've talked before in my compressed image reading bits using the following code:

    Code:
    Private Sub CompressFile(filePath As String)
        Dim data = File.ReadAllBytes(filePath)
        Dim result = Compress(data)
     
        File.WriteAllBytes(Path.ChangeExtension(filePath, ".lzw"), result)
    End Sub
     
    Private Function Compress(data As Byte()) As Byte()
        Dim result As Byte()
     
        'Process data here.
     
        Return result
    End Function
    maybe some one can help me to solve this problem ?

  2. #2
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: How to take value on image to put into dictionary lzw

    What is the problem?
    The example you show is compressing a byte stream, not a character stream so I don't see that it matters what the file is.
    The pseudo code looks basically C like, so a char in that case is essentially the same as Byte in VB.

    What I can't tell, and I don't feel like looking it up, is what units the code table encoded stream is. It can't be byte based since the numbers 256 to 4095 won't fit in 8-bits. It will take 12-bits to hold the number. If all values in the encoded stream are 12-bits, then I have to assume the "encode s to output file;" is doing some packing based on even odd encoded value to share a byte between two encoded table entries in the output stream (i.e. it takes 3-bytes to hold two table entry codes, one byte being shared between the two entries, upper nibble to one and lower nibble to the other).

    Is the question that you don't know how to translate the pseudo code to VB code, rather than anything having to do with Text versus Image, which doesn't look like it (file type) has anything to do with the compressing the stream with the given pseudo code.

    I have to wonder what happens when you've filled your 4096 entries though, which your pseudo code isn't covering. Perhaps you just didn't include that part as it doesn't matter at this step of your implementation. I have to think that using a compression method that is already provided in the windows API would be more efficient than re-implementing the algorithm in your own code, but I don't know since I haven't done any compression myself.

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2018
    Location
    Indonesia
    Posts
    13

    Re: How to take value on image to put into dictionary lzw

    I mean give the above example if in the value of the compressed text stored into the dictionary it is String (a, b, c etc), which I am still confused if the compression case of the image, what is stored into the dictionary (RGB or Pixels or Byte or etc)?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width