huffman-code

Huffman Tree in Java

℡╲_俬逩灬. 提交于 2020-01-01 19:35:14
问题 I have a problem with my Huffman tree code. In the main method I input a String of Symbols and I also input an Integer array containing the frequency of the Symbols. It should print out each Symbol and its Huffman code, but I think its wrong... Here is the code: package huffman; import java.util.*; abstract class HuffmanTree implements Comparable<HuffmanTree> { public final int frequency; // the frequency of this tree public HuffmanTree(int freq) { frequency = freq; } // compares on the

Matlab, Image compression

老子叫甜甜 提交于 2020-01-01 15:31:08
问题 i am unsure about what this is asking me to do in matlab? what does it mean to encode? what format should the answer be? can anyone help me to work it out please? Encode the 8x8 image patch and print out the results I have got an 8X8 image symbols=[0 20 50 99]; p=[32 8 16 8]; p = p/sum(p); [dict, avglen] = huffmandict(symbols, p); A = ... [99 99 99 99 99 99 99 99 ... 20 20 20 20 20 20 20 20 ... 0 0 0 0 0 0 0 0 ... 0 0 50 50 50 50 0 0 ... 0 0 50 50 50 50 0 0 ... 0 0 50 50 50 50 0 0 ... 0 0 50

Converting a String representation of bits to a byte

三世轮回 提交于 2020-01-01 04:41:06
问题 I'm just beginning to learn about file compression and I've run into a bit of a roadblock. I have an application that will encode a string such as "program" as a compressed binary representation "010100111111011000" (note this is still stored as a String). Encoding g 111 r 10 a 110 p 010 o 011 m 00 Now I need to write this to the file system using a FileOutputStream , the problem I'm having is, how can I convert the string "010100111111011000" to a byte[] / byte s to be written to the file

Using Huffman coding to compress images taken by the iPhone camera

爱⌒轻易说出口 提交于 2019-12-31 03:47:22
问题 Im thinking to use the Huffman coding to make an app that takes pictures right from the iPhone camera and compress it. Would it be possible for the hardware to handle the complex computation and building the tree ? In other words, is it doable? Thank you 回答1: If you mean the image files (like jpg, png, etc), then you should know that they are already compressed with algorithms specific to images. The resulting files would not huffman compress much, if at all. If you mean that you are going to

Huffman encoding - header & EOF

孤街浪徒 提交于 2019-12-30 11:28:25
问题 I am currently working on implementing a program based on the huffman algorithm in Java, and I am at the stage where I need to output the encoded content to a file. I am a bit confused about how to implement the header and eof needed for decoding. For my header at the moment I have all the unique values that occur from the input file and their frequency, but on some articles I have seen people do it with 0 or 1 represents the nodes and then the frequency (which I am a bit puzzled by as it

Efficient way of storing Huffman tree

与世无争的帅哥 提交于 2019-12-27 10:53:22
问题 I am writing a Huffman encoding/decoding tool and am looking for an efficient way to store the Huffman tree that is created to store inside of the output file. Currently there are two different versions I am implementing. This one reads the entire file into memory character by character and builds a frequency table for the whole document. This would only require outputting the tree once, and thus efficiency is not that big of a concern, other than if the input file is small. The other method

Reading and writing bit by bit in C++ for Huffman Encoding

一曲冷凌霜 提交于 2019-12-25 03:44:47
问题 I'm trying to encode and decode for a Huffman coding in C++. I'm not sure where my problem is I'm able to read and write but when I decompress the file its scrambled so I'm either not encoding or decoding correctly. I think its when I'm writing and reading the file where things go wrong. So this is what I have to write the encoded file. First I store all the bitcodes from my unordered map called uMap into one string: int i = 0, j = 0; string fullStr = ""; for (i = 0; i < buffsize; i++) //put

How is this Huffman Table created?

会有一股神秘感。 提交于 2019-12-24 04:02:10
问题 I have a table that shows the probability of an event happening. I'm fine with part 1, but part 2 is not clicking with me. I'm trying to get my head around how the binary numbers are derived in part 2? I understand 0 is assigned to the largest probability and we work back from there, but how do we work out what the next set of binary numbers is? And what do the circles around the numbers mean/2 shades of grey differentiate? It's just not clicking. Maybe someone can explain it in a way that

Mapping a list to a Huffman Tree whilst preserving relative order

一笑奈何 提交于 2019-12-24 02:55:08
问题 I'm having an issue with a search algorithm over a Huffman tree: for a given probability distribution I need the Huffman tree to be identical regardless of permutations of the input data. Here is a picture of what's happening vs what I want: Basically I want to know if it's possible to preserve the relative order of the items from the list to the tree. If not, why is that so? For reference, I'm using the Huffman tree to generate sub groups according to a division of probability, so that I can

Can you draw a binary tree given its pre-order binary sequence/ordering?

僤鯓⒐⒋嵵緔 提交于 2019-12-23 12:32:49
问题 Binary trees (and hence ordered forests) can be represented as binary strings. The binary string is obtained by traversing a binary tree in preorder, recording a 1 for every node and a 0 for every empty subtree (null link). This means that if I'm given a binary tree, I can do a preorder traversal and produce a binary sequence representation. Is the opposite also possible? If I'm given this binary sequence 11011000101101010001 , can I draw the binary tree? 回答1: Yes you can. Label the internal