我试图做一些形态学操作,然后尝试检测MSERFeatures。我收到错误。您能否在代码中提出任何替代/更正建议。我在 matlab 中遇到的错误也被引用
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);