资源简介
实现了对一幅BMP格式的图像进行二元霍夫曼编码和译码。
对一幅BMP格式的图像进行二元Fano编码、译码。

代码片段和文件信息
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
unsigned char* pBmpBuf; //image read pointer
int bmpWidth; //bmpwidth
int bmpHeight; //bmpheight
int BibitCount; //bits per pixel
RGBQUAD* pColorTable; //palette pointer
BITMAPFILEHEADER* filehead;
BITMAPINFOHEADER* infohead;
char str[100]; //image file name/path
int lineByte; //bits per row
int k; //huffman point
//build the struct for Huffman coding
struct node
{
short lson = -1;
short rson = -1;
short num = 0;
short parent = -1;
int frequency = 0;
string coded;
};
node anode[2 * 256 - 1];
//get scale map information
bool readBmp(char* bmpname) {
FILE* fp = fopen(bmpname “rb“);
if (fp == 0)
{
cout << “未能找到指定文件“;
return false;
}
//skip file header
fseek(fp sizeof(BITMAPFILEHEADER) 0);
//read the bitmap information header
infohead = new BITMAPINFOHEADER;
fread(infohead sizeof(BITMAPINFOHEADER) 1 fp);
bmpHeight = infohead->biHeight;
bmpWidth = infohead->biWidth;
BibitCount = infohead->biBitCount;
lineByte = ceil(bmpWidth * BibitCount / 8 + 3) / 4 * 4;
//read the palette
if (BibitCount == 8)
{
pColorTable = new RGBQUAD[256];
fread(pColorTable sizeof(RGBQUAD) 256 fp);
}
cout << “1.头文件处理完成“< //Read pixel encoding
int n;
n = lineByte * bmpHeight;
pBmpBuf = new unsigned char[n];
fread(pBmpBuf 1 n fp);
fclose(fp);
cout << “2.成功读取“< return true;
}
//provide a sort and huffmam method
bool complare(node &anode node &b) {
return anode.frequency > b.frequency;
}
//Traverses the image pixels that the pointer points
bool sortnode(unsigned char *pBmpBufnode anode[])
{
for (int i = 0; i <= 255; i++)
{
anode[i].num = i;
}
for (int i = 0; i < bmpHeight*bmpWidth; i++)
{
anode[int(pBmpBuf[i])].frequency++;
}
sort(anodeanode+256complare);
cout << “3.排序中。。。。。“;
return true;
}
//find the two points with the least weight to construct Huffman
int selectmin(int aint k) {
for (int i = 0; i < 256+k; i++)
{
if (anode[i].parent == -1) {
a = i;
break;
}
}
for (int i = 0; i < 256+k ; i++)
{
if (anode[i].parent == -1 && anode[a].frequency > anode[i].frequency )
{
a = i;
}
}
anode[a].parent = -2;
return a;
}
//construct Huffmam
bool huffman(node anode[]) {
for (k = 256; k < 256*2-1; k++)
{
int a = 0;
int b = 0;
a = selectmin(a k - 256);
b = selectmin(b k - 256);
anode[k].frequency = anode[a].frequency + anode[b].frequency;
anode[a].parent = k;
anode[b].parent = k;
anode[k].lson = a;
anode[k].rson = b;
}
return true ;
}
string Coded[256];
//code the pixel by Huffman
bool coding(node anode[]string Coded[]) {
for (int i = 0; i < 256; i++)
{
in
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1756088 2019-05-25 22:41 哈夫曼编码bmp图像,费诺编码bmp图像.docx
文件 11246 2019-05-25 22:30 readbmp.cpp
----------- --------- ---------- ----- ----
1767334 2
- 上一篇:去哪网旅游景点数据集合
- 下一篇:LabView2018 安装教程
相关资源
- 如何实现bmp位图透明贴图
- bmp文件读出为txt文件 txt文件写入为
- bmp2c
- BmpButton
- 哈夫曼压缩算法(源代码 实现报告)
- 基于V4L2的视频采集,能够采集YUVJPE
- AlCl3抑制大鼠骨形成及BMP/Smad信号转导
- 哈夫曼树编码和译码实验报告+运行视
- ORL_BMP.zip
- BMP位图文件解析
- 哈夫曼树--链表实现编码,解码
- 编程常用的素材(含png、jif、bmp、j
- jpeglib读取jpeg,转为bmp图,24真彩和灰
- 617张国内车牌60-17bmp图片用于OpenCV正样
- pEGFP-N1/BMP-2真核表达质粒的构建与鉴定
- 简单\“(8bit)Raw图像文件转换为(
- ORL人脸数据集,40个人,共400张bmp格式
- RGB565格式转BMP
- 数据结构课程设计——哈夫曼编/译码
- libmp3lame.a(3.100)静态库for iOS支持真
- RATA Raster (BMP) To Allegro (IPF)
- 哈夫曼树实现图片压缩与解压
- 贪心算法-哈夫曼编码
- 批量快速将多张bmp图片合并转换为b
- BMP图片读写,24位输入转换成8位输出
- AES加密BMP图片
- yuvtools_v2
- DICOM Explorer
- 数字图像处理测试BMP/JPG图片,图片为
- stm32图片解码
评论
共有 条评论