资源简介
读取一个256*256的图像,并对其进行LZW编码,最后输出字典以及相应的码字序列。压缩包里面包含C++源代码以及实验报告。

代码片段和文件信息
#include
#include
#include
#include
using namespace std;
//查找字典中有没有条目I
bool search( vector>& dict vector& I vector::size_type& index );
int main( )
{
//------------------------------定义变量------------------------------------
//打开文件的指针
FILE *fp;
//灰度值大小
int grey_level = 0;
//定义输入序列
vector input;
//定义输出序列
vector output;
//定义字典
vector> dict;
//字典索引序号
vector::size_type index;
//定义短语词条I
vector I;
//定义新加入的字符x
vector x;
//-----------------------------读取图片-------------------------------------
//打开图像矩阵文件
if( ( fp = fopen( “LENA256.IMG“ “rb“ ) ) == NULL ){
printf( “cannot open file\n“ );
exit( 0 );
}
int size;
cout << “The program is not efficient.“ << endl
<< “Please input the number of the pixels(1-65536): “;
cin >> size;
//构造灰度值序列
for( int i = 0; i <= size; i++ ){
grey_level = fgetc( fp );
if( grey_level == EOF )
break;
input.push_back( grey_level );
}
//关闭图像矩阵文件
fclose( fp );
//-------------------------------字典初始化------------------------------------
vector temp;
temp.push_back( 0 );
for( int i = 0; i < 256; i++ ){
temp[ 0 ] = i;
dict.push_back( temp );
}
//------------------------------构造码字和字典---------------------------------
x.push_back( input.back( ) );
input.pop_back( );
while( !input.empty( ) ){
I.push_back( x[ 0 ] );
while( 1 ){
//积累数据
search( dict I index );
I.push_back( input.back( ) );
x[ 0 ] = input.back( );
input.pop_back( );
//判断转移条件
if( !search( dict I index ) ) break;
if( input.empty( ) ) break;
}
//输出新码字和输出编码结果
output.push_back( index );
if( !input.empty( ) ) dict.push_back( I );
I.clear( );
}
//-----------------------------输出码字和字典----------------------------------
cout << “The dictionary is as follows: “ << endl;
for( vector::size_type i = 0; i < dict.size( ); i++ ){
cout << “index: “ << setw( 6 ) << left << i << “ I: “;
for( vector::size_type j = 0; j < dict[ i ].size( ); j++ ){
cout << setw( 4 ) << left << dict[ i ][ j ] << ‘ ‘;
}
cout << endl;
}
cout << “\nThe output is: \n“;
for( vector::size_type i = 0; i < output.size( ); i++ ){
cout << setw( 6 ) << left << output[ i ];
if( ( i + 1 ) % 10 == 0 && i != 0 )
cout << endl;
}
cout << “\n\nThe input size is: “ << size << endl;
cout << “The size of output is: “ << output.size( ) << endl;
return 0;
}
bool search( vector>& dict vector& I vector::size_type& index )
{
for( vector::size_type i = 0; i < dict.size( ); i++ )
if( I == dict[ i ] ){
index = i;
return true;
}
return false;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2945 2011-12-23 16:13 LZW.cpp
文件 294620 2011-12-24 00:13 作业五.docx
----------- --------- ---------- ----- ----
297565 2
相关资源
- 百度C++编码规范
- GBT 28169-2011 嵌入式软件 C语言编码规范
- 缩短循环码(2616)编译码程序-C语言
- pcm语音编码
- UNIX/LINUX下C语言中文短信UCS2编码和解
- 信息论课程设计——LZW编码
- c语言实现bch编码
- 个人总结的一些C/C++编码规范
- 谷歌C++编码规范 Google C++ 风格指南
- C语言实现LZW编码
- C++实现的改进遗传算法
- MFC莫尔斯电码的编码发声
- Google-C++编码规范中文版最新整理PDF版
- spiht算法小波图像编码算法
- LZW无损压缩
- GBT28169-2011嵌入式软件C语言编码规范
- 嵌入式软件C语言编码规范(高安全性
- 密码编码学:加密方法的C与C++实现
- MMX-密码编码学:加密方法的C与C++实现
- MFC 一维码生成+打印 支持多种编码1
- Huffman和算术编码的C++实现
- 基于JPEG2000的图像编码与解码c++版
- 简单实现的自适应算术编码
- 谷歌C++编码规范-中文 2018-03-30 最新版
- jbig二值图像压缩算法编码实现
- VC++串口通信编码
- 哈夫曼编码译码器数据结构
- 编码:隐匿在计算机软硬件背后的语
- vc++ 图像编码 视频编码
- 哈夫曼编码压缩文件,c/c++课程设计
评论
共有 条评论