[Insight-users] Image filtering and feature detection-

Dan Mueller dan.muel at gmail.com
Thu Sep 16 03:00:43 EDT 2010


Hi Ryan,

Firstly, some advice for the future: please post complete minimal
examples (with c++ file(s) and cmake list). This makes it much easier
for people to reproduce the reported issue. It also means you are more
likely to get an answer!

The pipeline described in your code below works as expected. The
output is a floating point image with the expected content. I guess
the issue is that you don't know how to read a floating-point image?
Consider using a "good" viewer such as Paraview:
http://www.paraview.org.

Alternatively, you can rescale the output to unsigned char and use a
normal file format (such as png). I have done this in the attached
code.

HTH

Cheers, Dan

On 14 September 2010 20:06, Ryan Smith <ryanleesmith at gmail.com> wrote:
> Thanks Dan.  My code is attached, and the input image is found at the
> following URL:
> http://i.imgur.com/wd3Yt.jpg
> Let me know if you want my output along the way to help troubleshoot.
>  Appreciate it-
> -Ryan
> CODE
> ===========================================================================================
>  if (argc < 4)
>   {
>     std::cout << "./<binary> <input-file> <output-file>
> <ball-kernel-radius>\n";
>     return EXIT_FAILURE;
>   }
>   typedef itk::Image<float, 2> ImageType;
>   typedef itk::ImageFileReader<ImageType> ReaderType;
>   typedef itk::ImageFileWriter<ImageType> WriterType;
>   typedef itk::BinaryBallStructuringElement<float, 2> KernelType;
>   typedef itk::WhiteTopHatImageFilter<ImageType, ImageType, KernelType>
> FilterType;
>   ReaderType::Pointer r = ReaderType::New();
>   r->SetFileName(argv[1]);
>   try
>   {
>     r->Update();
>   }
>   catch (itk::ExceptionObject &e)
>   {
>     std::cerr << e << std::endl;
>     return EXIT_FAILURE;
>   }
>   ImageType::Pointer image = r->GetOutput();
>   KernelType kernel;
>   kernel.SetRadius(atoi(argv[3]));
>   kernel.CreateStructuringElement();
>   FilterType::Pointer filter = FilterType::New();
>   filter->SetKernel(kernel);
>   filter->SetInput(image);
>   try
>   {
>     filter->Update();
>   }
>   catch (itk::ExceptionObject &e)
>   {
>     std::cerr << e << std::endl;
>     return EXIT_FAILURE;
>   }
>   WriterType::Pointer w = WriterType::New();
>   w->SetFileName(argv[2]);
>   w->SetInput(filter->GetOutput());
>   try
>   {
>     w->Update();
>   }
>   catch (itk::ExceptionObject &e)
>   {
>     std::cerr << e << std::endl;
>     return EXIT_FAILURE;
>   }
>  // ITK Binary Threshold
>  typedef itk::BinaryThresholdImageFilter < ImageType, ImageType >
> ThreshFilterType;
>  ThreshFilterType::Pointer thresh_filter = ThreshFilterType::New();
>  thresh_filter->SetInsideValue( 255 );
>  thresh_filter->SetOutsideValue( 0 );
>  thresh_filter->SetLowerThreshold( 35 );
>  thresh_filter->SetUpperThreshold( 255 );
>  thresh_filter->SetInput( filter->GetOutput() );
>   WriterType::Pointer w2 = WriterType::New();
>   w2->SetFileName(argv[4]);
>   w2->SetInput(thresh_filter->GetOutput());
>   try
>   {
>     w2->Update();
>   }
>   catch (itk::ExceptionObject &e)
>   {
>     std::cerr << e << std::endl;
>     return EXIT_FAILURE;
>   }
>   typedef itk::SignedMaurerDistanceMapImageFilter <
> ImageType, ImageType >
> itkSignedMaurerDistanceMapImageFilterType;
> itkSignedMaurerDistanceMapImageFilterType::Pointer distFilter
> = itkSignedMaurerDistanceMapImageFilterType::New ();
>
> distFilter->SetInput(thresh_filter->GetOutput());
> distFilter->SetInsideIsPositive(true);
>    distFilter->Update();
>   w2->SetFileName(argv[5]);
>   w2->SetInput(distFilter->GetOutput());
>   try
>   {
>     w2->Update();
>   }
>   catch (itk::ExceptionObject &e)
>   {
>     std::cerr << e << std::endl;
>     return EXIT_FAILURE;
>   }
>   typedef itk::RegionalMaximaImageFilter <
> ImageType, ImageType >
> itkRegionalMaximaImageFilterFilterType;
> itkRegionalMaximaImageFilterFilterType::Pointer rmFilter
> = itkRegionalMaximaImageFilterFilterType::New ();
>
> rmFilter->SetInput(distFilter->GetOutput());
>    rmFilter->Update();
>
>   w2->SetFileName(argv[6]);
>   w2->SetInput(rmFilter->GetOutput());
>   try
>   {
>     w2->Update();
>   }
>   catch (itk::ExceptionObject &e)
>   {
>     std::cerr << e << std::endl;
>     return EXIT_FAILURE;
>   }
>
>
> return EXIT_SUCCESS;
> }
-------------- next part --------------
# This project is designed to be built outside the Insight source tree.
PROJECT(ItkTest)

CMAKE_MINIMUM_REQUIRED(VERSION 2.4)

# Find ITK.
FIND_PACKAGE(ITK REQUIRED)
INCLUDE(${ITK_USE_FILE})

# The header files
SET(HEADERS
)

# The implementation files
SET(SOURCES
  main.cxx
)

# Add this as include directory
INCLUDE_DIRECTORIES(
  ${CMAKE_SOURCE_DIR}
  ${SOURCE_PATH}
)

# Main library
ADD_EXECUTABLE(ItkTest ${HEADERS} ${SOURCES})
TARGET_LINK_LIBRARIES(ItkTest ${ITK_LIBRARIES} ITKQuadEdgeMesh)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.cxx
Type: application/octet-stream
Size: 5150 bytes
Desc: not available
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100916/9d0b80fb/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: wd3Yt-out.png
Type: image/png
Size: 433 bytes
Desc: not available
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100916/9d0b80fb/attachment.png>


More information about the Insight-users mailing list