|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
x=imread('QRcode.jpg');
%figure;
%imshow(x);
[m,n]=size(x);
N=m*n;
num=zeros(1,256);%生成一个1*256的全0矩阵%
p=zeros(1,256);
for i=1:m
for j=1:n
num(x(i,j)+1)=num(x(i,j)+1)+1;
end
end
for i=0:255;
p(i+1)=num(i+1)/N;%计算灰度值为i的像素点出现的概率%
end
totalmean=0;
for i=0:255;
totalmean=totalmean+i*p(i+1);%总体的均值%
end
maxvar=0;
for k=0:255
kk=k+1;
zerosth=sum(p(1:kk));
firsth=0;
for h=0:k
firsth=firsth+h*p(h+1);
end
var=totalmean*zerosth-firsth;
var=var*var;
var=var/(zerosth*(1-zerosth)+0.01);
var=sqrt(var);
if(var>maxvar)
maxvar=var;
point=k;
end
end
threshold=point
这是用ostu求图像二值化阈值的,一运行就显示??? Error using ==> +
Function '+' is not defined for values of class 'uint8'.
Error in ==> c:\MATLAB6p5\work\Untitled12.m
On line 12 ==> num(x(i,j)+1)=num(x(i,j)+1)+1;
我把 num(x(i,j)+1)=num(x(i,j)+1)+1;改为 num(x(i,j))=num(x(i,j))+1;又显示??? Subscript indices must either be real positive integers or logicals.
Error in ==> c:\MATLAB6p5\work\Untitled12.m
On line 12 ==> num(x(i,j))=num(x(i,j))+1
我觉得线标没有超出范围啊,可就是不对,请问哪位高手会吗 |
-
|