I want to calculate the compression ration of original and final image?
5 views (last 30 days)
Show older comments
I calculated by
ratio=original.FileSize/Compressed.FileSize (which would be in bytes)
Now for calculating percentage of image compressed i used the following : 100(-(1/ratio)*100).
Now some where i found that (width*height*bits)/8 of original image divided by (width*height*bits)/8 can also give compression ratio percentage. But the two percentages are different. Please help me out in this.
3 Comments
Walter Roberson
on 21 Nov 2016
100(-(1/ratio)*100) expresses a multiplication by a negative number so I do not understand what you are trying to calculate there unless you use 100 * (1 - 1/ratio)
Answers (2)
Walter Roberson
on 21 Nov 2016
Your compressed data will be vector, rather than having width and height both.
You have to watch out for the color dimension: not width*height*bits/8 but width*height*bits*channels/8
You also have to be careful about the bits calculation. For compression purposes, it is not the number of bits that you are storing the data in while it is "live" in memory. For example if you had a strict black and white image, that would only take 1 bit per pixel but "live" in memory you would need at least 8 bits in MATLAB because MATLAB does not have a true bit data type. Likewise, if you double() an uint8 image, you have gone from 8 bits per pixel per channel to 64 bits per pixel per channel in memory. The amount of storage actually occupied is not the number you need to use for compression. Instead, for compression, you should be using the number of bits that is needed to differentiate one stored value from another -- or to put it another way, ceil(log2()) of the number of different values that the item can assume. For example, black and white is 2 different values, log2() is 1, ceil() is 1, so it is the 1 that you would use for compression, even if the 1 is currently represented in a 64 bit double. 5 different values log2 is slightly over 2, ceil() is 3, so 3 would be the bit count if your storage is intended to represent 5 possible values.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!