[Insight-users] Sparse image for building distance field

Sergiy Tkachuk sergtk.job at gmail.com
Thu Mar 28 17:59:37 EDT 2013


Hi Dan,

Thanks a lot for the link!
It looks like what I was looking for!
I tried code and just substituted itk::Image with itk::SparseImage and it
works!

I read your article before at
http://www.kitware.com/media/html/AlternativeMemoryModelsForITK.html .
After this I looked at
http://www.itk.org/Doxygen/html/classitk_1_1SparseImage.html and this
completely measleaded me - implementation of SparseImage in ITK is do
something different. But SparseImage at
http://www.insight-journal.org/browse/publication/646 is ok!

Thanks,
--
Best wishes,
Sergiy Tkachuk



On Fri, Mar 22, 2013 at 9:58 PM, Dan Mueller <dan.muel at gmail.com> wrote:

> 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/20130328/c1a7b000/attachment.htm>


More information about the Insight-users mailing list