Error using == Matrix dimensions must agree.

1 次查看(过去 30 天)
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)

采纳的回答

Guillaume
Guillaume 2014-10-14
The error is because L is the size of the image and dx is any size up to the number of connected components in your image. The two sizes are never going to be the same, hence you can't use == for that.
First, your find should be:
idx = find(Area >= 500);
To then remove all the objects in BW that have an area greater than 500, use ismember:
BW(ismember(L, idx)) = 0;
  7 个评论
Iain
Iain 2014-10-14
This will remove the bits of Areal that correspond to what you've removed from your labelled image:
Areal(Areal >= 500) = [];
Guillaume
Guillaume 2014-10-14
Medhi,
No. Area contains the area of all osteocytes, while idx contains the label number of all osteocytes with an area greater than 500. The two things represent completely different concept.
To get the label number of the osteocytes smaller than 500, you can either
1) reverse the find criteria
idxsmall = find(Areal < 500);
2) compute the set difference (not subtract) between all the labels and idx
idxsmall = setdiff(idx, 1:max(L(:)));

请先登录,再进行评论。

更多回答(1 个)

Image Analyst
Image Analyst 2014-10-14
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];

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by