给你一段程序,自己研究下吧!
clc
clear
close all;
%定义HufData/Len为全局变量的结构体
global HufData;
global Len
disp('计算机正在准备输出哈夫曼编码结果,请耐心等待……');
%原始码字的灰度
a=imread('kids.tif');
%分区画出原始图像和灰度直方图
figure;
subplot(1,2,1)
imshow(a);
%取消坐标轴和边框
axis off
box off
title('MATLAB自带图像','fontsize',13);
subplot(1,2,2);
axis off
box off
imhist(a);
title('图像灰度直方图','fontsize',13);
%图像的灰度统计
GrayStatistics=imhist(a);
GrayStatistics=GrayStatistics';
GrayRatioo=GrayStatistics/sum(GrayStatistics);
GrayRatioNO=find(GrayRatioo~=0);
Len=length(GrayRatioNO);
%初始化灰度集,防止系统随即赋予其垃圾值
GrayRatio=ones(1,Len);
for i=1:Len
GrayRatio(i)=Gray