|
30-基于中值的Ostu图像分割方法
百度网盘链接:https://pan.baidu.com/s/1Ciw1JIZC_joe-AAbzb2JnA
具体链接在halcom.cn论坛,联系人QQ:3283892722
该论坛是一个学习交流平台,我会逐一的和大家分享学习。
欢迎大家录制视频,你可在论坛进行打赏分享。
视频专用播放器:http://halcom.cn/forum.php?mod=viewthread&tid=258&extra=page%3D1\
- clc,clear,close all
- warning off
- im = imread('lena.tif');
- figure(1), imshow(im)
- [count, grayvalue] = imhist(im);
- L = 256;
- if(size(im,3)>1)
- im = rgb2gray(im);
- end
- [m,n] = size(im);
- f = count./(m*n);
- for i=1:L
- if(f(i)~=0)
- st = i;
- break;
- end
- end
- for i=L:-1:1
- if(f(i)~=0)
- ed = i;
- break;
- end
- end
- j=1;
- for i=1:ed-st
- w0(j) = sum( f(1:i) );
- j=j+1;
- end
- w0 = w0+0.001;
- w1 = 1-w0;
- m0 = median(1:ed-st);
- m1 = median(ed-st+1:L);
- mad1=0;
- for i=1:ed-st
- mad1 = mad1+f(i)./w0 * abs(i-m0);
- end
- mad2=0;
- for i=ed-st+1:L
- mad2 = mad2+f(i)./w1 * abs(i-m1);
- end
- k=w0.*mad1 + w1.*mad2;
- [value, index] = min(k);
- thr = st + index;
- bw = im>thr;
- figure(2), imshow(bw)
复制代码
|
|