Find clusters with specific value in 3D matrix

10 views (last 30 days)
Hello,
I have an image of the size (91*109*91). The image contains voxels with values from 0 to 1. Now I would like to discard all voxels instead of those meeting the following conditions:
  1. They have a value smaller than .05
  2. they are part of cluster (connected voxels) of minimum 30 voxels with value < .05
At the end, I would like to have a 91*109*91 matrix/image containing only clusters of voxels with a value < 0.05.
I can figure out the first condition, what’s tricky for me is the second condition.
  1 Comment
Matt J
Matt J on 20 Feb 2019
Edited: Matt J on 20 Feb 2019
At the end, I would like to have a 91*109*91 matrix/image containing only clusters of voxels with a value < 0.05.
And all discarded voxel values set to what? Zero? NaN?

Sign in to comment.

Accepted Answer

Matt J
Matt J on 20 Feb 2019
Edited: Matt J on 21 Feb 2019
S=regionprops(yourImage<0.05,'Area','PixelIdxList');
S=S([S.Area]>=30); %edited
result=zeros(size(yourImage));
for i=1:numel(S)
idx=S(i).PixelIdxList;
result(idx)=yourImage(idx);
end
  3 Comments
Matt J
Matt J on 20 Feb 2019
Never mind regionprops3.Here's a version with regionprops
S=regionprops(yourImage<0.05,'Area','PixelIdxList');
S=S([S.Volume]>=30);
result=zeros(size(yourImage));
for i=1:numel(S)
idx=S(i).PixelIdxList;
result(idx)=yourImage(idx);
end
nivons
nivons on 21 Feb 2019
Great! That works, thanks!
small error though: it has to be S=S([S.Area]>=30);

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!