[Insight-users] Anisotropic Diffusion filtering

rashedk rashed.vtk at googlemail.com
Tue Aug 14 18:58:46 EDT 2007


Hi Luis, 

I greatly appreciate you testing the programs on my image slices. The
Gradient anisotropic diffusion now works perfectly fine, and it does smooth
the image whilst preserving the edges. As you mentioned about setting the
pixel type to float, as this is what is used by the PDE solver of the
filter. I remember using 'short' and 'int' instead, which may be why i wasnt
able to get it to work. 

However, I am still curious as to why writing to a GIPL file after filtering
is still not working. So i am using this:
GradientAnisotropicDiffusionImageFilter slice.hdr sliceGADSmoothed.gipl 10
0.05 3.0

and I am getting this exception:
Location: "Unknown"
File: \Insight Toolkit\project\Code\Io\itkGiplImageIO.cxx
Line: 688
Description: Pixel Type Unknown

However, when i use:
GradientAnisotropicDiffusionImageFilter slice.hdr sliceGADSmoothed.hdr 10
0.05 3.0

it works perfectly fine - i.e. it writes the output to ANALYZE format ok. 

Many Thanks
Rashed. 



Luis Ibanez wrote:
> 
> Hi Rashed,
> 
>       Thanks for posting your image.
> 
> We tested both of your reported problems:
> 
>   a) Problem reading / writing GIPL images
>   b) Problem running Gradient anisotropic diffusion.
> 
> However, both of these scenarios worked fine in our tests.
> 
> 
> Please find attached the source code of the tests we ran,
> 
> a) We were able to convert your slice.hdr (Analyze image)
>     to GIPL just using the ImageReadWrite.cxx program attached.
>     The image was converted without any problem.
> 
> b) We were able to extract a slice from the Analyze image and
>     save it as a GIPL image, using the attached ImageReadExtractWrite.cxx
>     program.
> 
> c) We were able to run GradientAnisotropic diffusion on your
>     input analyze image and produce a GIPL image as output
>    with  the expected result of a smoothed image, and still having
>    some degree of edge-preservation.
> 
>    The command line used was:
> 
>     GradientAnisotropicDiffusionImageFilter slice.hdr
> sliceGADSmoothed.gipl10
> 0.05 3.0
> 
>    That is, 10 iterations, a time step of 0.05 and a conductance of 3.0
> 
>    The computation took 31 seconds in a Precision WorkStation 450
>    with  Intel Xeon CPU 2.40GHz running Debian Linux, and compiled
>    for Release using Gcc 4.1.
> 
>    Note that your image is called slice.hdr but it actually contains 8
> slices,
>    of 200x208 pixels in size.
> 
>    Note also that the pixel type used for the Gradient Anisotropic
> smoothing
>    is "float", this is due to the use of the PDE solver in this filter. In
> your
>    pipeline, you could use the CastImageFilter or the RescaleImageFilter
>    for converting the pixel type your image before passing it to the
>    GradientAnistropicDiffusionImageFilter.
> 
>   Please give it a try to the attached programs and let us know if you
> still
>   find any difficulties using the GradientAnisotropicDiffusion filter or
> using
>   the GIPL file format.
> 
> 
>      Thanks
> 
> 
>         Luis
> 
> 
> 
> ----------------------------------------------------------------------------------------------
> On 8/10/07, rashedk <rashed.vtk at googlemail.com> wrote:
>>
>>
>> Hi Luis,
>>
>> Thanks for your email. I managed to extract a slice of my 3D volume using
>> some other application. Now I am back to my old problem where I am trying
>> to
>> find the right parameters for the Anisotropic filtering.
>>
>> As you had previously suggested, I have hosted them on to a public site
>> (my
>> data). You can download this at:
>> http://www.doc.ic.ac.uk/~rkarim/slice.zip
>>
>> So the data is in the Analyze format, and the data is just a single slice
>> of
>> my MRA image of the left atrium.
>>
>> Thanks for your help. I really appreciate.
>>
>> Regards,
>> Rashed karim
>>
>>
>>
>>
>>
> 
> /*=========================================================================
> 
>   Program:   Insight Segmentation & Registration Toolkit
>   Module:    $RCSfile: GradientAnisotropicDiffusionImageFilter.cxx,v $
>   Language:  C++
>   Date:      $Date: 2005/08/27 01:45:54 $
>   Version:   $Revision: 1.26 $
> 
>   Copyright (c) Insight Software Consortium. All rights reserved.
>   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for
> details.
> 
>      This software is distributed WITHOUT ANY WARRANTY; without even 
>      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
>      PURPOSE.  See the above copyright notices for more information.
> 
> =========================================================================*/
> #if defined(_MSC_VER)
> #pragma warning ( disable : 4786 )
> #endif
> 
> //  Software Guide : BeginCommandLineArgs
> //    INPUTS: {BrainProtonDensitySlice.png}
> //    OUTPUTS: {GradientAnisotropicDiffusionImageFilterOutput.png}
> //    5 0.25 3
> //  Software Guide : EndCommandLineArgs
> 
> 
> #include "itkImage.h"
> #include "itkImageFileReader.h"
> #include "itkImageFileWriter.h"
> #include "itkRescaleIntensityImageFilter.h"
> #include "itkGradientAnisotropicDiffusionImageFilter.h"
> 
> 
> int main( int argc, char * argv[] )
> {
>   if( argc < 6 ) 
>     { 
>     std::cerr << "Usage: " << std::endl;
>     std::cerr << argv[0] << "  inputImageFile  outputImageFile ";
>     std::cerr << "numberOfIterations  timeStep  conductance" << std::endl;
>     return EXIT_FAILURE;
>     }
> 
>   typedef    float    InputPixelType;
>   typedef    float    OutputPixelType;
> 
>   const unsigned int Dimension = 3;
> 
>   typedef itk::Image< InputPixelType,  Dimension >   InputImageType;
>   typedef itk::Image< OutputPixelType, Dimension >   OutputImageType;
> 
>   typedef itk::ImageFileReader< InputImageType >  ReaderType;
> 
>   typedef itk::GradientAnisotropicDiffusionImageFilter<
>                InputImageType, OutputImageType >  FilterType;
>   FilterType::Pointer filter = FilterType::New();
> 
>   ReaderType::Pointer reader = ReaderType::New();
>   reader->SetFileName( argv[1] );
> 
>   filter->SetInput( reader->GetOutput() );
> 
>   const unsigned int numberOfIterations = atoi( argv[3] );
>   const double       timeStep           = atof( argv[4] );
>   const double       conductance        = atof( argv[5] );
> 
>   filter->SetNumberOfIterations( numberOfIterations );
>   filter->SetTimeStep( timeStep );
>   filter->SetConductanceParameter( conductance );
>   
>   typedef itk::ImageFileWriter< OutputImageType >  WriterType;
> 
>   WriterType::Pointer writer = WriterType::New();
>   writer->SetFileName( argv[2] );
>   writer->SetInput( filter->GetOutput() );
> 
>   try
>     {
>     writer->Update();
>     }
>   catch( itk::ExceptionObject & excp )
>     {
>     std::cerr << excp << std::endl;
>     return EXIT_FAILURE;
>     }
> 
>   return EXIT_SUCCESS;
> }
> 
> /*=========================================================================
> 
>   Program:   Insight Segmentation & Registration Toolkit
>   Module:    $RCSfile: ImageReadExtractWrite.cxx,v $
>   Language:  C++
>   Date:      $Date: 2005/08/27 01:46:10 $
>   Version:   $Revision: 1.16 $
> 
>   Copyright (c) Insight Software Consortium. All rights reserved.
>   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for
> details.
> 
>      This software is distributed WITHOUT ANY WARRANTY; without even 
>      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
>      PURPOSE.  See the above copyright notices for more information.
> 
> =========================================================================*/
> #if defined(_MSC_VER)
> #pragma warning ( disable : 4786 )
> #endif
> 
> #include "itkImageFileReader.h"
> #include "itkImageFileWriter.h"
> #include "itkExtractImageFilter.h"
> #include "itkImage.h"
> 
> 
> int main( int argc, char ** argv )
> {
>   // Verify the number of parameters in the command line
>   if( argc < 3 )
>     {
>     std::cerr << "Usage: " << std::endl;
>     std::cerr << argv[0] << " input3DImageFile  output2DImageFile " <<
> std::endl;
>     std::cerr << " sliceNumber " << std::endl;
>     return EXIT_FAILURE;
>     }
> 
>   typedef signed short        InputPixelType;
>   typedef signed short        OutputPixelType;
> 
>   typedef itk::Image< InputPixelType,  3 >    InputImageType;
>   typedef itk::Image< OutputPixelType, 2 >    OutputImageType;
> 
>   typedef itk::ImageFileReader< InputImageType  >  ReaderType;
>   typedef itk::ImageFileWriter< OutputImageType >  WriterType;
> 
>   const char * inputFilename  = argv[1];
>   const char * outputFilename = argv[2];
> 
>   ReaderType::Pointer reader = ReaderType::New();
>   WriterType::Pointer writer = WriterType::New();
> 
>   reader->SetFileName( inputFilename  );
>   writer->SetFileName( outputFilename );
> 
>   typedef itk::ExtractImageFilter< InputImageType, OutputImageType >
> FilterType;
>   FilterType::Pointer filter = FilterType::New();
>   
>   reader->Update();
>   InputImageType::RegionType inputRegion =
>            reader->GetOutput()->GetLargestPossibleRegion();
> 
>   InputImageType::SizeType size = inputRegion.GetSize();
>   size[2] = 0;
> 
>   InputImageType::IndexType start = inputRegion.GetIndex();
>   const unsigned int sliceNumber = atoi( argv[3] );
>   start[2] = sliceNumber;
> 
>   InputImageType::RegionType desiredRegion;
>   desiredRegion.SetSize(  size  );
>   desiredRegion.SetIndex( start );
> 
>   filter->SetExtractionRegion( desiredRegion );
> 
>   filter->SetInput( reader->GetOutput() );
>   writer->SetInput( filter->GetOutput() );
> 
>   try 
>     { 
>     writer->Update(); 
>     } 
>   catch( itk::ExceptionObject & err ) 
>     { 
>     std::cerr << "ExceptionObject caught !" << std::endl; 
>     std::cerr << err << std::endl; 
>     return EXIT_FAILURE;
>     } 
> 
>   return EXIT_SUCCESS;
> }
> 
> 
> 
> 
> /*=========================================================================
> 
>   Program:   Insight Segmentation & Registration Toolkit
>   Module:    $RCSfile: ImageReadWrite.cxx,v $
>   Language:  C++
>   Date:      $Date: 2006/05/10 20:27:17 $
>   Version:   $Revision: 1.19 $
> 
>   Copyright (c) Insight Software Consortium. All rights reserved.
>   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for
> details.
> 
>      This software is distributed WITHOUT ANY WARRANTY; without even 
>      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
>      PURPOSE.  See the above copyright notices for more information.
> 
> =========================================================================*/
> #if defined(_MSC_VER)
> #pragma warning ( disable : 4786 )
> #endif
> 
> #include "itkImageFileReader.h"
> #include "itkImageFileWriter.h"
> #include "itkImage.h"
> 
> int main( int argc, char ** argv )
> {
>   // Verify the number of parameters in the command line
>   if( argc < 3 )
>     {
>     std::cerr << "Usage: " << std::endl;
>     std::cerr << argv[0] << " inputImageFile  outputImageFile " <<
> std::endl;
>     return EXIT_FAILURE;
>     }
> 
>   typedef short      PixelType;
>   const   unsigned int        Dimension = 3;
>   typedef itk::Image< PixelType, Dimension >    ImageType;
> 
>   typedef itk::ImageFileReader< ImageType >  ReaderType;
>   typedef itk::ImageFileWriter< ImageType >  WriterType;
> 
>   ReaderType::Pointer reader = ReaderType::New();
>   WriterType::Pointer writer = WriterType::New();
> 
>   const char * inputFilename  = argv[1];
>   const char * outputFilename = argv[2];
> 
>   reader->SetFileName( inputFilename  );
>   writer->SetFileName( outputFilename );
> 
>   writer->SetInput( reader->GetOutput() );
> 
>   try 
>     { 
>     writer->Update(); 
>     } 
>   catch( itk::ExceptionObject & err ) 
>     { 
>     std::cerr << "ExceptionObject caught !" << std::endl; 
>     std::cerr << err << std::endl; 
>     return EXIT_FAILURE;
>     } 
> 
>   return EXIT_SUCCESS;
> }
> 
> 
> 
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
> 
> 

-- 
View this message in context: http://www.nabble.com/Anisotropic-Diffusion-filtering-tf4199946.html#a12153749
Sent from the ITK - Users mailing list archive at Nabble.com.



More information about the Insight-users mailing list