%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%编程人:童伟
%QQ:474701137
%日期:2009年4月26日
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%清屏,清除内存数据
clc
clear
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%读入图像,定义结构体
I=imread('rice.tif');
pix(256)=struct('huidu',0.0,...%灰度值
'number',0.0,...%对应像素的个数
'bianma','');%对应灰度的编码
[m n]=size(I);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%初始化结构数组
for i=1:256
pix(i).number=0;
pix(i).huidu=i;
pix(i).bianma='';
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%统计每种灰度像素的个数记录在pix数组中
for i=1:m
for j=1:n
k=I(i,j);%当前的灰度级
pix(k+1).number=1+pix(k+1).number;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%按灰度像素个数冒泡排序
matlab版本的哈弗曼编码
最新推荐文章于 2024-08-20 09:16:44 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)