[Insight-users] Image filtering and feature detection-

Ryan Smith ryanleesmith at gmail.com
Tue Sep 14 14:06:17 EDT 2010


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;
}






<http://i.imgur.com/wd3Yt.jpg>

On Tue, Sep 14, 2010 at 1:15 AM, Dan Mueller <dan.muel at gmail.com> wrote:

> Hi Ryan,
>
> Indeed, I computed the regional maxima of the distance map.
>
> Perhaps you could post your code (or a minimal example) and input data?
>
> Dan
>
> On 13 September 2010 22:50, Ryan Smith <ryanleesmith at gmail.com> wrote:
> > Hi Dan-
> > My itkSignedMaurerDistanceMapImageFilter now matches your output (I
> invoked
> > the SetInsideIsPositive(true); method as my initial result was the
> inverse
> > of yours).  With that said, my RegionalMaxima filter is not producing
> > quality results.  You are sending the distance map output to the to the
> > RegionalMaxima filter, not any of the other results in the chain, right?
> >  Upon saving the output of my RegionalMaximaImageFilter to disk I cannot
> > open the mha file with any of the readers I use.  I get an error. Any
> idea
> > on where I am going wrong?  I think I am close, however this one has me
> > stumped.  Thanks again for your continued support-
> > -Ryan
> >
> > On Fri, Aug 20, 2010 at 11:05 PM, Dan Mueller <dan.muel at gmail.com>
> wrote:
> >>
> >> Hi Ryan,
> >>
> >> It looks like you have a problem with pixel type. Consider using a
> >> real pixel type (eg. float or double).
> >>
> >> HTH
> >>
> >> Cheers, Dan
> >>
> >> On 20 August 2010 22:06, Ryan Smith <ryanleesmith at gmail.com> wrote:
> >> > Thanks again for all the help Dan.  I tried your suggestion for using
> >> > the itkSignedMaurerDistanceMapImageFilter and got different results.
>  I
> >> > sent
> >> > in my BinaryThresholdImageFilter output and got the following from
> >> > my itkSignedMaurerDistanceMapImageFilter
> >> > http://i.imgur.com/jZ1AN.png
> >> >
> >> > Are there any other inputs I need to set for my Mauerer Distance Map?
> >> >  This
> >> > one is new to me and I didn't find much in the documentation.  Thanks-
> >> > -Ryan
> >> > p.s. You were right about my previous lossy compression woes
> >> > On Thu, Aug 19, 2010 at 2:51 PM, Dan Mueller <dan.muel at gmail.com>
> wrote:
> >> >>
> >> >> Hi Ryan,
> >> >>
> >> >> 1. The output of the connected component filter you provided does not
> >> >> seem right. Are you doubly sure you are passing the binary image to
> >> >> the connected component filter? I have attached the output you should
> >> >> get.
> >> >>
> >> >> 2. That said, if you just need to extract seeds for further
> >> >> processing, I don't think you need to use the connected component
> >> >> filter. This filter simply assigns a unique identifier (Eg. 1, 2, 3,
> >> >> 4, etc) to each component or "blob" in the image. One way of
> obtaining
> >> >> seeds is to take the binary image, compute the distance transform
> (try
> >> >> Code/BasicFilters/itkSignedMaurerDistanceMapImageFilter.h), and the
> >> >> apply the regional maxima filter
> >> >> (Code/Review/itkRegionalMaximaImageFilter.h). I have attached the
> >> >> output from this chain.
> >> >>
> >> >> HTH
> >> >>
> >> >> Cheers, Dan
> >> >>
> >> >> On 19 August 2010 21:20, Ryan Smith <ryanleesmith at gmail.com> wrote:
> >> >> > Hi Dan-
> >> >> > The white top hat worked great at removing my extra features, and
> the
> >> >> > binary
> >> >> > thresholding cleaned everything else up, however I am still having
> >> >> > some
> >> >> > trouble using the ConnectedComponentFilter.  I found this article
> >> >> > which
> >> >> > is
> >> >> > trying to do exactly what I am attempting:
> >> >> >
> http://www.itk.org/pipermail/insight-users/2007-January/020532.html
> >> >> > I want the position and full width half max (FWHM) of each
> intensity
> >> >> > maxima
> >> >> > in the image.  I tried using the connected component filter and got
> >> >> > the
> >> >> > output found at the following URL: http://i.imgur.com/TCqL8.png
> >> >> > It appears each feature is being tagged as several different
> >> >> > features.
> >> >> >  Just
> >> >> > to confirm I am sending the binary thresholded image, not the
> >> >> > original Gaussian spot image into the ConnectedComponentFilter.
> >> >> > I feel like I am going down the wrong path here.  I don't
> necessarily
> >> >> > need
> >> >> > to segment my points, I just need to clean up the image (done) and
> >> >> > potentially use techniques such as those in other ITK problems I
> have
> >> >> > read
> >> >> > to find 'seed points' for some region growing algorithms based on
> the
> >> >> > intensity maxima of my image.  Any thoughts? Thanks in advance-
> >> >> > -Ryan
> >> >> >
> >> >> >
> >> >> > On Sun, Aug 15, 2010 at 11:22 PM, Dan Mueller <dan.muel at gmail.com>
> >> >> > wrote:
> >> >> >>
> >> >> >> Hi Ryan,
> >> >> >>
> >> >> >> You might consider using the "white top hat" operation to remove
> the
> >> >> >> background:
> >> >> >>    WhiteTopHat = I - Dilate( Erode(I) )
> >> >> >> where I is the image, Erode is morphological erosion, and Dilate
> is
> >> >> >> morphological dilation.
> >> >> >>
> >> >> >> You can find an implementation of this operation in:
> >> >> >>    Code/BasicFilters/itkWhiteTopHatImageFilter.h
> >> >> >>
> >> >> >> Once the background is removed, a simple global intensity
> threshold
> >> >> >> should suffice to segment the spots. The following filters may be
> >> >> >> helpful for that task:
> >> >> >>    Code/BasicFilters/itkBinaryThresholdImageFilter.h
> >> >> >>    Code/Algorithms/itkOtsuThresholdImageFilter.h
> >> >> >>    Code/Review/itkKappaSigmaThresholdImageFilter.h
> >> >> >>
> >> >> >> HTH
> >> >> >>
> >> >> >> Cheers, Dan
> >> >> >>
> >> >> >> On 15 August 2010 23:04, Ryan Smith <ryanleesmith at gmail.com>
> wrote:
> >> >> >> > Hi-
> >> >> >> > I am attempting to remove the background and detect features in
> >> >> >> > the
> >> >> >> > following image:
> >> >> >> > http://i.imgur.com/wd3Yt.jpg
> >> >> >> >
> >> >> >> > I have a series of images in which the white circular spots
> travel
> >> >> >> > and
> >> >> >> > the
> >> >> >> > white vertical stripes remain stationary.  I would like to apply
> >> >> >> > some
> >> >> >> > simple
> >> >> >> > background subtraction to remove the white stripes then
> autodetect
> >> >> >> > the
> >> >> >> > intensity maxima associated with the circular features.
> >> >> >> >
> >> >> >> > A brief search provided the following results which address
> >> >> >> > similar
> >> >> >> > problems
> >> >> >> > using itkConnectedComponentFilter.  Is this what I want after my
> >> >> >> > background
> >> >> >> > is subtracted?  Any example code on how to get the location and
> >> >> >> > sizes
> >> >> >> > of
> >> >> >> > the
> >> >> >> > components? Thanks in advance-
> >> >> >> >
> >> >> >> > -Ryan
> >> >> >> >
> >> >> >> >
> >> >> >> > _____________________________________
> >> >> >> > 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.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
> >> >> >> >
> >> >> >> >
> >> >> >
> >> >> >
> >> >
> >> >
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100914/c5e1e670/attachment.htm>


More information about the Insight-users mailing list