Error using == Matrix dimensions must agree.
Show older comments
I'm using the code below to find values, that is smaller than 500, but I get this error:
"Error using == Matrix dimensions must agree".
any one knows how to fix this problem?
thanks.
my code:
// BW is an image that I'm working on.
L = bwlabeln(BW);
s = regionprops(L);
Areal=[s.Area];
[~,dx] = find(Areal >= 500);
BW(L == dx)=0;
figure (5)
imagesc(BW)
1 Comment
Adam
on 14 Oct 2014
Does the error message not indicate the line which caused it?
Accepted Answer
More Answers (1)
Image Analyst
on 14 Oct 2014
You could try this:
% Prior to here, use your same code to get BW. Then...
labeledImage = bwlabeln(BW);
s = regionprops(labeledImage,'Area');
allAreas = [s.Area];
% Do the size filtering.
keeperIndexes = find(allAreas <= 500); % These are the ones that we want!
filteredLabeledImage = ismember(labeledImage, keeperIndexes);
% Apply a variety of pseudo-colors to the remaining regions and display them
coloredLabelsImage = label2rgb (filteredLabeledImage , 'hsv', 'k', 'shuffle');
% Display the pseudo-colored image.
imshow(coloredLabelsImage);
% Now measure again on the new labeled image to get areas
% of only those blobs > 50 and <= 500 pixels in area.
s = regionprops(filteredLabeledImage,'Area');
allAreas = [s.Area];
Categories
Find more on Region and Image Properties in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!