博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ostu进行遥感图像的分割
阅读量:6964 次
发布时间:2019-06-27

本文共 3180 字,大约阅读时间需要 10 分钟。

城市地区道路网的简单的阈值分割。采用的是单ostu(最佳阈值分割)算法,废话少说,如果不太清楚该算法,请参考文献[1]中的图像分割这一章的介绍。程序直接运行的效果如下。

 

直接附加代码,希望对大家有一些益处,节约你的时间:

% 最大类方差法实现自适应图像阈值分割% This implements is implemented by WENG, All rights reserved% Copy Rights (c) WENG% 2016-3-30 1639clear;clc;close all;warning off; %#ok
IMG = imread('steger_perfect_1_rg.tif');% fdoa1_rs1_rg.tifIMG_gray=double(rgb2gray(IMG));[M,N]=size(IMG_gray);gray_level=256;% HistgramHistgram_normal=zeros(256,1);% value span, 1~256for i_level=1:256, Histgram_normal(i_level)=sum(sum(IMG_gray==(i_level+1)));endHistgram_normal=Histgram_normal/(M*N); % histgram normalizem_overall=0;for m=1:gray_level,m_overall=m_overall+(m-1)*Histgram_normal(m);endsigma_max=0;sigma_B=zeros(gray_level,1);for i=1:gray_level, threshold=i-1; % calculate the number of the two class, the number is 0~1 num1=0; for m=1:threshold-1 num1=num1+Histgram_normal(m); end num2=1-num1; % cal m1, m2 m1=0; m2=0; for m=1:gray_level if m
sigma_max optical_T=threshold; sigma_max=sigma1; endendTh_optical=optical_T;Th_matalb=graythresh(IMG_gray)*255;%matlab函数求阈值fprintf(1,'The otsu threshold and Threshold calculate by graythresh are:\n %.1f [best], %.1f\n\n',Th_optical,Th_matalb);% visual the resultThreshold_Optimal_IMG=zeros(M,N);Threshold_graythresh_IMG=zeros(M,N);Threshold_Optimal_IMG(IMG_gray>Th_optical)=1;Threshold_graythresh_IMG(IMG_gray>Th_matalb)=1;figure,subplot(2,2,1);imshow(IMG,[]);title('Ori color image');subplot(2,2,2);imshow(IMG_gray,[]);title('Ori gray image');subplot(2,2,3);imshow(Threshold_graythresh_IMG,[]);title('Threshold calculated by graythresh');subplot(2,2,4);imshow(Threshold_Optimal_IMG,[]);title('Threshold calculated by ostu');figure,subplot(1,2,1);hold on; plot(1:gray_level,sigma_B);title('The two TH marked on \sigma array');xlabel('Th'); ylabel('\sigma_B');plot(Th_optical+1,sigma_B(Th_optical+1),'xg','MarkerSize',8,'LineWidth',2); text(Th_optical+1,sigma_B(Th_optical+1)-50,'otsu threshold');plot(Th_matalb+1,sigma_B(Th_matalb+1),'^r','MarkerSize',8,'LineWidth',2); text(Th_matalb+1,sigma_B(Th_matalb+1)-50,'graythresh calculated threshold');hold off;subplot(1,2,2);plot(1:gray_level,Histgram_normal);title('Gray image Histgram');hold on;plot(Th_optical+1,Histgram_normal(Th_optical+1),'xg','MarkerSize',8,'LineWidth',2);text(Th_optical+1,Histgram_normal(Th_optical+1)-50,'otsu threshold');plot(Th_matalb+1,Histgram_normal(Th_matalb+1),'^r','MarkerSize',8,'LineWidth',2);text(Th_matalb+1,Histgram_normal(Th_matalb+1)-50,'graythresh calculated threshold');hold off;% Image that can be classified by the threshold evaluateSigma_G=std(IMG_gray(:));eta_ostu=sigma_B(Th_optical+1)/Sigma_G;eta_matlab=sigma_B(Th_matalb+1)/Sigma_G;fprintf(1,'The separability of ostu and matlab graythresh func respectively are:\n%.3f, %.3f\n',eta_ostu,eta_matlab);

 

 

 

 

 

参考文献

[1] (美)冈萨雷斯(Gonzalez, R.C.), (美)伍兹(Woods,等. 数字图像处理[M]. 电子工业出版社, 2013.

没有整理与归纳的知识,一文不值!高度概括与梳理的知识,才是自己真正的知识与技能。 永远不要让自己的自由、好奇、充满创造力的想法被现实的框架所束缚,让创造力自由成长吧! 多花时间,关心他(她)人,正如别人所关心你的。理想的腾飞与实现,没有别人的支持与帮助,是万万不能的。
    本文转自wenglabs博客园博客,原文链接:http://www.cnblogs.com/arxive/p/5338000.html
,如需转载请自行联系原作者
你可能感兴趣的文章
今天到旅行
查看>>
Spark Streaming使用Kafka保证数据零丢失
查看>>
Linux学习记录--数据流重定向
查看>>
YII 联合查询
查看>>
PHP扩展模块Memcache Redis Mssql部署
查看>>
盘点11个面向文档的开源NoSQL数据库
查看>>
eclipse 快捷键
查看>>
最长有效括按号长度(利用栈解决java语言)
查看>>
用Gvim建立IDE编程环境 (Windows篇)
查看>>
ansible及ansible-palybook使用(持续更新)
查看>>
关于endian的故事,big-endian和little-endian
查看>>
Spring定时任务的几种实现
查看>>
使用JMeter进行性能测试
查看>>
使用@Controller注解为什么要配置<mvc:annotation-driven />
查看>>
彪悍的人生不需要解释
查看>>
近期学习的LINUX 命令
查看>>
域策略 设置本地管理员
查看>>
ie6 css :hover 和 select遮挡问题、和z-index失效问题
查看>>
9月22号
查看>>
Attempted to access a cursor after it has been clo
查看>>