[Insight-users] Problem with CannyEdgeDetectionImageFilter and ExtractImageFilter

Bill Lorensen bill.lorensen at gmail.com
Tue Mar 10 20:54:01 EDT 2009


Please place a try/catch block around each writer Update.

Something like:

  try
    {
...
    }
 catch( itk::ExceptionObject & excp )
    {
    std::cerr << "Error while writing" << std::endl;
    std::cerr << excp << std::endl;
    return EXIT_FAILURE;
    }

On Tue, Mar 10, 2009 at 11:16 AM, cyrille Valladeau
<cyrille.valladeau at c-s.fr> wrote:
> Hi all,
>
> I'm making a class that uses a itkCannyEdgeDetectionImageFilter.
> Unfortunatly my class generates a segmentation fault!!!
> I've tried to fix the problem but it seems to be hard to find. First I've
> thought it was a streming/threading problem in my own source code but not.
> I managed to identify the problem using basic itk classes. Applying a canny
> edge detection over a full image works without any problem, applying the
> same filter over an extract of an image which start index is the same as the
> origin index of the full image works fine too, but if you try to apply the
> filter ovec an extract of the image which start index is not the image
> origin it give you the segfault.
>
> Well in attachment, you'll find an example that shows it. It applies a canny
> over an image and then over an extract of the image (which start index of
> the extract is given as argument).
> The argument list is : input image, output full image, output extracted
> image, extraction index.
>
> Is that a bug? Or am I doing something wrong?
> If anybody has an idea it will be helpfull...
> Thanks,
> Cyrille
>
>
> /*=========================================================================
>
>  Program:   ORFEO Toolbox
>  Language:  C++
>  Date:      $Date$
>  Version:   $Revision$
>
>
>  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
>  See OTBCopyright.txt 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 "itkImage.h"
> #include "itkImageFileReader.h"
> #include "itkImageFileWriter.h"
> #include "itkExtractImageFilter.h"
> #include "itkCannyEdgeDetectionImageFilter.h"
> #include "itkRescaleIntensityImageFilter.h"
>
> int main(int argc, char* argv[])
> {
>  if(argc != 5)
>    {
>      std::cout<<"Invalid input args (input, outputFullImage,
> outputExtractImage, indexExtraction)"<<std::endl;
>      return 0;
>    }
>
>  const char * inputName         = argv[1];
>  const char * outputName        = argv[2];
>  const char * outputExtractName = argv[3];
>
>  typedef double PixelType;
>  typedef unsigned short OutPixelType;
>  typedef itk::Image<PixelType, 2>
> InputImageType;
>  typedef itk::Image<OutPixelType, 2>
>  OutputImageType;
>  typedef itk::ImageFileReader<InputImageType>
> ReaderType;
>  typedef itk::ImageFileWriter<OutputImageType>
>  WriterType;
>  typedef itk::ExtractImageFilter<InputImageType, InputImageType>
>  ExtractType;
>  typedef itk::CannyEdgeDetectionImageFilter<InputImageType, InputImageType>
> CannyType;
>  typedef itk::RescaleIntensityImageFilter<InputImageType, OutputImageType>
>  RescalerType;
>
>
>  /****************
>   * PROCESSING OVER FULL IMAGE
>   ****************/
>  ReaderType::Pointer   reader   = ReaderType::New();
>  WriterType::Pointer   writer   = WriterType::New();
>  CannyType::Pointer    canny    = CannyType::New();
>  RescalerType::Pointer rescaler = RescalerType::New();
>
>  InputImageType::SizeType size;
>  size.Fill(50);
>  InputImageType::IndexType index;
>  index.Fill(10);
>  InputImageType::RegionType region;
>  region.SetSize(size);
>  region.SetIndex(index);
>
>  reader->SetFileName(inputName);
>
>  canny->SetInput( reader->GetOutput() );
>
>  rescaler->SetInput(canny->GetOutput());
>  rescaler->SetOutputMinimum(0);
>  rescaler->SetOutputMaximum(255);
>
>  writer->SetInput(rescaler->GetOutput() );
>  writer->SetFileName(outputName);
>  writer->Update();
>
>  /****************
>   * PROCESSING OVER AN EXTRACT
>   ****************/
>  ReaderType::Pointer   reader2   = ReaderType::New();
>  WriterType::Pointer   writer2   = WriterType::New();
>  CannyType::Pointer    canny2    = CannyType::New();
>  RescalerType::Pointer rescaler2 = RescalerType::New();
>  ExtractType::Pointer  extract   = ExtractType::New();
>
>  InputImageType::SizeType size2;
>  size2.Fill(50);
>  InputImageType::IndexType index2;
>  index2.Fill(atoi(argv[4]));
>  InputImageType::RegionType region2;
>  region2.SetSize(size2);
>  region2.SetIndex(index2);
>
>  reader2->SetFileName(inputName);
>
>  extract->SetExtractionRegion(region2);
>  extract->SetInput( reader2->GetOutput() );
>
>  canny2->SetInput( extract->GetOutput() );
>
>  rescaler2->SetInput(canny2->GetOutput());
>  rescaler2->SetOutputMinimum(0);
>  rescaler2->SetOutputMaximum(255);
>
>  writer2->SetInput(rescaler2->GetOutput() );
>  writer2->SetFileName(outputExtractName);
>  writer2->Update();
>
>
>  return 1;
> }
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> 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
>
>


More information about the Insight-users mailing list