压缩算法从入门到放弃之二叉树(1)

作者: 玄夜 时间: 2018.6.30


前言

算法,永不过时!

干码农干了好几年了,感觉自己能拿出手的东西并不多啊,所以最近有了重新拾起算法这块的想法;

进入正题,这是一个压缩算法系列的文章,从最简单的二叉树开始写,敬请关注。


一、二叉树的简介

二叉树是数据结构中树家族最为基础的结构。

1、二叉树应用场景:

①、哈夫曼编码,简单有效的压缩算法

②、快速排序、查找

2、二叉树的特性:

①、二叉树的每个结点至多只有二棵子树;

②、二叉树的子树有左右之分,次序不能颠倒;

③、二叉树的第i层至多有2i-1个结点;深度为k的二叉树至多有2k-1个结点。

3、二叉树的基本形态:

二叉树是递归定义的,其结点有左右子树之分:

①空二叉树——如图(a);

②只有一个根结点的二叉树——如图(b);

③只有左子树——如图(c);

④只有右子树——如图(d);

⑤完全二叉树——如图(e)。

4.二叉树的表达方法:

①、图像表达法,如图:

②、符号表达法:

以上图为例(A,(B(D,E),C(F))

③、遍历表达法:

先序遍历为ABDECF

中序遍历为DBEAFC

后序遍历为DEBFCA


二、实战

好了,上面写的都是一些基本的知识点,现在直接上代码,简单粗暴:

1、先建一个类
package com.jt.tree;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by jay on 2018/6/30.
 */

public class Tree {

    private Tree root;//根节点
    private Tree left;//左节点
    private Tree right;//右节点
    private Object obj;//数据域
    private List<Tree> datas;//存储所有节点

    public Tree(Tree left, Tree right, Object obj) {
        super();
        this.left = left;
        this.right = right;
        this.obj = obj;
    }
    public Tree(Object obj) {
        this(null, null, obj);
    }
    public Tree() {
        super();
    }


    /**
     * 构建一个二叉树
     * @param objs
     */
    public void createTree(Object[] objs){
        datas=new ArrayList<Tree>();
        for (Object obj : objs) {
            datas.add(new Tree(obj));
        }
        root=datas.get(0);//将0作为根节点
        for (int i = 0; i < objs.length/2; i++) {
            datas.get(i).left=datas.get(i*2+1);
            if(i*2+2<datas.size()){
                datas.get(i).right=datas.get(i*2+2);
            }
        }
    }

    //先序遍历
    public void preorder(Tree root){
        if(root!=null){
            log(root.getData());
            preorder(root.left);
            preorder(root.right);
        }

    }
    //中序遍历
    public void inorder(Tree root){
        if(root!=null){
            inorder(root.left);
            log(root.getData());
            inorder(root.right);
        }

    }
    //后序遍历
    public void postorder(Tree root){
        if(root!=null){
            postorder(root.left);
            postorder(root.right);
            log(root.getData());
        }

    }
    private void log(Object obj) {
        System.out.print(obj+" ");
    }
    public Object getData() {
        return obj;
    }
    public Tree getRoot() {
        return root;
    }

}

复制代码
2、测试代码:
    Tree tree = new Tree();
    Object[] obj = {1,2,3,4,5,6};
    tree.createTree(obj);
    
    tree.preorder(tree.getRoot());
    System.out.println("\n");
    tree.inorder(tree.getRoot());
    System.out.println("\n");
    tree.postorder(tree.getRoot());
复制代码
3、测试结果:

本篇文章就到这了,有哪里不对的请各位指点。

炮友们有问题,请留言 感谢! 这是粉丝QQ群

文章作者写的matlab源代码,该文章发表在Digital Signal Processing: Ke-Kun Huang , Hui Liu, Chuan-Xian Ren, Yu-Feng Yu and Zhao-Rong Lai. Remote sensing image compression based on binary tree and optimized truncation. Digital Signal Processing, vol. 64, pp. 96-106, 2017. (http://dx.doi.org/10.1016/j.dsp.2017.02.008) 遥感图像数据非常广泛,因此需要通过空间设备上的低复杂度算法进行压缩。具有自适应扫描顺序(BTCA)的二叉树编码是一个的有效算法。然而,对于大规模遥感图像,BTCA需要大量的内存,而且不能随机存取。在本文中,我们提出了一种基于BTCA的新的编码方法。小波图像首先划分为几个块,并由BTCA单独编码的。根据BTCA的属性,仔细选择每个块的有效截断点,以优化速率失真的比例,从而获得更高的压缩比、更低的内存要求和随机访问性能。由于没有任何熵编码,所提出的方法简单快速,非常适合于空间设备。对三个遥感图像集进行实验,结果表明它可以显着提高PSNR、SSIM和VIF,以及主观视觉体验。 The remote sensing image data is so vast that it requires compression by low-complexity algorithm on space-borne equipment. Binary tree coding with adaptive scanning order (BTCA) is an effective algorithm for the mission. However, for large-scale remote sensing images, BTCA requires a lot of memory, and does not provide random access property. In this paper, we propose a new coding method based on BTCA and optimize truncation. The wavelet image is first divided into several blocks which are encoded individually by BTCA. According the property of BTCA, we select the valid truncation points for each block carefully to optimize the ratio of rate-distortion, so that a higher compression ratio, lower memory requirement and random access property are attained. Without any entropy coding, the proposed method is simple and fast, which is very suitable for space-borne equipment. Experiments are conducted on three remote sensing image sets, and the results show that it can significantly improve PSNR, SSIM and VIF, as well as subjective visual experience.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值