%%bound2im为自定义函数,需放到MATLAB当前路径中一起运行
I = imread('peppers.png');
red = 2*I(:,:,1)-I(:,:,2)-I(:,:,3);%超红色模型
t = graythresh(red);%OUTS自适应阈值
red_bw = im2bw(red,t);%二值化
%%%腐蚀
se = strel('disk',10);
red_imerode = imerode(red_bw,se);
%%%膨胀
se = strel('disk',10);
red_dilate = imdilate(red_bw,se);
%%%第一种提取方法,不需要那个附加的自定义函数%%%
g = bwperim(red_dilate,4);
%%%%%第二种提取方法%%%%
%b = bwboundaries(red_dilate,'noholes',‘conn’,4);%轮廓提取
%%%找出最长边界
%d = cellfun('length',b);
%[maxd,k] = max(d);
%b = b{k};
%%%
%[m,n] = size(I);%获取原图像大小,用于确定边界图像大小
g = bound2im(b,m,n);%产生边界图像