Please help with thresholding and bwareaopen to make binary image

1 view (last 30 days)
I am thresholding a stack of images that look quite similar (serial CT scans of a model) into binary images (see sample image below) in the hopes of finding the centroids of circular region A in each image. The location of that cluster is grossly the same across the images, but I need the accurate measurement of its centroid coordinates.
I would love to have help on the following: In my stack of images (in the hundreds), some images do not have unwanted clusters (as indicated in yellow) after thresholding and bwareaopen, so the centroid of that image is unique (and correctly belongs to A). However, multiple images have unwanted clusters that persist despite setting size thresholds. Is there a way to avoid having these unwanted pieces after bwareaopen? I am curious as to how to set a bwareaopen constrain on circularity to filter out the bottom pieces. But I also don't know how I would eliminate the circle on the right side of the image. I would love to only have circle A left on the final thresholding result, because I would need to capture its area too.
My partial script to look for the centroid is as follows:
for i = 1:216
tmp = I{i};
tmp(tmp>est_bg_HUmean(i)+2*est_bg_HUsd(i))=1; % thresholding to make binary
tmp(tmp~=1)=0;
tmp=imfill(tmp);
tmpout = xor(bwareaopen(tmp,1500), bwareaopen(tmp,10000)); % boundaries b/c wanted R insert size >2500
s = regionprops(tmpout,'centroid');
clear tmp tmpout
centroids_R_insert{i} = nearest(cat(1, s.Centroid));
end

Answers (1)

Image Analyst
Image Analyst on 22 Aug 2016
Work on the 3-D image not the 2D slices. Then use Imclearborder to get rid of the ones that touch the borders of the image, and look at the solidity of the objects in regionprops to get rid of the curved one.
  2 Comments
Brian
Brian on 22 Aug 2016
Thank you for your suggestion, Image Analyst! The clusters actually weren't touching any of the borders. But I found out that you could pad the images to remove all the unwanted clusters. Great!
Image Analyst
Image Analyst on 24 Aug 2016
I don't see how padding the image would remove clusters. If you cropped the image, then imclearborder would remove them, but not padding, unless you padded it with true/1/255/white, but last I checked padarray() did not let you specify the padding value.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!