- Where did you insert this code.
- A copy of the complete error message is important usually.
I got an error as Function definitions are not permitted in this context.
1 次查看(过去 30 天)
显示 更早的评论
This is my code, I want to compute threshold of an image.I copied this code from internet.I am getting some problem in function definition. How to overcome this. Thanks in advance.
function level=isodata(I)
I = im2uint8(I(:));
% STEP 1: Compute mean intensity of image from histogram, set T=mean(I) [counts,N]=imhist(I); i=1; mu=cumsum(counts); T(i)=(sum(N.*counts))/mu(end); T(i)=round(T(i));
% STEP 2: compute Mean above T (MAT) and Mean below T (MBT) using T from % step 1 mu2=cumsum(counts(1:T(i))); MBT=sum(N(1:T(i)).*counts(1:T(i)))/mu2(end);
mu3=cumsum(counts(T(i):end)); MAT=sum(N(T(i):end).*counts(T(i):end))/mu3(end); i=i+1; % new T = (MAT+MBT)/2 T(i)=round((MAT+MBT)/2);
% STEP 3 to n: repeat step 2 if T(i)~=T(i-1) while abs(T(i)-T(i-1))>=1 mu2=cumsum(counts(1:T(i))); MBT=sum(N(1:T(i)).*counts(1:T(i)))/mu2(end);
mu3=cumsum(counts(T(i):end));
MAT=sum(N(T(i):end).*counts(T(i):end))/mu3(end);
i=i+1;
T(i)=round((MAT+MBT)/2);
Threshold=T(i);
end
% Normalize the threshold to the range [i, 1].
level = (Threshold - 1) / (N(end) - 1);
1 个评论
Jan
2014-10-20
The most important details are not explained directly:
回答(1 个)
Jan
2014-10-20
Function definitions are not allowed in the command line and not inside scripts. This topic has been discussed frequently in this forum and searching for the error message will reveal, how function files are created: They start with the keyword "function".
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Low-Level File I/O 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!