【问题标题】:Edge detection using fuzzy threshold value in matlab在matlab中使用模糊阈值进行边缘检测
【发布时间】:2013-04-20 00:52:48
【问题描述】:

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

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);

【问题讨论】:

    标签: matlab edge-detection


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2016-01-08
      • 1970-01-01
      • 2016-08-26
      • 1970-01-01
      • 2012-12-31
      • 2018-12-21
      • 1970-01-01
      • 2014-05-01
      • 1970-01-01
      相关资源
      最近更新 更多