I have used sitk::LabelIntensityStatisticsImageFilter like this:
.... another filters
sitk::Image cc = sitk::SLIC(imgTemp);
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 …
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.
Dave, can you elaborate a little bit here, please ? Can you write me a little piece of pseudo code for “sort of masking” ? Are you talked about sitk::Mask filter ? If you did, what should I put as maskImage ? And for maskingValue ? Sorry for (maybe) so basically questions, I would appreciate your answer.
Ok, here was my masking idea, in Python, because everything is so much easier in Python.
img = sitk.ReadImage("your_label_img.nii")
# make a binary mask image for just value 42
mask_img = (img == 42)
# make an inverse of the mask
inverse_mask = 1-mask_img
# apply inverse_mask so that 42 goes to 0
new_img = img * inverse_mask
You could achieve similar results in C++, but you’d have to use a bunch of math image filters. Like I said, everything is just so much easier in Python.