Filter used after LabelIntensityStatisticsImageFilter

I have used sitk::LabelIntensityStatisticsImageFilter like this:

		sitk::Image imgTemp(img);
    .... another filters
		sitk::Image cc = sitk::SLIC(imgTemp);
		sitk::LabelIntensityStatisticsImageFilter stat;
		stat.Execute(cc, imgTemp);
		std::vector<int64_t>::iterator it;
		std::vector<int64_t> labels = stat.GetLabels();
		for (it = labels.begin(); it != labels.end(); ++it)
		{
			double size = stat.GetPhysicalSize(*it);
			if (size >= dValue1 &&
				size <= dValue2)
			{
				// what should I collect here to let in the output image only values between dValue1 and dValue2 ?
			}
		}

in order to know what components are bigger or less than some predefined values (dValue1 and dValue2).

How can I do in order to let as ouput image the values between (predefined) dValue1 and dValue2 ? What SimpleITK filter should I use ?

I have to mention that I am working in C++ only. I said that because I noticed that Python has extra methods …

To remove all labels with a size smaller than dValue1, you can use the RelabelComponentImageFilter. Use the SetMinimumObjectSize method with dValue.

https://simpleitk.org/doxygen/latest/html/classitk_1_1simple_1_1RelabelComponentImageFilter.html

As far as the maximum size, I think you need to do some sort of masking. For labels of size larger than dValue2, mask them out, i.e. change them to 0. You can use the MaskNegatedImageFilter for that:

https://simpleitk.org/doxygen/latest/html/classitk_1_1simple_1_1MaskNegatedImageFilter.html

2 Likes

You can also use the ChangeLabelImageFilter to map input label ids to output label ids. For the case of wanting to remove certain labels the ChangeMap member would contain entries which map labels to be removed to zero.

3 Likes

Yeah, I figured there was a better way of doing it, but my brain was not quite firing on all cylinders. And of course @blowekamp knows the filters (and SimpleITK in general) much better than I do.