# LabelMapToLabelImageFilter\`s output is an image with white color

**URL:** https://discourse.itk.org/t/labelmaptolabelimagefilter-s-output-is-an-image-with-white-color/5316
**Category:** Algorithms
**Tags:** itk, c
**Created:** [September 5, 2022, 9:44am UTC](https://discourse.itk.org/t/labelmaptolabelimagefilter-s-output-is-an-image-with-white-color/5316 "2022-09-05T09:44:12Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Bugmaker](https://discourse.itk.org/user_avatar/discourse.itk.org/bugmaker/32/2500_2.png) [@Bugmaker](https://discourse.itk.org/u/Bugmaker)
#### Post date: [September 5, 2022, 9:44am UTC](https://discourse.itk.org/t/labelmaptolabelimagefilter-s-output-is-an-image-with-white-color/5316/1 "2022-09-05T09:44:12Z")

</div>

I want to use the ConnectedComponentImageFilter to delete the false positive area, and pass the result through other filters ( **LabelImageToShapeLabelMapFilter** , **LabelMap** , **LabelMapToLabelImageFilter** namely) to convert into image.

I find the background of the final result turn white and that the white background obscured the label.  
However, when i use itk-snap to update, the 3d volume is right, and Each vertebra is clearly segmented.

```auto
typedef itk::Image<float, 3> ImageTypeFloat;
typedef itk::Image<int, 3>	ImageSeg;
using LabelObject = itk::ShapeLabelObject<int, 3>;
using LabelMap = itk::LabelMap<LabelObject>;
using ConnectComment = itk::ConnectedComponentImageFilter<ImageTypeFloat, ImageSeg>;
using LabelImageToLabelMapFilter = itk::LabelImageToShapeLabelMapFilter<ImageSeg, LabelMap>;
using L2IType = itk::LabelMapToLabelImageFilter<LabelMap, ImageTypeFloat>;
using LabelShapeKeepNObject = itk::LabelShapeKeepNObjectsImageFilter<ImageSeg>;
using ImageRegionIterator = itk::ImageRegionConstIterator<ImageTypeFloat>;
using ImageIterator = itk::ImageRegionIterator<ImageTypeFloat>;
ConnectComment::Pointer connectcomment = ConnectComment::New();

WriteType::Pointer writer = WriteType::New();
ImageIOTypeNII::Pointer niftio = ImageIOTypeNII::New();

connectcomment->SetInput(img);
connectcomment->SetBackgroundValue(0);
connectcomment->Update();
LabelImageToLabelMapFilter::Pointer limgtmap = LabelImageToLabelMapFilter::New();
limgtmap->SetInput(connectcomment->GetOutput());
limgtmap->Update();

LabelMap::Pointer labelmap = limgtmap->GetOutput();
for (float label = 0; label < labelmap->GetNumberOfLabelObjects(); label++)
{
	const LabelObject* labelobject = labelmap->GetLabelObject(label);
	labelobject->Print(std::cout);
	std::cout << "-------------------------------------------------------" << std::endl;
}

std::cout << "--------------------------------Process------------------------" << std::endl;

std::vector<LabelObject::Pointer>filter_objects;
for (LabelMap::Iterator in2(labelmap); !in2.IsAtEnd(); ++in2)
{
	if (in2.GetLabelObject()->GetNumberOfPixels() < 10000)
		filter_objects.emplace_back(in2.GetLabelObject());
}
for (int i = 0; i < filter_objects.size(); i++)
	labelmap->RemoveLabelObject(filter_objects[i]);

L2IType::Pointer l2i = L2IType::New();
l2i->SetInput(labelmap);
l2i->Update();

ImageTypeFloat::Pointer res = l2i->GetOutput();
res->SetSpacing(img->GetSpacing());
res->SetDirection(img->GetDirection());

writer->SetImageIO(niftio);
writer->SetFileName("connect_.nii.gz");
writer->SetInput(res);
writer->Update();

```

the **final result** i have mentioned is **res**

**The res image:**

 ![connect_](https://discourse.itk.org/uploads/default/original/2X/8/8c1308e17fcb3b67dd94c0e2f058b9927180b258.png)

**ITK-Snap seg:**  
 ![itksnap_seg](https://discourse.itk.org/uploads/default/original/2X/8/87b1523dcc17b1f8d0ccbeeab3bdc39d4f22c564.png)

---

<div class="post-metadata">

### Author: ![Bugmaker](https://discourse.itk.org/user_avatar/discourse.itk.org/bugmaker/32/2500_2.png) [@Bugmaker](https://discourse.itk.org/u/Bugmaker)
#### Post date: [September 7, 2022, 7:01am UTC](https://discourse.itk.org/t/labelmaptolabelimagefilter-s-output-is-an-image-with-white-color/5316/2 "2022-09-07T07:01:01Z")

</div>

I solve this problem by changing the itk::LabelImageToShapeLabelMapFilter`s in input datatype and output datatype into Int instead of Float.  
it is seems that there is something wrong with this filter in converting datatype.
