hello,
I am using label map to remove some undesirable regions in binary image.
first, call BinaryImageToShapeLabelMapFilter to get label map, then output the label map and all the objects’ centroids.
I have checked the label map result’s m_labelobject_container, before output it to the main function, its object container is normal. and when I have got the label map in main function,all the elements in m_labelobject_container is null.
Is there anything wrong with my code?
how to output the label map normally?
thanks a lot.
Here is my code segment:
template< typename PixelType = bool, uint16_t dim = 3 >
static void GetCenroidofObjects(itk::SmartPointer<itk::Image<PixelType, dim>>& image,
std::map<int, itk::Point<double, dim>>& rmCen,
itk::LabelMap<itk::ShapeLabelObject<uint64_t, dim>>*& outLabelMap)
{
//** calculate all the regions's priority**//
using BinaryImageToShapeLabelMapFilterType = itk::BinaryImageToShapeLabelMapFilter<itk::Image<PixelType, dim>>;
BinaryImageToShapeLabelMapFilterType::Pointer binaryImageToShapeLabelMapFilter =
BinaryImageToShapeLabelMapFilterType::New();
binaryImageToShapeLabelMapFilter->SetFullyConnected(true);
binaryImageToShapeLabelMapFilter->SetInput(image);
binaryImageToShapeLabelMapFilter->Update();
/*auto*/ outLabelMap = binaryImageToShapeLabelMapFilter->GetOutput();
auto num = outLabelMap->GetNumberOfLabelObjects();
//uint16_t largestAreaIdx = 0;
/*uint64_t largestArea = 0;*/
mippVolumeEngineLog::GetInstance()->PrintDebugInfo(LogInfoType::Information,
L"region num", std::to_wstring(num));
//concurrency::parallel_for(0, int(num), [&](uint32_t i)
for (unsigned int i = 0; i < num; i++)
{
BinaryImageToShapeLabelMapFilterType::OutputImageType::LabelObjectType* labelObject =
outLabelMap->GetNthLabelObject(i);
rmCen.emplace(std::make_pair(labelObject->GetLabel(),labelObject->GetCentroid()));
}//);
}
int main()
{
using CentroidType = itk::Point<double, g_Dimension>;
itk::LabelMap<itk::ShapeLabelObject<uint64_t, 3>>* outLabelMap;
std::map<int, CentroidType> mCen;
ITKWrapper::GetCenroidofObjects<bool>(binRes, mCen, outLabelMap);
//outLabelMap->RemoveLabel(2000);
}