필터 지우기
필터 지우기

BW cluster removal based on size (all parameters identified)

조회 수: 11 (최근 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 CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by