使用 detectMSERFeatures 时出错

Error in using detectMSERFeatures

我试图做一些形态学操作,然后尝试了 detectMSERFeatures。我得到 error.can 你建议我在 matlab 中遇到的 code.The 错误中的任何 alternative/correction 也被引用

Img= imread('sub.png');
figure,imshow(Img);title('Original Image')
Img=double(Img);
m1=Img>40;
sd = stdfilt(Img, ones(3,3));
Img = Img.*m1;
figure,imshow(Img);
Img = bwareaopen(Img,50);
figure,imshow(Img);
% Detect and extract regions
mserRegions = detectMSERFeatures(Img);
mserRegionsPixels = vertcat(cell2mat(mserRegions.PixelList));  % extract regions
% Visualize the MSER regions overlaid on the original image
figure; imshow(Img); hold on;
plot(mserRegions, 'showPixelList', true,'showEllipses',false);
title('MSER regions');
% Convert MSER pixel lists to a binary mask
mserMask = false(size(Img));
ind = sub2ind(size(mserMask), mserRegionsPixels(:,2),mserRegionsPixels(:,1));
mserMask(ind) = true;

hy = fspecial('sobel');
hx = hy';
Iy = imfilter(double(Img), hy, 'replicate');
Ix = imfilter(double(Img), hx, 'replicate');
gradmag = sqrt(Ix.^2 + Iy.^2);
edgeMask=gradmag;
figure, imshow(gradmag,[]), title('gradmag')
edgeAndMSERIntersection = edgeMask & mserMask;
figure; imshowpair(edgeMask, edgeAndMSERIntersection, 'montage');
title('Gradient and intersection of Gradient with MSER regions')
[label n]=bwlabel(edgeAndMSERIntersection);
figure,imshow(label2rgb(label,'jet','k','shuffle'));

我收到如下错误

    Error using images.internal.imageDisplayValidateParams>validateCData (line 119)
If input is logical (binary), it must be two-dimensional.

Error in images.internal.imageDisplayValidateParams (line 27)
common_args.CData = validateCData(common_args.CData,image_type);

Error in images.internal.imageDisplayParseInputs (line 78)
common_args = images.internal.imageDisplayValidateParams(common_args);

Error in imshow (line 223)
  [common_args,specific_args] = ...

Error in ex7 (line 11)
figure,imshow(m3);

你得到的错误输出可以用你的一行代码从底部读取,当你向上读取这些行时,它会深入到调用堆栈中。所以最上面一行给出了实际抱怨的函数和它给出的原因。

这一行表示,对于逻辑输入,图像必须是二维的。如果你给它 3 维数据,那么它被假定为颜色但它不能接受逻辑值 - 逻辑值是二进制值,它只能是 true/false (并且可以用 0 和 1 表示,有时很难区分普通的 uint 或 float)。

原因在错误报告的另一端,在最后一行:

figure,imshow(m3);

这通常是您代码中的一行。现在这一行没有出现在您提供的代码示例中,所以我从这里猜测,但首先要做的是检查 m3 变量的属性。你可以用

找到它的尺寸
size(m3)

最有可能的两种情况是 a)。 m3 有两个以上的维度。也许它是针对标量设置阈值的彩色图像。或者 b)。 m3 小于二维。也许你已经对它做了一些操作来降低它的维度,比如总和或平均值。

如果这不能帮助您找到错误的来源,我建议粘贴 ex7 script/function 的其他行。错误发生在第 11 行,因此至少前 11 行是有用的。如果它是一个函数,那么查看生成函数输入的代码会很有帮助。