matlab 番茄,正在做成熟番茄识别,遇到一个小问题,求大神帮忙

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

pic=imread('D:\机械视觉\新建文件夹\图片.jpg'); %载入图象

function result=avefilter(pic)%均值滤波器进行滤波处理

H=[1,1,1;1,1,1;1,1,1];%产生滤波模板

H=h/9;%滤波模板归一化

rgb=im2double(pic);

R=rgb(:,:,1);

G= rgb(:,:,2);

B= rgb(:,:,3);

result_r=conv2(r,h);%对图象进行滤波

result_g=conv2(g,h);%对图象进行滤波

result_b=conv2(b,h);%对图象进行滤波

result=cat(3,result_r,result_g,result_b);

function his=rgb2hsi(rgb) % RGB格式转换成HIS,并提取h分量

rgb=im2double(rgb);

R=rgb(:,:,1);

G=rgb(:,:,2);

B=rgb(:,:,3); %Implement the conversion equations.

num=0.5*((r-g)+(r-b));

den=sqrt((r-g).^2+(r-b).*(g-b));

theta=acos(num./(den+eps));

H=theta;

H(b>g)=2*pi-H(b>g);

H=H/(2*pi);

num=min(min(r,g),b);

den=r+g+b;

den(den==0)=eps;

S=1-3.*num./den;

H(S==0)=0;

I=(r+g+b)/3; %combine all three results into an his image.

his=cat(3,H,S,I);

function result=midfilter(pic) %对提取的h分量进行中值滤波

result=medfilt2(pic,[5 5]);

function result=zhifangtu(pic) %获取直方图

[M,N]=size(pic);

pic=(pic)*100;

pic=floor(pic);

H=zeros(1,100);

for m=1:M

for n=1:N

rk=pic(m,n)+1;

h(rk)=h(rk)+1;

end

end

result=h;

function t=get_yuzhi(h) %获取直方图的阈值

len=length(h);

hmax=0;

hmin=0;

max=0;

for i=1:len

if h(i)>max

max=h(i);

hmax=i;

end

end

t1=(hmax+hmin)/2;

t2=t1;

t=0;

totalh=0;

totalt=0;

num=0;

while abs(t1+t2-2*t)>0.5

t=(t1+t2)/2;

totalh=0;

totalt=0;

for i=1:floor(t)

totalh=totalh+h(i)*i;

totalt=totalt+h(i);

end

t2=(totalh/totalt);

totalh=0;

totalt=0;

for i=floor(t)+1:len

totalh=totalh+h(i)*i;

totalt=totalt+h(i);

end

t1=(totalh/totalt);

num=num+1;

if num==200

break;

end

end

function result=pengzhang(pic) %对图象进行膨胀操作

se=strel('disk',13);

result=imdilate(pic,se);

function result=fushi(pic) %对图象进行腐蚀操作

se=strel('disk',8);

result=imdilate(pic,se);

[1,num]=bwlabel(h_pengzhang2,8);

function res=zhongxin(pic,num) %求取重心

[m,n]=size(pic); %m hang

temp=1:num;

ii=zeros(1,num);

jj=zeros(1,num);

count= zeros(1,num);

for io=1:num

for i=1:m

for j=1:n

if pic((i-1)*n+j)==temp(io)

ii(io)=ii(io)+i;

jj(io)=jj(io)+j;

count=count+1;

end

end

end

end

res=[ii./count;jj./count];

错误: 文件:avefilter.m 行:119 列:1

脚本中的所有函数都必须以 'end' 结束。

你可能感兴趣的:(matlab,番茄)