[Insight-users] Sparse image for building distance field
Dan Mueller
dan.muel at gmail.com
Fri Mar 22 15:58:51 EDT 2013
Hi Sergiy,
You might also be interested in the following Insight Journal article:
http://www.insight-journal.org/browse/publication/646
It is quite old, so I doubt it will compile with the latest ITK without
modifications...
HTH
Cheers, Dan
On 22 March 2013 23:16, Sergiy Tkachuk <sergtk.job at gmail.com> wrote:
> Hello all,
>
> I want to build distance field for the object.
> My object is very sparsed and I want to build distance field for it and
> not to allocate memory for every voxel in the grid.
> Number of voxel in 3d grid is about 10^10 (more precisely: 2000x2000x2000)
> Number of voxel in object itself is about 10^6.
>
> I tried to play with itk::SignedMaurerDistanceMapImageFilter creating
> image 5x5x5 in sandbox:
>
>
> const unsigned int Dimension = 3;
> typedef char InputPixelType;
> typedef float OutputPixelType;
>
> typedef itk::Image<InputPixelType, Dimension> InputImageType;
> typedef itk::Image<OutputPixelType, Dimension> OutputImageType;
>
> InputImageType::Pointer image = InputImageType::New();
>
> InputImageType::SizeType size;
> size[0] = 5;
> size[1] = 5;
> size[2] = 5;
>
> InputImageType::IndexType start;
> start.Fill(0);
>
> InputImageType::RegionType region;
> region.SetIndex(start);
> region.SetSize(size);
>
> image->SetRegions(region);
> image->Allocate();
>
> image->FillBuffer(0);
>
> InputImageType::IndexType index;
>
> // initialize
> InputImageType::IndexType gapIndex;
> gapIndex[0] = gapIndex[1] = gapIndex[2] = 2;
> for (index[0] = 0; index[0] < size[0]; ++index[0])
> for (index[1] = 0; index[1] < size[1]; ++index[1])
> for (index[2] = 0; index[2] < size[2]; ++index[2]) {
> if (index == gapIndex) continue;
> image->SetPixel(index, 1);
> }
>
> // Define the distance map filter and apply it to the image
> typedef itk::SignedMaurerDistanceMapImageFilter<InputImageType,
> OutputImageType> DistanceFilterType;
> DistanceFilterType::Pointer distanceFilter = DistanceFilterType::New();
> distanceFilter->SetInput(image);
> distanceFilter->SetBackgroundValue(0);
> distanceFilter->SetSquaredDistance(false);
> distanceFilter->Update();
>
> // Output distance field values
> for (int x = 1; x < size[0]-1; ++x)
> {
> for (int y = 1; y < size[1]-1; ++y)
> {
> for (int z = 1; z < size[2]-1; ++z)
> {
> InputImageType::IndexType ind;
> ind[0] = x;
> ind[1] = y;
> ind[2] = z;
>
> float value = distanceFilter->GetOutput()->GetPixel(ind);
> std::cout << x << " " << y << " " << z << " -> " << value
> << std::endl;
> }
> }
> }
>
>
> The code works fine.
> But it requires memory for every voxel of grid, and this is not acceptable
> for 10^10 voxels.
>
> Is it possible to use some kind of sparse structure to build distance
> field?
>
> I read about itk::SparseImage, but it seems this structure is sparse
> concerning value only, but indices are allocated for the whole grid. Am I
> undestood correctly? If no, I will be glad if somebody point out where I am
> mistaken. Thanks.
>
> If itk::SparseImage is not sutable in my case, is it possible to implement
> custom Image format for input to itk::SignedMaurerDistanceMapImageFilter?
> If so, are the any useful guidelines to achieve this?
> For now it is not clear for me how to correctly derive my Image type from
> DataObject and handle regions - I don't need full power of ITK filter
> pipeline, just to call itk::SignedMaurerDistanceMapImageFilter - possibly
> this helps me to simplify custom image implementation.
>
> Any ideas could be helpful for me!
>
> Thanks in advance,
> Sergiy
>
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.php
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20130323/a826faea/attachment.htm>
More information about the Insight-users
mailing list