forked from kazuho/rangecoder
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
caf365f
commit 64bb08d
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
Installation | ||
============ | ||
|
||
pip install range-coder | ||
|
||
|
||
Example | ||
======= | ||
|
||
```python | ||
from range_coder import RangeEncoder, RangeDecoder, prob_to_cum_freq | ||
|
||
data = [2, 0, 1, 0, 0, 0, 1, 2, 2] | ||
prob = [0.5, 0.2, 0.3] | ||
|
||
# convert probabilities to cumulative integer frequency table | ||
cumFreq = prob_to_cum_freq(prob, resolution=128) | ||
|
||
# encode data | ||
encoder = RangeEncoder(filepath) | ||
encoder.encode(data, cumFreq) | ||
encoder.close() | ||
|
||
# decode data | ||
decoder = RangeDecoder(filepath) | ||
dataRec = decoder.decode(len(data), cumFreq) | ||
decoder.close() | ||
``` |