Reputation: 437
I was trying to do some morphological operation and then tried detectMSERFeatures. I'm getting error.can you suggest any alternative/correction in the code.The error I had in the matlab is also quoted
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'));
I'm getting error as follows
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);
Upvotes: 2
Views: 722
Reputation: 1635
The error output you are getting can be read from the bottom with a line of your code, and as you read the lines upwards it goes deeper into the call stack. So the top line gives the function that actually complained and the reason it gives.
On this line it says that, for logical inputs, the image has to be 2-dimensional. If you give it 3-dimensional data then it's assumed to be colour but then it can't accept logical values - a logical value is a binary one, it can only be true/false (and can be represented with 0 and 1, which sometimes makes it hard to tell apart from a normal uint or float).
The reason for this is at the other end of the error report, in the bottom line:
figure,imshow(m3);
this will be a line from your code usually. Now this line doesn't appear in the code sample you gave so I'm guessing from here but the first thing to do is check the properties of the m3
variable. You can find its dimensions with
size(m3)
The two likeliest scenarios are that a). m3
has more than two dimensions. Perhaps it's a colour image that's been thresholded against a scalar. Alternatively b). m3
has less than two dimensions. Perhaps you've done some operation on it which reduced its dimensionality like a sum or a mean.
If this doesn't help you find the source of the error I would suggest to paste the other lines of the ex7
script/function. The error occurs at line 11 so at least the first 11 lines would be useful. If it's a function then it would be helpful to see the code that produces the inputs to the function.
Upvotes: 2