图像处理--采用最大熵方法进行图像分割

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

数字图象处理课程设计

题目:采用最大熵方法进行图像分割

班级:电信121

学号:3120412014

姓名:吴向荣

指导老师:王栋

起止时间:2016.1.4~2016.1.8

西安理工大学

源代码:

clear,clc

image=imread('C:\Users\Administrator\Desktop\图像课设\3.jpg');

subplot(2,2,1);imshow(image);title('原始彩图')

%% %灰度图

imagegray=rgb2gray(image); %彩色图转换为灰度图

subplot(2,2,2);imshow(imagegray);title('灰度图')

%计算灰度直方图分布counts和x分别为返回直方图数据向量和相应的彩色向量

count=imhist(imagegray);

subplot(2,2,3);imhist(imagegray);title('灰度直方图')

[m,n]=size(imagegray);

imagegray=fun_maxgray(count,imagegray,m,n);

subplot(2,2,4);imshow(imagegray);title('最大熵处理后的图')

%% 彩色图

% r=image(:,:,1);countr=imhist(r);r=fun_maxgray(countr,r,m,n);

% subplot(2,2,1);imshow(r);

% g=image(:,:,2);countg=imhist(g);g=fun_maxgray(countg,g,m,n); % subplot(2,2,2);imshow(g);

% b=image(:,:,3);countb=imhist(b);b=fun_maxgray(countb,b,m,n); % subplot(2,2,3);imshow(b);

b=0;

for z=1:3

figure

titleName = strcat('第',num2str(z),'通道灰度直方图');

titleName1 = strcat('第',num2str(z),'通道最大熵处理后图');

a=image(:,:,z);subplot(1,2,1);imhist(a);title(titleName)

countr=imhist(a);a=fun_maxgray(countr,a,m,n);

subplot(1,2,2);imshow(a);title(titleName1)

b=b+a;

end

figure,imshow(b);title('彩色各通道处理后叠加图')

最大熵方法进行图像分割的子函数:

function sample=fun_maxgray(count,sample,m,n) countp=count/(m*n); %每一个像素的分布概率

E=[];

E1=0;

E2=0;

L=256;

for th=2:L-1 %循环阈值

pth=sum(countp(1:th+1)); %计算对应阈值概率if countp(th)==0 %当阈值概率为0跳出当前循环continue;

end

for i=1:th

if countp(i)==0 %当前像素概率为0,跳出当前循环

continue;

end

E1=E1-countp(i)/pth*log(countp(i)/pth);

end

for i=th-1:L

if countp(i)==0

continue;

end

E2=E2-countp(i)/(1-pth)*log(countp(i)/(1-pth)); end

e=E1+E2;

E=[E e];

end

th=find(E==(max(E))); %找数组中最大值的阈值

%[ma,index]=max(E);

for i=1:m %对图像二值化

for j=1:n

if sample(i,j)>th

sample(i,j)=255;

else

sample(i,j)=0; e

运行结果:

其他图片比较:

THANKS !!!

致力为企业和个人提供合同协议,策划案计划书,学习课

件等等

打造全网一站式需求

欢迎您的下载,资料仅供参考

相关文档
最新文档