Commit 972a814a authored by remicres's avatar remicres
Browse files

ENH: sort objects labels from left to right, then top to bottom

parent 01d93ed8
......@@ -12,17 +12,17 @@ namespace lsrm
const unsigned int width,
const unsigned int height)
{
LabelImageType::IndexType index;
LabelImageType::SizeType size;
LabelImageType::RegionType region;
LabelImageType::IndexType labelImageRegionStart;
LabelImageType::SizeType labelImageRegionSize;
LabelImageType::RegionType labelImageRegion;
index[0] = 0; index[1] = 0;
size[0] = width; size[1] = height;
region.SetIndex(index);
region.SetSize(size);
labelImageRegionStart[0] = 0; labelImageRegionStart[1] = 0;
labelImageRegionSize[0] = width; labelImageRegionSize[1] = height;
labelImageRegion.SetIndex(labelImageRegionStart);
labelImageRegion.SetSize(labelImageRegionSize);
LabelImageType::Pointer label_img = LabelImageType::New();
label_img->SetRegions(region);
label_img->SetRegions(labelImageRegion);
label_img->Allocate();
using LabelImageIterator = itk::ImageRegionIterator<LabelImageType>;
......@@ -39,13 +39,29 @@ namespace lsrm
for (auto& pix: borderPixels)
{
index[0] = pix % width;
index[1] = pix / width;
label_img->SetPixel(index, label);
labelImageRegionStart[0] = pix % width;
labelImageRegionStart[1] = pix / width;
label_img->SetPixel(labelImageRegionStart, label);
}
++label;
}
// Sort labels in their appearance order from left->right to top->bottom
const LabelImageType::InternalPixelType noDataLabel = 0;
vnl_vector<LabelImageType::InternalPixelType> lut(label,noDataLabel);
label=1;
for(it.GoToBegin();!it.IsAtEnd(); ++it)
{
unsigned int inputLabel = it.Get();
if (lut[ inputLabel ] == noDataLabel)
{
lut[ inputLabel ] = label;
label++;
}
}
for(it.GoToBegin();!it.IsAtEnd(); ++it)
it.Set(lut[it.Get()]);
// Fill holes
typedef itk::GrayscaleFillholeImageFilter<LabelImageType,LabelImageType> FillholeFilterType;
FillholeFilterType::Pointer fillFilter = FillholeFilterType::New();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment