How to save variables in matlab in most optimal way

4 views (last 30 days)
Hello, i have being trying to implement multiple image compression algorithms in matlab (such as RLE) but when encoding an image and trying to save the encoded matrix as a .mat file, it always becomes larger when it should be smaller thoeratically
so i want to know what other ways can you save variables such that it gets the original size it should have
thanks in advace
  4 Comments
Adel Hafri
Adel Hafri on 15 May 2022
okay so i have a 750x750 jpeg pictures with values ranging from 0 to 255 and im supposed to apply losless image compression algorithms to reduce the size of those pictures, lossless image compression algorithms such as huffman work by reducing the length of frequent occuring symbols, for example if 150 was my most occuring then my huffman algorithm gives it the code 0 for example and so i ll be saving 7 bits times the frequncy of that data which means compression, the problem is matlab automatically makes that 1 bit length 0 into a 00000000 so essentialy, my algorithm is pointless since matlab will make all the data 8 bit length again, so i want a way to save data exactly the size i want, whether 1 bit,2bits.3....etc instead of it forcing all data to be 8bits
here is an example of how the algorithm changes the symbols
the picture i used isnt the best example of compression but you can get the idea

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 15 May 2022
fwrite() with the 'bit1' precision.
For compression calculations purposes you should never be using the size of mat files. mat files have overhead for every variable, and mat files have their own compression built in.
  7 Comments
Adel Hafri
Adel Hafri on 3 Jun 2022
nevermind, i fixed it, i had to use ubit1 instead of bit1 for unsigned binary
again thank you so much man, you are a life saver

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!