BW cluster removal based on size (all parameters identified)

4 ビュー (過去 30 日間)
Brian
Brian 2016 年 2 月 9 日
編集済み: Brian 2016 年 2 月 10 日
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".
  1 件のコメント
Brian
Brian 2016 年 2 月 10 日
編集済み: Brian 2016 年 2 月 10 日
Always to the rescue. Thank you much! I will check out your tutorials as well.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by