Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
pagmerek committed Nov 12, 2023
1 parent 8f8a8da commit 3bea589
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 37 deletions.
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
# fractal-wavelet-compression
Image compression with fractal wavelet transform
# `frave`
![fractals](img/fractals.gif)

`frave` is an image compression algorithm based on complex-base system fractals.

## Decomposition of an image
Unlike other compression algorithms `frave` works on tame-twindragon fractals rather than on blocks.

## Compression pipeline
- Decomposing image to fractals using complex-base numeral systems
- Saving the residues of each block
- Quantization based on dividing the smallest layer of fractals
- Entropy coding with ANS

## Compression rates
> TBD!
Binary file removed img/decomposition.gif
Binary file not shown.
Binary file added img/fractals.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 1 addition & 2 deletions src/compression/decoder.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::collections::HashMap;

use itertools::Itertools;
use rans::b64_decoder::B64RansDecoderMulti;
use rans::RansDecoderMulti;

Expand Down Expand Up @@ -72,7 +71,7 @@ impl Decoder for FractalImage {
let length = self.coef.iter().filter(|x| x.is_some()).count();
let mut coef = self.coef.clone();
let depth = utils::get_prev_power_two(length).trailing_zeros() + 1;
let scale_bits = u32::try_from(depth - 1).unwrap();
let scale_bits = depth - 1;
let mut decoder: B64RansDecoderMulti<3> = B64RansDecoderMulti::new(compressed_coef);
let ctxs = ans_contexts;
let layers = vec![
Expand Down
9 changes: 7 additions & 2 deletions src/compression/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,12 @@ impl Encoder for FractalImage {
}

fn ans_encode(&self) -> (Vec<u8>, Vec<AnsContext>) {
let valid_coef = &self.coef.clone().into_iter().flatten().collect::<Vec<i32>>();
let valid_coef = &self
.coef
.clone()
.into_iter()
.flatten()
.collect::<Vec<i32>>();
let true_depth = utils::get_prev_power_two(valid_coef.len()).trailing_zeros() + 1;
let layer1 = &valid_coef[1 << (true_depth - 1)..];
let layer2 = &valid_coef[1 << (true_depth - 2)..1 << (true_depth - 1)];
Expand All @@ -94,7 +99,7 @@ impl Encoder for FractalImage {
let mut contexts: Vec<ans::AnsContext> = vec![];

for (i, layer) in [layer1, layer2, layer3].into_iter().enumerate() {
let counter = layer.clone().into_iter().counts();
let counter = &(*layer).iter().counts();
let freq = counter
.values()
.map(|e| u32::try_from(*e).unwrap())
Expand Down
24 changes: 11 additions & 13 deletions src/fractal/image.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::cmp;

use image::GrayImage;
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -55,7 +53,6 @@ impl FractalImage {
x: width as i32 / 2,
y: height as i32 / 2,
}; //;Self::find_center(depth, variant);
dbg!(depth, center);

Self {
height,
Expand Down Expand Up @@ -99,17 +96,18 @@ impl FractalImage {
.find(|&(_i, rw, rh)| img_w as i32 <= rw && img_h as i32 <= rh)
.unwrap()
.0
-1
- 1
}

fn find_center(depth: usize, variant: [Coord; 30]) -> Coord {
variant[0..depth]
.iter()
.fold(Coord { x: 0, y: 0 }, |accum, value| Coord {
x: accum.x - cmp::min(0, value.x),
y: accum.y - cmp::min(0, value.y),
})
}
// TODO: Implement valid find center algorithm
// fn find_center(depth: usize, variant: [Coord; 30]) -> Coord {
// variant[0..depth]
// .iter()
// .fold(Coord { x: 0, y: 0 }, |accum, value| Coord {
// x: accum.x - cmp::min(0, value.x),
// y: accum.y - cmp::min(0, value.y),
// })
// }

#[inline]
pub fn get_pixel(&self, x: i32, y: i32) -> Option<i32> {
Expand Down Expand Up @@ -140,6 +138,6 @@ pub fn get_quantization_matrix_soft() -> Vec<i32> {
#[must_use]
pub fn get_quantization_matrix() -> Vec<i32> {
vec![
1, 1, 1,1,1,1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 10, 10, 10, 10, 10, 10, 16, 9, 2,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 10, 10, 10, 10, 10, 10, 16, 9, 2,
]
}
1 change: 0 additions & 1 deletion src/fractal/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
pub mod haar_tree;
pub mod image;
pub mod variants;
17 changes: 0 additions & 17 deletions utils.rs

This file was deleted.

0 comments on commit 3bea589

Please sign in to comment.