[Insight-users] VectorConfidenceConnectedImageFilter Bug/Fix?
Bradley Lowekamp
blowekamp at mail.nih.gov
Mon May 16 16:30:32 EDT 2005
Thank you.
Any reason the algorithm was not changed to remove the needless
dependency on NumericTraits as I suggested?
Also, These new headers you have added are not "installed" when make
install is performed. So my code did not find these needed headers
until I copies them to the /usr/local/include/Insight/Common directory.
========================================================
Bradley Lowekamp
Management Systems Designers Contractor for
Office of High Performance Computing and Communications
National Library of Medicine
'blowekamp at mail.nih.gov
On May 14, 2005, at 2:15 PM, Karthik Krishnan wrote:
> Thanks for pointing this out
>
> You should be able to use it on vector images now. Please cvs update
> Code/Common. Pixel traits for vector pixels (for a few dimensions and
> data types) have been added. There is also a test
> Testing/Code/IO/itkVectorImageReadWriteTest.cxx
>
> The attached file tests confidence connected on vector pixels.
>
> thanks
> regards
> karthik
>
>
>
> Bradley Lowekamp wrote:The VectorConfidenceConnectedImageFilter does
> not work with Vectors, only RGBPixel types.
>>
>> Can anyone confirm or deny that this is a correct way to fix this?
>> And if so should it be placed in the CVS? I am willing to up date the
>> necessary test. I do not fully understand how filters are suppose to
>> work with the different types, and how they indicate what types they
>> work with so there may be something I am missing.
>>
>> Thanks.
>>
>> On May 6, 2005, at 11:18 AM, Lowekamp, Bradley (NIH/NLM/LHC) wrote:
>>
>>> Hello all.
>>>
>>>
>>> I can only get VectorConfidenceConnectedImageFilter to work with
>>> RGB typed images, the following caused me problems:
>>>
>>>
>>>
>>> typedef itk::Image < itk::FixedArray<double, 4>, 2> MyImageType;
>>>
>>> typedef itk::VectorConfidenceConnectedImageFilter<MyImageType,
>>> MaskImageType> ConnectedFilterType;
>>>
>>> ConnectedFilterType::Pointer cc = ConnectedFilterType::New();
>>>
>>>
>>> The compiler would complain about these lines in
>>> itkVectorCondidenceConnectedImageFilter.txx:
>>>
>>>
>>>
>>> typedef typename NumericTraints<InputPixelType>::RealType
>>> InputRealType;
>>>
>>> ...
>>>
>>> const unsigned int dimension = InputRealType::Dimension;
>>>
>>>
>>>
>>> After check around I discovered the "RealType" is not defined for
>>> these Fixed array templates, and the it seems like it's not really
>>> even needed by the VectorConnectedConfidence class, so deleted the
>>> definition of InputRealType, and change the second line:
>>>
>>>
>>>
>>> const unsigned int dimension = InputPixelType::Dimension;
>>>
>>>
>>> These seemed to fix the problem I was running into, I have not
>>> tested this much yet. I could be wrong about this, I was just
>>> hacking around to get the fix, I don't know what all this class does
>>> internally.
>>>
>>>
>>> The reason that I was trying this was because I am thinking that
>>> Hue, might be a better classifier for my data, so I wrote a adaptor
>>> to add it, which caused things to break.
>>>
>>>
>>> Thanks,
>>>
>>> Brad
>>>
>>>
>>> ========================================================
>>>
>>> Bradley Lowekamp
>>>
>>> Management Systems Designers Contractor for
>>>
>>> Office of High Performance Computing and Communications
>>>
>>> National Library of Medicine
>>>
>>> 'blowekamp at mail.nih.gov
>>> <ATT1074990.txt>
>> _______________________________________________
>> Insight-users mailing list
>> Insight-users at itk.org
>> http://www.itk.org/mailman/listinfo/insight-users
>>
>
> #include <iostream>
> #include "itkVector.h"
> #include "itkImage.h"
> #include "itkImageFileReader.h"
> #include "itkImageFileWriter.h"
> #include "itkImageLinearConstIteratorWithIndex.h"
> #include "itkImageLinearIteratorWithIndex.h"
> #include "itkVectorConfidenceConnectedImageFilter.h"
>
> int main(int argc, char * argv [])
> {
>
> if ( argc < 4 )
> {
> itkGenericOutputMacro(<<"VectorConfConnected DummyMetaImageFile
> seedX seedY");
> std::cout << "For example: VectorConfConnected dummy.mhd 5 5" <<
> std::endl;
> return EXIT_FAILURE;
> }
>
> // Test for vector pixel type.
>
> const unsigned int Dimension = 2;
>
> // Create image of vector pixels
> typedef itk::Vector< double, 4 > PixelType;
> typedef itk::Image < PixelType, Dimension> ImageType;
> typedef itk::ImageFileReader< ImageType > ReaderType;
> typedef itk::ImageFileWriter< ImageType > WriterType;
>
> ImageType::Pointer inputImage = ImageType::New();
> ReaderType::Pointer reader = ReaderType::New();
> WriterType::Pointer writer = WriterType::New();
>
> const double tolerance = 0.001;
>
> //Create 3 different vectors
> PixelType vector0(0.0);
> PixelType vector1;
> vector1[0] = 1.0;
> vector1[1] = 2.0;
> vector1[2] = 3.0;
> vector1[3] = 4.0;
> PixelType vector2;
> vector2[0] = 1.0;
> vector2[1] = 2.0;
> vector2[2] = 3.0;
> vector2[3] = 12.0;
>
> typedef itk::ImageLinearIteratorWithIndex< ImageType >
> IteratorType;
> typedef itk::ImageLinearConstIteratorWithIndex< ImageType >
> ConstIteratorType;
>
> //Create a 20 x 20 image of vector pixels of length 4, with 3 kinds
> of regions as
> //defined by vector0, vector1 and vector2. Then see if
> VectorConfidenceConnectedImageFilter
> //works on it. If yes smile, if not frown.
> //
> ImageType::SizeType size;
> size.Fill( 20 );
> ImageType::IndexType index;
> index.Fill( 0 );
> ImageType::RegionType region;
> region.SetSize( size );
> region.SetIndex( index );
> inputImage->SetLargestPossibleRegion( region );
> inputImage->SetBufferedRegion( region );
> inputImage->SetRequestedRegion( region );
> inputImage->Allocate();
>
> // Create region1.
> inputImage->FillBuffer( vector0);
>
> std::cout << "Create image of x9 image of vector pixels. IO Read and
> write it. " << std::endl;
>
> // Create Region2
> for (int i=2; i<=17; i++)
> {
> for (int j=2; j<=17; j++)
> {
> index[0] = i;
> index[1] = j;
> inputImage->SetPixel( index, vector1);
> }
> }
>
> // Create Region3
> for (int i=8; i<=12; i++)
> {
> for (int j=8; j<=12; j++)
> {
> index[0] = i;
> index[1] = j;
> inputImage->SetPixel( index, vector2);
> }
> }
>
>
> // Write to a file and read to see if IO works
> //
> writer->SetInput(inputImage);
> writer->SetFileName(argv[1]);
> writer->Update();
>
> reader->SetFileName(argv[1]);
> reader->Update();
> ImageType::Pointer outputImage = reader->GetOutput();
>
> ConstIteratorType cit( outputImage,
> outputImage->GetLargestPossibleRegion() );
> index[0] = 4;
> index[1] = 4;
> cit.SetIndex(index);
> if( cit.Get() != vector1 )
> {
> std::cout << "Vector Image Write-Read failed. Tried to write " <<
> vector1 <<
> " But read " << cit.Get() << std::endl;
> return EXIT_FAILURE;
> }
> index[0] = 0;
> index[1] = 0;
> cit.SetIndex(index);
> if( cit.Get() != vector0 )
> {
> std::cout << "Vector Image Write-Read failed. Tried to write " <<
> vector0 <<
> " But read " << cit.Get() << std::endl;
> return EXIT_FAILURE;
> }
>
> std::cout << "Image of vector pixels write-read [PASSED]" <<
> std::endl;
>
> std::cout << "Test << operator:: Vector1 = " << vector2 <<
> "[PASSED]" << std::endl;
>
> // See if Pixeltraits are fine
> //
> std::cout << "Test NumericTraits<Vector<double,4>>::Zero " <<
> itk::NumericTraits< PixelType >::Zero <<
> std::endl;
> std::cout << "Test NumericTraits <Vector <double,4 > >::One " <<
> itk::NumericTraits< PixelType >::One <<
> std::endl;
>
>
> // Test VectorConfidenceConnectedImageFilter
> //
> typedef itk::Image< unsigned char, 2 > MaskImageType;
>
> typedef itk::Image < itk::Vector< double, 4>, 2> MyImageType;
> typedef itk::VectorConfidenceConnectedImageFilter<MyImageType,
> MaskImageType> ConnectedFilterType;
> ConnectedFilterType::Pointer cc = ConnectedFilterType::New();
> cc->SetInput(outputImage);
> index[0] = atoi( argv[2] );
> index[1] = atoi( argv[3] );
> cc->SetSeed( index );
> cc->SetInitialNeighborhoodRadius( 1 );
> cc->Update();
> MaskImageType::Pointer ccoutImage = cc->GetOutput();
>
> typedef itk::ImageLinearConstIteratorWithIndex< MaskImageType >
> ConstIteratorType2;
>
> // Spit out the segmented regions on screen
> //
> ConstIteratorType2 cit2( ccoutImage,
> ccoutImage->GetLargestPossibleRegion() );
> for (int i=0; i<20; i++)
> {
> for (int j=0; j<20; j++)
> {
> index[0] = i;
> index[1] = j;
> cit2.SetIndex(index);
> std::cout << cit2.Get() << "\t";
> }
> std::cout << std::endl;
> }
>
> return EXIT_SUCCESS;
> }
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/enriched
Size: 8911 bytes
Desc: not available
Url : http://public.kitware.com/pipermail/insight-users/attachments/20050516/2cf3e672/attachment.bin
More information about the Insight-users
mailing list