- 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!