[ITK-users] LabelGeometryImageFilter: empty output of GetOrientedLabelImage and GetOrientedIntensityImage
Bradley Lowekamp
blowekamp at mail.nih.gov
Tue Apr 7 08:37:49 EDT 2015
Hello,
I have a much improved version of the algorithm to compute oriented bounding boxes here:
https://github.com/blowekamp/itkOBBLabelMap
It is correctly accounts for the image's physical spacing, origin, and direction cosines, significantly faster, and more memory efficient. Here would be a close to turn-key test/example for this task:
https://github.com/blowekamp/itkOBBLabelMap/blob/master/test/itkOrientedBoundingBoxImageLabelMapFilterTest2.cxx
HTH,
Brad
On Apr 7, 2015, at 1:38 AM, Bill Lorensen <bill.lorensen at gmail.com> wrote:
> I have a 2D example that fails when the origin is not 0.0. Now I'll
> try to find the bug.
>
>
> On Mon, Apr 6, 2015 at 10:13 AM, Bill Lorensen <bill.lorensen at gmail.com> wrote:
>> Could be a bug. Need to find a smaller test case that fails. Maybe
>> because of non-zero origin. I'll take a look.
>>
>>
>> On Mon, Apr 6, 2015 at 9:55 AM, Thomas Seidel <seidel at cvrti.utah.edu> wrote:
>>> I tried it again. I am quite sure there is nothing wrong with my input
>>> files because the filter apparently creates correct output measures for
>>> all labels (e.g. eigenvalues, bounding box, volume, etc).
>>> But the orientedlabelimages are all zero, except for label 0 (which is my
>>> background). The dimension of these images corresponds to the size
>>> (length, width, depth) of the oriented bounding boxes.
>>>
>>> I think the image origins are all messed up. May there something be wrong
>>> with the center of rotation?
>>>
>>> E.g.: label 0, which is background, has the same bounding box size as the
>>> input label image.
>>> Input LabelImage:
>>> dimensions: 512 1024 130 (in pixels)
>>> origin: [102.273, 0, 5.96985] (in physical size)
>>>
>>> oriented image of label 0:
>>> dimensions: 1026 515 131
>>> origin: [-51.2878, 50.6859, -0.132971]
>>>
>>>
>>> Is this a bug, or did I forget to set a parameter?
>>>
>>> Thanks,
>>> Thomas
>>>
>>>
>>>
>>>
>>>
>>> On 4/6/15 12:02 AM, "Bill Lorensen" <bill.lorensen at gmail.com> wrote:
>>>
>>>> Thomas,
>>>>
>>>> I compiled your program and ran it on one of my labeled images and it
>>>> produces the expected output.
>>>>
>>>> On Sun, Apr 5, 2015 at 2:52 PM, Thomas Seidel <seidel at cvrti.utah.edu>
>>>> wrote:
>>>>> Hi Bill,
>>>>>
>>>>> Thanks for your answer. Here is (part of the) source I am using.
>>>>> Do you need the image or source files?
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> #include "itkImage.h"
>>>>> #include "itkImageFileReader.h"
>>>>> #include "itkImageFileWriter.h"
>>>>> #include "itkLabelGeometryImageFilter.h"
>>>>>
>>>>> #include "itksys/SystemTools.hxx"
>>>>>
>>>>> #include <sstream>
>>>>>
>>>>>
>>>>> int main(int argc, char * argv[])
>>>>> {
>>>>> // Verify command line arguments
>>>>> if( argc < 2 )
>>>>> {
>>>>> std::cerr << "Usage: " << std::endl;
>>>>> std::cerr << argv[0] << " InputImageFile [-intensity
>>>>> <IntensityImageFile>]" << std::endl;
>>>>> return EXIT_FAILURE;
>>>>> }
>>>>> std::string inputFilename = argv[1];
>>>>> std::string intensityFile;
>>>>> bool calcIntensity = false;
>>>>>
>>>>>
>>>>> int argcounter = 2;
>>>>> while (argc>argcounter)
>>>>> {
>>>>> if (!strncmp(argv[argcounter],"-intensity",10) ) {intensityFile
>>>>> =
>>>>> argv[argcounter + 1]; calcIntensity = true; }
>>>>> argcounter++;
>>>>> }
>>>>>
>>>>> // Setup types
>>>>> typedef itk::Image<unsigned int, 3> IntImageType;
>>>>> typedef itk::Image<float, 3> FloatImageType;
>>>>> typedef itk::ImageFileReader<IntImageType> ReaderType;
>>>>> typedef itk::ImageFileReader<FloatImageType>
>>>>> FloatReaderType;
>>>>>
>>>>> ReaderType::Pointer reader = ReaderType::New();
>>>>> reader->SetFileName( inputFilename );
>>>>> FloatReaderType::Pointer FloatReader = FloatReaderType::New();
>>>>>
>>>>>
>>>>>
>>>>> typedef itk::LabelGeometryImageFilter< IntImageType, FloatImageType >
>>>>> LabelGeometryImageFilterType;
>>>>> LabelGeometryImageFilterType::Pointer labelGeometryImageFilter =
>>>>> LabelGeometryImageFilterType::New();
>>>>> labelGeometryImageFilter->SetInput( reader->GetOutput() );
>>>>>
>>>>>
>>>>> if (calcIntensity)
>>>>> {
>>>>> FloatReader->SetFileName(intensityFile);
>>>>> FloatReader->Update();
>>>>>
>>>>> labelGeometryImageFilter->SetIntensityInput(FloatReader->GetOutput());
>>>>> labelGeometryImageFilter->CalculateOrientedIntensityRegionsOn();
>>>>>
>>>>> }
>>>>>
>>>>>
>>>>> labelGeometryImageFilter->CalculatePixelIndicesOn();
>>>>> labelGeometryImageFilter->CalculateOrientedBoundingBoxOn();
>>>>> labelGeometryImageFilter->CalculateOrientedLabelRegionsOn();
>>>>>
>>>>> labelGeometryImageFilter->Update();
>>>>>
>>>>> LabelGeometryImageFilterType::LabelsType allLabels =
>>>>> labelGeometryImageFilter->GetLabels();
>>>>> LabelGeometryImageFilterType::LabelsType::iterator allLabelsIt;
>>>>> std::cout << "Number of labels: " <<
>>>>> labelGeometryImageFilter->GetNumberOfLabels() << std::endl;
>>>>> std::cout << std::endl;
>>>>>
>>>>>
>>>>>
>>>>> for( allLabelsIt = allLabels.begin(); allLabelsIt != allLabels.end();
>>>>> allLabelsIt++ )
>>>>> {
>>>>>
>>>>> LabelGeometryImageFilterType::LabelPixelType labelValue =
>>>>> *allLabelsIt;
>>>>>
>>>>>
>>>>> std::ostringstream stream;
>>>>> stream << labelValue << ".vtk";
>>>>> typedef itk::ImageFileWriter<IntImageType> WriterType;
>>>>> WriterType::Pointer writer = WriterType::New();
>>>>> writer->SetFileName(stream.str());
>>>>>
>>>>> writer->SetInput(labelGeometryImageFilter->GetOrientedLabelImage(labelVal
>>>>> u
>>>>> e));
>>>>> writer->Update();
>>>>>
>>>>> std::ostringstream stream2;
>>>>> stream2 << labelValue << "-intensity.vtk";
>>>>>
>>>>> if (calcIntensity) {
>>>>> typedef itk::ImageFileWriter<FloatImageType>
>>>>> FloatWriterType;
>>>>> FloatWriterType::Pointer Floatwriter =
>>>>> FloatWriterType::New();
>>>>> Floatwriter->SetFileName(stream2.str());
>>>>>
>>>>> Floatwriter->SetInput(labelGeometryImageFilter->GetOrientedIntensityImage
>>>>> (labelValue));
>>>>> Floatwriter->Update();
>>>>> }
>>>>> }
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> return EXIT_SUCCESS;
>>>>> }
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> On 4/5/15 12:10 PM, "Bill Lorensen" <bill.lorensen at gmail.com> wrote:
>>>>>
>>>>>> Do you have a small, compilable example that illustrates the problem?
>>>>>>
>>>>>> On Sun, Apr 5, 2015 at 10:09 AM, Thomas Seidel <seidel at cvrti.utah.edu>
>>>>>> wrote:
>>>>>>> Hi all,
>>>>>>>
>>>>>>> I am using the itkLabelGeometryImageFilter to get information about
>>>>>>> the
>>>>>>> orientation of labeled objects.
>>>>>>> I provide a LabelImage and a IntensityImage.
>>>>>>> I set CalculateOrientedLabelRegionsOn() and
>>>>>>> CalculateOrientedIntensityRegionsOn().
>>>>>>>
>>>>>>> However, when I use
>>>>>>> writer->SetInput(filter->GetOrientedLabelImage());
>>>>>>> writer->Update();
>>>>>>> or
>>>>>>> writer->SetInput(filter->GetOrientedIntensityImage());
>>>>>>> writer->Update();
>>>>>>>
>>>>>>> it just generates empty images (all values 0) with the size of the
>>>>>>> oriented
>>>>>>> bounding box.
>>>>>>>
>>>>>>> Is this how the filter is supposed to work?? I was expecting the
>>>>>>> rotated
>>>>>>> labels and the rotated region of the intensity image defined by the
>>>>>>> oriented
>>>>>>> bounding box, respectively.
>>>>>>>
>>>>>>> Thanks,
>>>>>>> Thomas
>>>>>>>
>>>>>>> _____________________________________
>>>>>>> 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://public.kitware.com/mailman/listinfo/insight-users
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> Unpaid intern in BillsBasement at noware dot com
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Unpaid intern in BillsBasement at noware dot com
>>>
>>>
>>>
>>
>>
>>
>> --
>> Unpaid intern in BillsBasement at noware dot com
>
>
>
> --
> Unpaid intern in BillsBasement at noware dot com
> _____________________________________
> 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://public.kitware.com/mailman/listinfo/insight-users
More information about the Insight-users
mailing list