Hi Gaetan,<br><br>Thank you very much !<br><br>The example code you referred me to showed me how to perform the merge.<br><br>I just had to add the lines:<br><br>//added code per itkMergeLabelMapFilterTest1.cxx<br><br>  convertermerge-&gt;SetInput( labelMap );<br>
<br>  convertermerge-&gt;SetInput( 1, labelMap2 );<br><br>  //end of added code<br><br>Thanks again,<br>john<br><br><div class="gmail_quote">On Thu, Dec 17, 2009 at 1:12 PM, John Drozd <span dir="ltr">&lt;<a href="mailto:john.drozd@gmail.com">john.drozd@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi Gaetan,<br><br>My particular brain subject had the left and right brain ventricle as separate regions, so I inputed a seed for the left ventricle and a seed for the right ventricle, and created a separate label map for each ventricle.  (I could not figure out how to create a label map with two labelled segmentations, so I am trying to merge these two label maps into a combined label map.)<br>

<br>Below is my code and thank you:<br><br>/*<br>to run type:<br><br>./ConnectedThresholdImagechangedtoFuzzyConnectednessImageFilter &quot;/trumpet/downloads/ReadAtlasDicomSeriesAndReadSubjectDicomSeries_Plugin/ReadAtlasDicomSeriesAndReadSubjectDicomSeries/ReadAtlasDicomSeriesAndReadSubjectDicomSeries3DSlicerDec22009/normal002_S_0295.dcm&quot; outsubjectnormal4final.dcm outfuzzymapnormal.mhd 100 151 95 86 152 76 2.5 10<br>

<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><br>#include &quot;itkConnectedThresholdImageFilter.h&quot;<br>
<br>
#include &quot;itkImage.h&quot;<br>#include &quot;itkCastImageFilter.h&quot;<br><br>#include &quot;itkCurvatureFlowImageFilter.h&quot;<br><br>#include &quot;itkImageFileReader.h&quot;<br>#include &quot;itkImageFileWriter.h&quot;<br>

<br>#include &quot;itkGDCMImageIO.h&quot;<br><br>#include &quot;itkVersion.h&quot;<br><br>#include &quot;itkOrientedImage.h&quot;<br>#include &quot;itkMinimumMaximumImageFilter.h&quot;<br><br>#include &quot;itkGDCMImageIO.h&quot;<br>

#include &quot;itkGDCMSeriesFileNames.h&quot;<br>#include &quot;itkNumericSeriesFileNames.h&quot;<br><br>#include &quot;itkImageSeriesReader.h&quot;<br>#include &quot;itkImageSeriesWriter.h&quot;<br><br>#include &quot;itkResampleImageFilter.h&quot;<br>

#include &quot;itkShiftScaleImageFilter.h&quot;<br><br>#include &quot;itkIdentityTransform.h&quot;<br>#include &quot;itkLinearInterpolateImageFunction.h&quot;<br><br>#include &lt;itksys/SystemTools.hxx&gt;<br><br>#include &quot;gdcm/src/gdcmFile.h&quot;<br>

#include &quot;gdcm/src/gdcmUtil.h&quot;<br><br>#include &lt;string&gt;<br><br>//added per attribute_values.cxx<br>#include &quot;itkImageFileReader.h&quot;<br><br>#include &quot;itkShapeLabelObject.h&quot;<br><br>#include &quot;itkLabelMap.h&quot;<br>

<br>#include &quot;itkBinaryImageToShapeLabelMapFilter.h&quot;<br>//end of added code<br><br>//added per label.cxx<br>#include &quot;itkLabelObject.h&quot;<br>#include &quot;itkLabelMap.h&quot;<br>#include &quot;itkBinaryImageToLabelMapFilter.h&quot;<br>

#include &quot;itkLabelMapToLabelImageFilter.h&quot;<br>//end of added code<br><br>#include &quot;itkSimpleFilterWatcher.h&quot;<br><br>//added per FuzzyConnectednessImageFilter.cxx<br>#include &quot;itkSimpleFuzzyConnectednessScalarImageFilter.h&quot;<br>

#include &quot;itkConfidenceConnectedImageFilter.h&quot;<br>//end of added code<br><br>#include &quot;itkMergeLabelMapFilter.h&quot;<br><br>int main( int argc, char *argv[])<br>{<br>  if( argc &lt; 7 )<br>    {<br>    std::cerr &lt;&lt; &quot;Missing Parameters &quot; &lt;&lt; std::endl;<br>

    std::cerr &lt;&lt; &quot;Usage: &quot; &lt;&lt; argv[0];<br>  <br>    std::cerr &lt;&lt; &quot; inputImage  outputImage outputAffinityMap seedX seedY seedZ seedX seedY seedZ multiplier tolerancedivisor&quot; &lt;&lt; std::endl;<br>

<br><br>    return 1;<br>    }<br><br>  typedef   unsigned char          BinaryPixelType;<br><br>  const     unsigned int    Dimension = 3;<br><br>  typedef itk::Image&lt; BinaryPixelType, Dimension &gt;  BinaryImageType;<br>

  <br><br>  typedef signed short InputPixelType;<br><br>  typedef itk::Image&lt; InputPixelType, Dimension &gt; InputImageType;<br>  typedef unsigned char LabelType;<br>  const unsigned int dim = 3;<br>  typedef itk::ShapeLabelObject&lt; LabelType, dim &gt; LabelObjectType;<br>

  typedef itk::LabelMap&lt; LabelObjectType &gt; LabelMapType;<br><br>  typedef itk::LabelMap&lt; LabelObjectType &gt; LabelMapType2;<br><br>  typedef itk::BinaryImageToShapeLabelMapFilter&lt; BinaryImageType, LabelMapType&gt; ConverterType;<br>

<br>  ConverterType::Pointer converter = ConverterType::New();<br><br>   typedef itk::BinaryImageToShapeLabelMapFilter&lt; BinaryImageType, LabelMapType&gt; ConverterType2;<br>  ConverterType2::Pointer converter2 = ConverterType2::New();<br>

<br>  typedef  itk::ImageFileReader&lt; InputImageType &gt; ReaderType;<br>  typedef  itk::ImageFileWriter&lt;  BinaryImageType  &gt; WriterType;<br>  <br>  ReaderType::Pointer reader = ReaderType::New();<br>  WriterType::Pointer writer = WriterType::New();<br>

 <br>  typedef itk::GDCMImageIO           ImageIOTypefixed;<br>  ImageIOTypefixed::Pointer gdcmImageIOfixed = ImageIOTypefixed::New();<br>  reader-&gt;SetImageIO( gdcmImageIOfixed );<br><br>  typedef itk::GDCMImageIO           ImageIOTypefixed2;<br>

  ImageIOTypefixed2::Pointer gdcmImageIOfixed2 = ImageIOTypefixed2::New();<br><br>  reader-&gt;SetFileName( argv[1] );<br>  <br>  reader-&gt;Update();<br>  <br>  typedef itk::ConfidenceConnectedImageFilter&lt; <br>                                                  InputImageType, <br>

                                                  BinaryImageType <br>                                                    &gt;  ConfidenceConnectedFilterType;<br><br>  ConfidenceConnectedFilterType::Pointer confidenceConnectedFilter = <br>

                                                 ConfidenceConnectedFilterType::New();<br><br>  typedef itk::SimpleFuzzyConnectednessScalarImageFilter&lt; <br>                                                  InputImageType, <br>

                                                  BinaryImageType <br>                                                    &gt;  FuzzySegmentationFilterType;<br><br>   FuzzySegmentationFilterType::Pointer fuzzysegmenter = <br>

                                         FuzzySegmentationFilterType::New();<br><br>   typedef FuzzySegmentationFilterType::FuzzySceneType  FuzzySceneType; <br><br>   typedef  itk::ImageFileWriter&lt; FuzzySceneType  &gt;    FuzzyWriterType;<br>

<br>   FuzzyWriterType::Pointer fwriter = FuzzyWriterType::New();<br>   <br>   fwriter-&gt;SetFileName( argv[3] );<br><br>   BinaryImageType::IndexType  index;<br> <br>  index[0] = atoi( argv[4] );<br>  index[1] = atoi( argv[5] );<br>

  index[2] = atoi( argv[6] );<br><br>  const double varianceMultiplier = atof( argv[10] );<br><br>  confidenceConnectedFilter-&gt;SetInput( reader-&gt;GetOutput()  );<br>  confidenceConnectedFilter-&gt;SetMultiplier( varianceMultiplier );<br>

  confidenceConnectedFilter-&gt;SetNumberOfIterations( 12 );<br>  <br>  fuzzysegmenter-&gt;SetInput( reader-&gt;GetOutput() );<br><br>  double varianceEstimation = 0;<br><br>  double  meanEstimation = 0;<br><br>  confidenceConnectedFilter-&gt;SetSeed( index );<br>

  confidenceConnectedFilter-&gt;Update();<br><br>  meanEstimation      = confidenceConnectedFilter-&gt;GetMean();<br>  varianceEstimation  = confidenceConnectedFilter-&gt;GetVariance();<br><br>  std::cout &lt;&lt; &quot;Mean     estimation = &quot; &lt;&lt; meanEstimation     &lt;&lt; std::endl;<br>

  std::cout &lt;&lt; &quot;Variance estimation = &quot; &lt;&lt; varianceEstimation &lt;&lt; std::endl;<br><br>  if( varianceEstimation &gt; meanEstimation/atoi( argv[11] ) )<br>    {<br>      <br>      index[0] = index[0]-10;<br>

      index[1] = index[1]-10;<br>      index[2] = index[2]-10;<br><br>      confidenceConnectedFilter-&gt;SetSeed( index );<br>      confidenceConnectedFilter-&gt;Update();<br><br>      meanEstimation      = confidenceConnectedFilter-&gt;GetMean();<br>

      varianceEstimation  = confidenceConnectedFilter-&gt;GetVariance();<br><br>    }<br><br>  while( varianceEstimation &gt; meanEstimation/atoi( argv[11] )  )<br>    {<br><br>      index[0] = index[0] + 1;<br><br>      confidenceConnectedFilter-&gt;SetSeed( index );<br>

      confidenceConnectedFilter-&gt;Update();<br><br>      meanEstimation      = confidenceConnectedFilter-&gt;GetMean();<br>      varianceEstimation  = confidenceConnectedFilter-&gt;GetVariance();<br>  <br>      std::cout &lt;&lt; &quot;Mean     estimation = &quot; &lt;&lt; meanEstimation     &lt;&lt; std::endl;<br>

      std::cout &lt;&lt; &quot;Variance estimation = &quot; &lt;&lt; varianceEstimation &lt;&lt; std::endl;<br><br>      if ( varianceEstimation &gt; meanEstimation/atoi( argv[11] ))<br>    {<br>      index[1] = index[1] + 1;<br>

<br>      confidenceConnectedFilter-&gt;SetSeed( index );<br>      confidenceConnectedFilter-&gt;Update();<br><br>      meanEstimation      = confidenceConnectedFilter-&gt;GetMean();<br>      varianceEstimation  = confidenceConnectedFilter-&gt;GetVariance();<br>

  <br>      std::cout &lt;&lt; &quot;Mean     estimation = &quot; &lt;&lt; meanEstimation     &lt;&lt; std::endl;<br>      std::cout &lt;&lt; &quot;Variance estimation = &quot; &lt;&lt; varianceEstimation &lt;&lt; std::endl;<br>

    }<br><br>      if ( varianceEstimation &gt;  meanEstimation/atoi( argv[11] ))<br>    {<br>      index[2] = index[2] + 1;<br><br>      confidenceConnectedFilter-&gt;SetSeed( index );<br>      confidenceConnectedFilter-&gt;Update();<br>

<br>      meanEstimation      = confidenceConnectedFilter-&gt;GetMean();<br>      varianceEstimation  = confidenceConnectedFilter-&gt;GetVariance();<br>  <br>      std::cout &lt;&lt; &quot;Mean     estimation = &quot; &lt;&lt; meanEstimation     &lt;&lt; std::endl;<br>

      std::cout &lt;&lt; &quot;Variance estimation = &quot; &lt;&lt; varianceEstimation &lt;&lt; std::endl;<br>    }<br><br>    }<br><br>  std::cout &lt;&lt; index &lt;&lt; std::endl;<br><br>  std::cout &lt;&lt; &quot;Mean     estimation = &quot; &lt;&lt; meanEstimation     &lt;&lt; std::endl;<br>

  std::cout &lt;&lt; &quot;Variance estimation = &quot; &lt;&lt; varianceEstimation &lt;&lt; std::endl;<br><br>  fuzzysegmenter-&gt;SetObjectSeed( index );<br> <br>  fuzzysegmenter-&gt;SetMean( meanEstimation );<br>  fuzzysegmenter-&gt;SetVariance( varianceEstimation );<br>

  fuzzysegmenter-&gt;SetThreshold( 0.5 );<br><br>  fuzzysegmenter-&gt;Update();<br><br>  //begin second label<br> <br>  FuzzySegmentationFilterType::Pointer fuzzysegmenter2 = <br>                                         FuzzySegmentationFilterType::New();<br>

  index[0] = atoi( argv[7] );<br>  index[1] = atoi( argv[8] );<br>  index[2] = atoi( argv[9] );<br><br>  confidenceConnectedFilter-&gt;SetInput( reader-&gt;GetOutput()  );<br>  confidenceConnectedFilter-&gt;SetMultiplier( varianceMultiplier );<br>

  confidenceConnectedFilter-&gt;SetNumberOfIterations( 12 );<br>  <br>  fuzzysegmenter2-&gt;SetInput( reader-&gt;GetOutput() );<br><br>  varianceEstimation = 0;<br><br>  meanEstimation = 0;<br><br>  confidenceConnectedFilter-&gt;SetSeed( index );<br>

  confidenceConnectedFilter-&gt;Update();<br><br>  meanEstimation      = confidenceConnectedFilter-&gt;GetMean();<br>  varianceEstimation  = confidenceConnectedFilter-&gt;GetVariance();<br><br>  std::cout &lt;&lt; &quot;Mean     estimation = &quot; &lt;&lt; meanEstimation     &lt;&lt; std::endl;<br>

  std::cout &lt;&lt; &quot;Variance estimation = &quot; &lt;&lt; varianceEstimation &lt;&lt; std::endl;<br><br>  if( varianceEstimation &gt; meanEstimation/atoi( argv[11] ) )<br>    {<br>      <br>      index[0] = index[0]-10;<br>

      index[1] = index[1]-10;<br>      index[2] = index[2]-10;<br><br>      confidenceConnectedFilter-&gt;SetSeed( index );<br>      confidenceConnectedFilter-&gt;Update();<br><br>      meanEstimation      = confidenceConnectedFilter-&gt;GetMean();<br>

      varianceEstimation  = confidenceConnectedFilter-&gt;GetVariance();<br><br>    }<br><br>  while( varianceEstimation &gt; meanEstimation/atoi( argv[11] )  )<br>    {<br><br>      index[0] = index[0] + 1;<br><br>      confidenceConnectedFilter-&gt;SetSeed( index );<br>

      confidenceConnectedFilter-&gt;Update();<br><br>      meanEstimation      = confidenceConnectedFilter-&gt;GetMean();<br>      varianceEstimation  = confidenceConnectedFilter-&gt;GetVariance();<br>  <br>      std::cout &lt;&lt; &quot;Mean     estimation = &quot; &lt;&lt; meanEstimation     &lt;&lt; std::endl;<br>

      std::cout &lt;&lt; &quot;Variance estimation = &quot; &lt;&lt; varianceEstimation &lt;&lt; std::endl;<br><br>      if ( varianceEstimation &gt; meanEstimation/atoi( argv[11] ))<br>    {<br>      index[1] = index[1] + 1;<br>

<br>      confidenceConnectedFilter-&gt;SetSeed( index );<br>      confidenceConnectedFilter-&gt;Update();<br><br>      meanEstimation      = confidenceConnectedFilter-&gt;GetMean();<br>      varianceEstimation  = confidenceConnectedFilter-&gt;GetVariance();<br>

  <br>      std::cout &lt;&lt; &quot;Mean     estimation = &quot; &lt;&lt; meanEstimation     &lt;&lt; std::endl;<br>      std::cout &lt;&lt; &quot;Variance estimation = &quot; &lt;&lt; varianceEstimation &lt;&lt; std::endl;<br>

    }<br><br>      if ( varianceEstimation &gt;  meanEstimation/atoi( argv[11] ))<br>    {<br>      index[2] = index[2] + 1;<br><br>      confidenceConnectedFilter-&gt;SetSeed( index );<br>      confidenceConnectedFilter-&gt;Update();<br>

<br>      meanEstimation      = confidenceConnectedFilter-&gt;GetMean();<br>      varianceEstimation  = confidenceConnectedFilter-&gt;GetVariance();<br>  <br>      std::cout &lt;&lt; &quot;Mean     estimation = &quot; &lt;&lt; meanEstimation     &lt;&lt; std::endl;<br>

      std::cout &lt;&lt; &quot;Variance estimation = &quot; &lt;&lt; varianceEstimation &lt;&lt; std::endl;<br>    }<br><br>    }<br><br>  std::cout &lt;&lt; index &lt;&lt; std::endl;<br><br>  std::cout &lt;&lt; &quot;Mean     estimation = &quot; &lt;&lt; meanEstimation     &lt;&lt; std::endl;<br>

  std::cout &lt;&lt; &quot;Variance estimation = &quot; &lt;&lt; varianceEstimation &lt;&lt; std::endl;<br><br>  fuzzysegmenter2-&gt;SetObjectSeed( index );<br> <br>  fuzzysegmenter2-&gt;SetMean( meanEstimation );<br>  fuzzysegmenter2-&gt;SetVariance( varianceEstimation );<br>

  fuzzysegmenter2-&gt;SetThreshold( 0.5 );<br><br>  fuzzysegmenter2-&gt;Update();<br><br>  //end second label<br><br>  typedef itk::MetaDataDictionary DictionaryType;<br> <br>  DictionaryType inputdict = reader-&gt;GetMetaDataDictionary();<br>

<br>  writer-&gt;SetMetaDataDictionary( inputdict );<br>   <br>  writer-&gt;SetFileName( argv[2] );<br><br>  converter-&gt;SetInput( fuzzysegmenter-&gt;GetOutput() );<br><br>  converter-&gt;SetFullyConnected( true );<br>
  <br>
  converter-&gt;SetInputForegroundValue( 255 );<br><br>  converter-&gt;SetOutputBackgroundValue( 0 );<br><br>  converter-&gt;Update();<br>  <br>  converter2-&gt;SetInput( fuzzysegmenter2-&gt;GetOutput() );<br><br>  converter2-&gt;SetFullyConnected( true );<br>

  <br>  converter2-&gt;SetInputForegroundValue( 255 );<br><br>  converter2-&gt;SetOutputBackgroundValue( 0 );<br><br>  converter2-&gt;Update();<br>  <br>  LabelMapType::Pointer labelMap = converter-&gt;GetOutput();<br><br>

  LabelMapType2::Pointer labelMap2 = converter2-&gt;GetOutput();<br><br>  std::cout.precision(20);<br><br>  std::cout &lt;&lt; &quot;labelMap-&gt;GetNumberOfLabelObjects() = &quot; &lt;&lt; labelMap-&gt;GetNumberOfLabelObjects() &lt;&lt; std::endl;<br>

<br>  std::cout &lt;&lt; &quot;labelMap2-&gt;GetNumberOfLabelObjects() = &quot; &lt;&lt; labelMap2-&gt;GetNumberOfLabelObjects() &lt;&lt; std::endl;<br><br>  for( unsigned int label=1; label&lt;=labelMap-&gt;GetNumberOfLabelObjects(); label++ )<br>

    {<br>    // we don&#39;t need a SmartPointer of the label object here, because the reference is kept in<br>    // in the label map.<br>    const LabelObjectType * labelObject = labelMap-&gt;GetLabelObject( label );<br>

    std::cout &lt;&lt; label &lt;&lt; &quot;\t&quot; &lt;&lt; labelObject-&gt;GetSize() &lt;&lt; &quot;\t&quot; &lt;&lt; labelObject-&gt;GetPhysicalSize() &lt;&lt; &quot;\t&quot; &lt;&lt; labelObject-&gt;GetCentroid() &lt;&lt; std::endl;<br>

    }<br>  <br>  for( unsigned int label=1; label&lt;=labelMap2-&gt;GetNumberOfLabelObjects(); label++ )<br>    {<br>    // we don&#39;t need a SmartPointer of the label object here, because the reference is kept in<br>    // in the label map.<br>

    const LabelObjectType * labelObject2 = labelMap2-&gt;GetLabelObject( label );<br>    std::cout &lt;&lt; label &lt;&lt; &quot;\t&quot; &lt;&lt; labelObject2-&gt;GetSize() &lt;&lt; &quot;\t&quot; &lt;&lt; labelObject2-&gt;GetPhysicalSize() &lt;&lt; &quot;\t&quot; &lt;&lt; labelObject2-&gt;GetCentroid() &lt;&lt; std::endl;<br>

    }<br><br>  //added to merge the two label maps<br>  <br>  typedef itk::MergeLabelMapFilter&lt; LabelMapType &gt; ConverterMergeType;<br><br>  ConverterMergeType::Pointer convertermerge = ConverterMergeType::New();<br>

<br>  /*******************************<br><br>  how do I merge labelMap and LabelMap2 ?<br><br>  ********************************/<br><br>   //end<br><br>  typedef itk::LabelMapToLabelImageFilter&lt; LabelMapType, BinaryImageType &gt; L2IType;<br>

<br>  L2IType::Pointer l2i = L2IType::New();<br>  <br>  l2i-&gt;SetInput( converter-&gt;GetOutput() );<br><br>  writer-&gt;SetInput( l2i-&gt;GetOutput() );<br><br>  try<br>    {<br>    writer-&gt;Update();<br>    }<br>  catch( itk::ExceptionObject &amp; excep )<br>

    {<br>    std::cerr &lt;&lt; &quot;Exception caught !&quot; &lt;&lt; std::endl;<br>    std::cerr &lt;&lt; excep &lt;&lt; std::endl;<br>    }<br>  <br>  fwriter-&gt;SetInput( fuzzysegmenter-&gt;GetFuzzyScene() );<br>  fwriter-&gt;Update();<br>

<br>  return 0;<br>}<br><br><br><div class="gmail_quote">2009/12/17 Gaëtan Lehmann <span dir="ltr">&lt;<a href="mailto:gaetan.lehmann@jouy.inra.fr" target="_blank">gaetan.lehmann@jouy.inra.fr</a>&gt;</span><div><div></div>
<div class="h5"><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
Le 17 déc. 09 ŕ 18:22, John Drozd a écrit :<div><br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi,<br>
<br>
Can anyone show me how to use the MergeLabelMapFilter to merge two label maps?<br>
</blockquote>
<br>
<br></div>
Hi John,<br>
<br>
You can look at Testing/Code/Review/itkMergeLabelMapFilterTest1.cxx, as an example.<br>
<br>
Can you be more specific on what you want to do?<br>
<br>
Regards,<br>
<br>
Gaëtan<br><font color="#888888">
<br>
<br>
-- <br>
Gaëtan Lehmann<br>
Biologie du Développement et de la Reproduction<br>
INRA de Jouy-en-Josas (France)<br>
tel: +33 1 34 65 29 66    fax: 01 34 65 29 09<br>
<a href="http://voxel.jouy.inra.fr" target="_blank">http://voxel.jouy.inra.fr</a>  <a href="http://www.itk.org" target="_blank">http://www.itk.org</a><br>
<a href="http://www.mandriva.org" target="_blank">http://www.mandriva.org</a>  <a href="http://www.bepo.fr" target="_blank">http://www.bepo.fr</a><br>
<br>
</font></blockquote></div></div></div><br>
</blockquote></div><br>