It is on the Wiki. It is on the itk software guide (manual).I am using visual studio 2010 and cmake.The code is the following:<br><br>/////////// code ///////////<br>/*=========================================================================<br>
<br> Program: Insight Segmentation & Registration Toolkit<br> Module: $RCSfile: NeighborhoodConnectedImageFilter.cxx,v $<br> Language: C++<br> Date: $Date: 2009-03-17 21:44:42 $<br> Version: $Revision: 1.29 $<br>
<br> Copyright (c) Insight Software Consortium. All rights reserved.<br> See ITKCopyright.txt or <a href="http://www.itk.org/HTML/Copyright.htm">http://www.itk.org/HTML/Copyright.htm</a> for details.<br><br> This software is distributed WITHOUT ANY WARRANTY; without even <br>
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR <br> PURPOSE. See the above copyright notices for more information.<br><br>=========================================================================*/<br>
#if defined(_MSC_VER)<br>#pragma warning ( disable : 4786 )<br>#endif<br><br>#ifdef __BORLANDC__<br>#define ITK_LEAN_AND_MEAN<br>#endif<br><br>// Software Guide : BeginLatex<br>//<br>// The following example illustrates the use of the<br>
// \doxygen{NeighborhoodConnectedImageFilter}. This filter is a close variant<br>// of the \doxygen{ConnectedThresholdImageFilter}. On one hand, the<br>// ConnectedThresholdImageFilter accepts a pixel in the region if its intensity<br>
// is in the interval defined by two user-provided threshold values. The<br>// NeighborhoodConnectedImageFilter, on the other hand, will only accept a<br>// pixel if \textbf{all} its neighbors have intensities that fit in the<br>
// interval. The size of the neighborhood to be considered around each pixel is<br>// defined by a user-provided integer radius. <br>//<br>// The reason for considering the neighborhood intensities instead of only the<br>
// current pixel intensity is that small structures are less likely to be<br>// accepted in the region. The operation of this filter is equivalent to<br>// applying the ConnectedThresholdImageFilter followed by mathematical<br>
// morphology erosion using a structuring element of the same shape as<br>// the neighborhood provided to the NeighborhoodConnectedImageFilter.<br>//<br>// Software Guide : EndLatex <br><br><br>// Software Guide : BeginCodeSnippet<br>
#include "itkNeighborhoodConnectedImageFilter.h"<br>// Software Guide : EndCodeSnippet<br><br><br>#include "itkImage.h"<br>#include "itkCastImageFilter.h"<br><br><br>// Software Guide : BeginLatex<br>
//<br>// The \doxygen{CurvatureFlowImageFilter} is used here to smooth the image<br>// while preserving edges.<br>//<br>// Software Guide : EndLatex <br><br>// Software Guide : BeginCodeSnippet<br>#include "itkCurvatureFlowImageFilter.h"<br>
// Software Guide : EndCodeSnippet<br><br><br>#include "itkImageFileReader.h"<br>#include "itkImageFileWriter.h"<br><br><br>int main( int argc, char *argv[] )<br>{<br> if( argc < 8 )<br> {<br> std::cerr << "Missing Parameters " << std::endl;<br>
std::cerr << "Usage: " << argv[0];<br> std::cerr << " inputImage outputImage seedX seedY seedZ lowerThreshold upperThreshold" << std::endl;<br> return 1;<br> }<br>
<br><br> // Software Guide : BeginLatex<br> // <br> // We now define the image type using a particular pixel type and image<br> // dimension. In this case the \code{float} type is used for the pixels due<br> // to the requirements of the smoothing filter. <br>
//<br> // Software Guide : EndLatex <br><br> // Software Guide : BeginCodeSnippet<br> typedef float InternalPixelType;<br> const unsigned int Dimension = 3;<br> typedef itk::Image< InternalPixelType, Dimension > InternalImageType;<br>
// Software Guide : EndCodeSnippet<br><br><br> typedef unsigned char OutputPixelType;<br> typedef itk::Image< OutputPixelType, Dimension > OutputImageType;<br><br> typedef itk::CastImageFilter< InternalImageType, OutputImageType ><br>
CastingFilterType;<br> CastingFilterType::Pointer caster = CastingFilterType::New();<br> <br><br> // We instantiate reader and writer types<br> //<br> typedef itk::ImageFileReader< InternalImageType > ReaderType;<br>
typedef itk::ImageFileWriter< OutputImageType > WriterType;<br><br> ReaderType::Pointer reader = ReaderType::New();<br> WriterType::Pointer writer = WriterType::New();<br><br> reader->SetFileName( argv[1] );<br>
writer->SetFileName( argv[2] );<br><br><br> // Software Guide : BeginLatex<br> // <br> // The smoothing filter type is instantiated using the image type as<br> // a template parameter.<br> //<br> // Software Guide : EndLatex <br>
<br> // Software Guide : BeginCodeSnippet<br> typedef itk::CurvatureFlowImageFilter<InternalImageType, InternalImageType><br> CurvatureFlowImageFilterType;<br> // Software Guide : EndCodeSnippet<br><br><br> // Software Guide : BeginLatex<br>
// <br> // Then, the filter is created by invoking the \code{New()} method and<br> // assigning the result to a \doxygen{SmartPointer}.<br> //<br> // Software Guide : EndLatex <br><br> // Software Guide : BeginCodeSnippet<br>
CurvatureFlowImageFilterType::Pointer smoothing = <br> CurvatureFlowImageFilterType::New();<br> // Software Guide : EndCodeSnippet<br><br><br> // Software Guide : BeginLatex<br> // <br> // We now declare the type of the region growing filter. In this case it is<br>
// the NeighborhoodConnectedImageFilter. <br> //<br> // Software Guide : EndLatex <br><br> // Software Guide : BeginCodeSnippet<br> typedef itk::NeighborhoodConnectedImageFilter<InternalImageType,<br> InternalImageType > ConnectedFilterType;<br>
// Software Guide : EndCodeSnippet<br><br> // Software Guide : BeginLatex<br> // <br> // One filter of this class is constructed using the \code{New()} method. <br> //<br> // Software Guide : EndLatex <br><br> // Software Guide : BeginCodeSnippet<br>
ConnectedFilterType::Pointer neighborhoodConnected = ConnectedFilterType::New();<br> // Software Guide : EndCodeSnippet<br><br><br> // Software Guide : BeginLatex<br> // <br> // Now it is time to create a simple, linear data processing pipeline. A<br>
// file reader is added at the beginning of the pipeline and a cast<br> // filter and writer are added at the end. The cast filter is required<br> // to convert \code{float} pixel types to integer types since only a<br>
// few image file formats support \code{float} types.<br> //<br> // Software Guide : EndLatex <br><br> // Software Guide : BeginCodeSnippet<br> smoothing->SetInput( reader->GetOutput() );<br> neighborhoodConnected->SetInput( smoothing->GetOutput() );<br>
caster->SetInput( neighborhoodConnected->GetOutput() );<br> writer->SetInput( caster->GetOutput() );<br> // Software Guide : EndCodeSnippet<br><br><br> // Software Guide : BeginLatex<br> //<br> // The CurvatureFlowImageFilter requires a couple of parameters to<br>
// be defined. The following are typical values for $2D$ images. However<br> // they may have to be adjusted depending on the amount of noise present in<br> // the input image.<br> //<br> // Software Guide : EndLatex <br>
<br> // Software Guide : BeginCodeSnippet<br> smoothing->SetNumberOfIterations( 5 );<br> smoothing->SetTimeStep( 0.125 );<br> // Software Guide : EndCodeSnippet<br><br><br> // Software Guide : BeginLatex<br> //<br>
// The NeighborhoodConnectedImageFilter requires that two main parameters<br> // are specified. They are the lower and upper thresholds of the interval<br> // in which intensity values must fall to be included in the<br>
// region. Setting these two values too close will not allow enough<br> // flexibility for the region to grow. Setting them too far apart will<br> // result in a region that engulfs the image.<br> //<br> // \index{itk::NeighborhoodConnectedImageFilter!SetLower()}<br>
// \index{itk::NeighborhoodConnectedImageFilter!SetUppder()}<br> //<br> // Software Guide : EndLatex <br><br> const InternalPixelType lowerThreshold = atof( argv[6] );<br> const InternalPixelType upperThreshold = atof( argv[7] );<br>
<br> // Software Guide : BeginCodeSnippet<br> neighborhoodConnected->SetLower( lowerThreshold );<br> neighborhoodConnected->SetUpper( upperThreshold );<br> // Software Guide : EndCodeSnippet<br><br> // Software Guide : BeginLatex<br>
// <br> // Here, we add the crucial parameter that defines the neighborhood size<br> // used to determine whether a pixel lies in the region. The larger the<br> // neighborhood, the more stable this filter will be against noise in the<br>
// input image, but also the longer the computing time will be. Here we<br> // select a filter of radius $2$ along each dimension. This results in a<br> // neighborhood of $5 \times 5$ pixels.<br> //<br> // Software Guide : EndLatex <br>
<br> // Software Guide : BeginCodeSnippet<br> InternalImageType::SizeType radius;<br><br> radius[0] = 2; // two pixels along X <br> radius[1] = 2; // two pixels along Y <br><br> neighborhoodConnected->SetRadius( radius );<br>
// Software Guide : EndCodeSnippet<br><br><br> // Software Guide : BeginLatex<br> //<br> // As in the ConnectedThresholdImageFilter we must now provide the<br> // intensity value to be used for the output pixels accepted in the region<br>
// and at least one seed point to define the initial region.<br> //<br> // \index{itk::NeighborhoodConnectedImageFilter!SetSeed()}<br> // \index{itk::NeighborhoodConnectedImageFilter!SetReplaceValue()}<br> //<br>
// Software Guide : EndLatex <br><br> InternalImageType::IndexType index;<br> <br> index[0] = atoi( argv[3] );<br> index[1] = atoi( argv[4] );<br> index[2] = atoi( argv[5] );<br><br><br> // Software Guide : BeginCodeSnippet<br>
neighborhoodConnected->SetSeed( index );<br> neighborhoodConnected->SetReplaceValue( 255 );<br> // Software Guide : EndCodeSnippet<br><br> <br> // Software Guide : BeginLatex<br> // <br> // The invocation of the \code{Update()} method on the writer triggers the<br>
// execution of the pipeline. It is usually wise to put update calls in a<br> // \code{try/catch} block in case errors occur and exceptions are thrown.<br> //<br> // Software Guide : EndLatex <br><br> // Software Guide : BeginCodeSnippet<br>
try<br> {<br> writer->Update();<br> }<br> catch( itk::ExceptionObject & excep )<br> {<br> std::cerr << "Exception caught !" << std::endl;<br> std::cerr << excep << std::endl;<br>
}<br> // Software Guide : EndCodeSnippet<br><br><br> // Software Guide : BeginLatex<br> //<br> // Now we'll run this example using the image<br> // \code{BrainProtonDensitySlice.png} as input available from the<br>
// directory \code{Examples/Data}. We can easily segment the major<br> // anatomical structures by providing seeds in the appropriate locations<br> // and defining values for the lower and upper thresholds. For example<br>
//<br> // \begin{center}<br> // \begin{tabular}{|l|c|c|c|c|}<br> // \hline<br> // Structure & Seed Index & Lower & Upper & Output Image \\ \hline<br> // White matter & $(60,116)$ & 150 & 180 & Second from left in Figure \ref{fig:NeighborhoodConnectedImageFilterOutput} \\ \hline<br>
// Ventricle & $(81,112)$ & 210 & 250 & Third from left in Figure \ref{fig:NeighborhoodConnectedImageFilterOutput} \\ \hline<br> // Gray matter & $(107,69)$ & 180 & 210 & Fourth from left in Figure \ref{fig:NeighborhoodConnectedImageFilterOutput} \\ \hline<br>
// \end{tabular}<br> // \end{center}<br> //<br> // \begin{figure} \center<br> // \includegraphics[width=0.24\textwidth]{BrainProtonDensitySlice.eps}<br> // \includegraphics[width=0.24\textwidth]{NeighborhoodConnectedImageFilterOutput1.eps}<br>
// \includegraphics[width=0.24\textwidth]{NeighborhoodConnectedImageFilterOutput2.eps}<br> // \includegraphics[width=0.24\textwidth]{NeighborhoodConnectedImageFilterOutput3.eps}<br> // \itkcaption[NeighborhoodConnected segmentation results ]{Segmentation results<br>
// of the NeighborhoodConnectedImageFilter for various seed points.}<br> // \label{fig:NeighborhoodConnectedImageFilterOutput}<br> // \end{figure}<br> //<br> // As with the ConnectedThresholdImageFilter, several seeds could<br>
// be provided to the filter by using the \code{AddSeed()} method.<br> // Compare the output of Figure<br> // \ref{fig:NeighborhoodConnectedImageFilterOutput} with those of Figure<br> // \ref{fig:ConnectedThresholdOutput} produced by the<br>
// ConnectedThresholdImageFilter. You may want to play with the<br> // value of the neighborhood radius and see how it affect the smoothness of<br> // the segmented object borders, the size of the segmented region and how<br>
// much that costs in computing time. <br> //<br> // Software Guide : EndLatex <br><br> return 0;<br>}<br><br><br><br><div class="gmail_quote">2011/4/9 David Doria <span dir="ltr"><<a href="mailto:daviddoria@gmail.com">daviddoria@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div><div></div><div class="h5">On Sat, Apr 9, 2011 at 10:10 AM, john smith <<a href="mailto:mkitkinsightuser@gmail.com">mkitkinsightuser@gmail.com</a>> wrote:<br>
> Hi to everyone,<br>
><br>
> I am trying to run the "NeighborhoodConnectedImageFilter" from the itk<br>
> software guide, but for a 3-D image and not for a 2-D image as in the<br>
> example. But when I run it, I take the following message:Inavlid Allocation<br>
> size 4294967295. Do you know what is wrong?<br>
><br>
> Thanks in advance<br>
<br>
</div></div>It looks like there is no example at all of<br>
NeighborhoodConnectedImageFilter on the wiki. If you would post what<br>
you have on the wiki under WishList/NeighborhoodConnectedImageFilter3D<br>
or something like that, along with a note about where it crashes, we<br>
can try to look into it.<br>
<font color="#888888"><br>
David<br>
</font></blockquote></div><br><div style="visibility: hidden; left: -5000px; position: absolute; z-index: 9999; padding: 0px; margin-left: 0px; margin-top: 0px; overflow: hidden; word-wrap: break-word; color: black; font-size: 10px; text-align: left; line-height: 130%;" id="avg_ls_inline_popup">
</div>