Extract image using threshold

Hello, can you advise me the most efficient combination of filters to extract region of image based on threshold value? (ie reduce the image by margins that are below the defined threshold value)

In SimpleITK you could convert your threshold into a label image, and then run the LabelShapeStatisticsImageFilter. One of the methods is GetBoundingBox, which you can use to extract the image region. Here’s the documentation for the filter:

https://itk.org/SimpleITKDoxygen/html/classitk_1_1simple_1_1LabelShapeStatisticsImageFilter.html

In ITK, the equivalent is the LabelGeometryImageFilter, although I haven’t used that myself.

https://itk.org/Doxygen/html/classitk_1_1LabelGeometryImageFilter.html

What you might need is BinaryThresholdImageFilter. Then followed by iterator pass to determine bounds of your object, or use LabelGeometryImageFilter if you prefer use of existing filters over efficient code. Finally use RegionOfInterestImageFilter to get the image reduced to only the extracted object.

Hello Dave. Based on your words, I have tried:

BOOL CMyDoc::Segement5(sitk::Image& img)
{
	sitk::Image imgTemp(img);
	sitk::LabelShapeStatisticsImageFilter statistic;
	statistic.Execute(imgTemp);
	statistic.SetBackgroundValue(200);
	std::vector<unsigned int> box = statistic.GetBoundingBox(20);
	sitk::ConfidenceConnectedImageFilter confidence;
	confidence.SetSeed(box);
	img = confidence.Execute(imgTemp);

Now, img object I have transferred forward into VTK and I visualized as vtkVolume (color), but I see only a diffuse cube. Can you lead me into a bone segmentation ? I need to remove a bone from a VTK volume, or, at least to color it.

Of course, I have tried with other SetBackgroundValue values, none of them had worked.

Of course, I have tried every algorithm from here: http://insightsoftwareconsortium.github.io/SimpleITK-Notebooks/Python_html/300_Segmentation_Overview.html

I guess I need a good values for this task …

SetBackgroundValue has to be called before the Execute. Execute is when the stats are actually computed. After that, SetBackground won’t have any effect unless you call Execute again.

David, you had right :slight_smile:

BOOL CMyDoc::Segement5(sitk::Image& img)
{
	sitk::Image imgTemp(img);
	sitk::LabelShapeStatisticsImageFilter statistic;
	statistic.SetBackgroundValue(200);
	statistic.Execute(imgTemp);
	std::vector<unsigned int> box = statistic.GetBoundingBox(20);
	sitk::ConfidenceConnectedImageFilter confidence;
	confidence.SetSeed(box);
	img = confidence.Execute(imgTemp);

But after I corrected the order of code, I got no segmentation organ … of course, due to statistic.SetBackgroundValue(200); and / or statistic.GetBoundingBox(20);

Where can I find proper values for bone segmentation ?

Hello @flaviu2,
If you are working with CT there are known Hounsfield unit values for bone. If you are working with another modality the value may not be consistent (MR will vary across machines), so you will have to compute threshold values for each image.

Thank Ziv. I have a CT modality, and I am struggle to find a SimpleITK filter to achieve that. And I’ve found sitk::ConfidenceConnected, but I don’t know where to put those HU values for bones … look, I wrote this:

std::vector<std::vector<unsigned int>> list;
InitializeList2(list);

    sitk::Image img;
	sitk::Image imgTemp(img);
	img = sitk::ConfidenceConnected(imgTemp, list, 5, 2.5, 2, 200);

and the list is:

void CMyDoc::InitializeList2(std::vector<std::vector<unsigned int>>& list)
{
	std::vector<unsigned int> sub;
	sub.push_back(1000);
	sub.push_back(1200);
	sub.push_back(1900);
	list.push_back(sub);
}

but I got bone segmentation … only a diffuse noising cube … obviously, I didn’t write something right, or, more probably, I didn’t understand something right :slight_smile:

Ok. Well, segmentation based on thresholds is a very basic approach and will rarely work, sometimes with luck it will. ConfidenceConnected does not allow for explicit thresholds, ConnectedThreshold does.

If you don’t mind reading Python code, this jupyter notebook illustrates how to use several region growing filters including the two mentioned above.

1 Like

With every discussion from here, some things become clearly ! Many many thanks !
So, in order to use my clicks points, I should not use ConfidenceConnected filter because does not allow explicit thresholds. For this approach, I need to use ConnectedThreshold filter.

Now I am gonna figure out how to use vtkCellPicker point inside ConnectedThreshold filter … :roll_eyes:

Yaniv, thank you a lot for your words, if you have more, don’t hesitate to provide me :slight_smile:

Flaviu.