Click here to Skip to main content
15,881,744 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all

i'm developing LZW image compression and my code works will

my program compress the image as list of integers, but I have probelem when I saved the compressed stream in file. The file size is larger than the original image size

What can I do??

Please help

Thanks in advance
Posted

I'm guessing here and "image as list of integers" may be your problem - you need to think of the compression result as a stream of bits - not a sequence of integers.

Regards
Espen Harlinn
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 16-Jan-11 18:48pm    
Espen,

Well, I can really appreciate your note on stream of bits (well, a 5), but I would not be sure about the inquirer.

I tried to write some elementary explanation (maybe, not elementary enough).
Sergey Alexandrovich Kryukov 16-Jan-11 18:49pm    
Could you or anyone decrypt the abbreviation "OP" for me?
fjdiewornncalwe 16-Jan-11 23:09pm    
I hate to write it here, but I believe OP stands for "Offending Party", however the connotation is quite negative that way, so it is probably better that it be kept in acronym form. :)
Sergey Alexandrovich Kryukov 16-Jan-11 23:16pm    
Thank you; it explains a lot :-)
I started to hate acronyms after I worked in several US companies. I found people use too many acronyms, including those created in the company; the meaning is often completely forgotten; asking about the real meaning is a way to earn good enemies because those people feel intimidated :-)
Espen Harlinn 17-Jan-11 9:11am    
Ouch :)
What do you consider an image size? If you hope that this is a size of integer multiplied by the number of points; and your persistent presentation would match it, then you hope in vain. The persistent size will always be more -- for a good reason.

If you save using any kind of text-based formatter like XML, it's apparently takes more space, but not because of tags, new line characters, etc. -- mostly because most of the characters of the output could fit in just 4 bits (hex digits along occupy only 4 bits, decimal even less), but physically they occupy 8-16 bits per characters (depending on UTF). For example, text representation of byte "F1" takes two bytes compared to binary 1 byte. (Sorry if it seems too trivial for you -- explaining just in case. I don't really think you're working with texts.).

If you're using (any kind of) binary formatter, it takes more room due to less trivial reason: the persistent presentation contains good amount of meta-data. This meta-data is very important and is needed for reliability -- I would never sorry for extra space.

Surprize! LHW compression will not allow for an essential gain over binary formatted representation. Even less compression you can get over text stream when compared to binary, because text redundancy is well compressed, but not eliminated completely.

The problem is that you're trying to create lostless (of cource) image compression using general-purpose methods, not specific to images.
To get and idea of lost-less image compressions, experiment with available compression methods used in TIFF -- they are useful (a must to have, anyway) but not very effective.
 
Share this answer
 
v5
Comments
Espen Harlinn 16-Jan-11 18:58pm    
5+ Good work - I think, I'm not sure though, OP is an acronym for Original Poster - good question :)
Sergey Alexandrovich Kryukov 16-Jan-11 19:02pm    
Thank you. My first version of answer was not quite adequate (at the moment of my comment) -- I'm still updating it.
Thank you all for reply


Thanks SAKryukov for explanation


as you know LZW is character based compression, and the image must be represented as string to compress

I'm using hash table for building the dictionary as follow:
Map<string,integer> dictionary = new HashMap<string,integer>;();

The image is compressed as list of integers but the stream is saved in the compressed file as bytes (I convert every int to array of bytes)

I tried to use Byte instead of integer in the hash table but it dosen't work, because when the dictionary grow, the integers more than 256 will need more than one byte

Any idea?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900