• 大小: 320KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-10
  • 语言: Matlab
  • 标签: matlab  

资源简介

图像分割matlab程序,里面有一些图像分割的例子,可以供大家学习

资源截图

代码片段和文件信息




%%%利用二维最佳直方图熵法(KSW熵法)及穷举法实现灰度图像阈值分割
%%%主程序


%%初始部分,读取图像及计算相关信息

clear;
close all;
clc;

%format long;

I=imread(‘rice.tif‘);


windowsize=3;
I_temp=I;
for i=2:255
    for j=2:255
        I_temp(ij)=round(mean2(I(i-1:i+1j-1:j+1)));
    end
end
I_average=I_temp;


I_p=I;
I_average_p=I_average;
hist_2d(1:2561:256)=zeros(256256);
for i=1:256
    for j=1:256
        hist_2d(I_p(ij)I_average_p(ij))=hist_2d(I_p(ij)I_average_p(ij))+1;
    end
end

total=256*256;

hist_2d_1=hist_2d/total;


%%%%%%

Hst=0;
for i=0:255
    for j=0:255
        if hist_2d_1(i+1j+1)==0
            temp=0;
        else
            temp=hist_2d_1(i+1j+1)*log(1/hist_2d_1(i+1j+1));
        end
        Hst=Hst+temp;
    end
end



%%程序主干部分
t0=clock;

    for s=0:255
        for t=0:255
            adapt_value(s+1t+1)=ksw_2d(st0255hist_2d_1Hst);
        end
    end
        
    
    [max_value1index1]=max(adapt_value);
    [max_value2index2]=max(max_value1);
    t_opt=index2-1;
    s_opt=index1(index2)-1;
    
t1=clock;
search_time=etime(t1t0);
    
%%阈值分割及显示部分

threshold_opt=s_opt/255;

I1=im2bw(Ithreshold_opt);

disp(‘灰度图像阈值分割的效果如图所示:‘);
disp(‘源图为:Fifure No.1‘);
disp(‘二维最佳直方图熵法及穷举法阈值分割后的图像为:Fifure No.2‘);

figure(1);
imshow(I);
title(‘源图‘);

figure(2);
imshow(I1);
title(‘二维最佳直方图熵法及穷举法阈值分割后的图像‘);


disp(‘二维最佳直方图熵法及穷举法阈值为(st):‘);
disp(s_opt);
disp(t_opt);

disp(‘二维最佳直方图熵法及穷举法阈值搜索所用时间(s):‘);
disp(search_time);

%%程序结束








    
        

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     目录          0  2006-08-05 19:28  segment_ga

     文件       1789  2005-05-24 17:27  segment_ga\2d_ksw_qiongju.asv

     文件       1739  2005-05-24 17:33  segment_ga\2d_ksw_qiongju.m

     文件        429  2005-04-27 16:04  segment_ga\cross.asv

     文件        471  2005-05-24 10:36  segment_ga\cross.m

     文件        506  2005-05-24 10:58  segment_ga\cross1.asv

     文件        569  2005-05-24 11:20  segment_ga\cross1.m

     文件        574  2005-05-25 08:51  segment_ga\cross_2d.asv

     文件        712  2005-05-25 08:56  segment_ga\cross_2d.m

     文件        809  2005-05-25 12:41  segment_ga\cross_2d1.m

     目录          0  2006-08-05 19:28  segment_ga\datas

     文件      78816  2005-05-25 12:31  segment_ga\datas\ksw_2d_ga_improve.fig

     文件      78816  2005-05-26 18:55  segment_ga\datas\ksw_2d_ga_qiongju_noise.fig

     文件      78816  2005-05-25 11:09  segment_ga\datas\ksw_ga_improve.fig

     文件      78816  2005-05-25 11:13  segment_ga\datas\ksw_ga_improve_noise.fig

     文件      78808  2005-05-25 10:51  segment_ga\datas\ksw_qiongju.fig

     文件      78808  2005-05-25 11:01  segment_ga\datas\ksw_qiongju_noise.fig

     文件        686  2005-05-26 19:12  segment_ga\datas\二维最佳直方图熵法及传统遗传算法.txt

     文件        549  2005-05-25 13:33  segment_ga\datas\二维最佳直方图熵法及改进遗传算法.txt

     文件        582  2005-05-26 18:54  segment_ga\datas\二维最佳直方图熵法及穷举法.txt

     文件        489  2005-05-25 11:25  segment_ga\datas\最佳直方图熵法及改进遗传算法.txt

     文件        444  2005-05-25 11:24  segment_ga\datas\最佳直方图熵法及穷举法.txt

     文件       2516  2005-05-23 22:00  segment_ga\ga_main.asv

     文件       2519  2005-05-23 22:28  segment_ga\ga_main.m

     文件        512  2005-09-14 13:22  segment_ga\hist2.m

     文件        520  2005-04-27 15:59  segment_ga\ksw.asv

     文件        614  2005-05-25 10:47  segment_ga\ksw.m

     文件        749  2005-05-24 16:47  segment_ga\ksw_2d.asv

     文件        761  2005-05-25 10:31  segment_ga\ksw_2d.m

     文件       3213  2005-05-25 11:43  segment_ga\ksw_2d_ga.asv

............此处省略39个文件信息

评论

共有 条评论