BW cluster removal based on size (all parameters identified)

4 次查看(过去 30 天)
Hello all,
I have a stack of 512 by 512 labeled binary images ("lab") from which I wish to remove clusters that are smaller than 8 pixel sizes in dimension. The cell array "idx" contains 33 matrices, specifying the indices of clusters that are larger than 8 pixel sizes in each of the 33 slices.
I encounter the error: "Error using ~= Matrix dimensions must agree." with the following code when I attempt my removal.
lab_large = zeros(512,512,33);
for i = 1:33
tmp = lab(:,:,i);
tmp2 = idx{i};
tmp(tmp~=tmp2(:))=0;
tmp(tmp~=0)=1;
lab_large(:,:,i) = tmp;
end
How should I tell MATLAB to maintain clusters identified in "idx" from "lab" and turn everything else into zeros?
I am aware that morphology operations may achieve a similar result with imclose, but I want to minimize altering the shapes of the surviving clusters.
Thank you so much!

采纳的回答

Image Analyst
Image Analyst 2016-2-9
编辑:Image Analyst 2016-2-9
You can use bwareaopen() to get rid of blobs less than a certain size. If you have a bunch of other criteria, like circularity or solidity or whatever, then you can get rid of blobs by passing the list of indexes into ismember(). See my Image Segmentation Tutorial at http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862
binaryImage = bwareaopen(binaryImage, 8); % Only 8 pixels or bigger survive.
or
labeledImage = bwlabel(binaryImage);
indexesToKeep = [2,4,13,33]; % Whatever....
newBinaryImage = ismember(labeledImage, indexesToKeep) > 0;
By the way, in image processing we don't call them "clusters". They're called "blobs" or "connected components".

更多回答(0 个)

类别

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