利用matlab中的模糊阈值进行边缘检测

时间:2013-04-19 15:51:03

标签: matlab edge-detection

有人可以解释为什么我的代码中出现以下错误吗?

I=imread('lena.jpg');
[M,N]=size(I);
p = zeros(256,3);
for ii=1:256 p(ii,1)=ii-1; end;
p(:,2) = imhist(I);
p (p(:,2)==0,:) = []; % remove zero entries in p
% Calling Shannon procedure, return t1 value and its location in p
[T1,Loc]=Shannon(p);
% Calling Tsallis procedure of Part1
pLow= p(1:Loc,:); T2= Tsallis_Sqrt(pLow);
% Calling Tsallis procedure of Part2
pHigh=p(Loc+1:size(p),:); T3=Tsallis_Sqrt(pHigh);
% Cerate binary matrices f
f=zeros(M,N);
for i=1:M;
for j=1:N;
if ((I(i,j)>= T2)&(I(i,j)<T1))|(I(i,j)>= T3)
f(i,j)=1; end;
end;
end
% Calling EdgeDetector procedure, return edge detection image.
[g]= EdgeDetector(f);
figure;
imshow(g);

我使用香农熵来找到阈值。为此,我创建了树函数:Shannon(p),Tsallis_Sqrt(p),EdgeDetector(f)。但我在主文件中收到此错误。请帮我解决这个错误。

??? Error using ==> iptcheckinput
Function IMHIST expected its first input, I or X, to be two-dimensional.

Error in ==> imhist>parse_inputs at 270
iptcheckinput(a, {'double','uint8','logical','uint16','int16','single'}, ...

Error in ==> imhist at 57
[a, n, isScaled, top, map] = parse_inputs(varargin{:});

Error in ==> MainProgram at 6
p(:,2) = imhist(I);

1 个答案:

答案 0 :(得分:1)

imhist(I)的第一个参数必须是灰度(强度)图像。您的I可能是RGB 3通道图像。 RGB图像有3个维度,但函数期望二维矩阵作为输入,这就是你得到错误的原因。

您可以考虑先将图像转换为灰度格式

rgbimage = imread('lena.jpg');
I = rgb2gray(RGB);