[Insight-users] watershed with MRI

lydia coin lydia_coin3d@yahoo.fr
Wed, 8 Jan 2003 19:47:56 +0100 (CET)


--0-1693339096-1042051676=:55056
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit


thank you for your hints.

That what I did,  I used an MRI image, with the GradientMagnitudeImageFilter and pass it to the watershed filter. the result is an image with the same intensity value.

In addition to using MRI image, I took the image of the testing example as follows (source code below). The result is an image with the same intensity value everywhere in the image ( like for the MRI). In this case the pixel type is float but still doesn't work. I'll cast the MR image to float but in the meanwhile, could you have a look to my code, maybe something is wrong.  

 

typedef itk::Image<float, 2> ImageType2D;
  itk::ImageRegion<2> Region2D;
  itk::Size<2>  size2D;
   size2D[0] = 256;
   size2D[1] = 256;
  itk::Index<2> orig2D;
   orig2D[0] = 0;
   orig2D[1] = 0;

  Region2D.SetSize(size2D);
  Region2D.SetIndex(orig2D);

  ImageType2D::Pointer image2D = ImageType2D::New();
   image2D->SetLargestPossibleRegion(Region2D);
   image2D->SetBufferedRegion(Region2D);
   image2D->SetRequestedRegion(Region2D);
   image2D->Allocate();


itk::ImageRegionIterator<ImageType2D>
     it2D(image2D, image2D->GetRequestedRegion());  
  
  float q = 0.00f;
  for (; !it2D.IsAtEnd(); ++it2D)
    {
      it2D.Value() = ::sin(q);
      q = q + 0.10f;
    }

  float lower_threshold=.05f;
itk::WatershedImageFilter<ImageType2D>::Pointer watershed
    = itk::WatershedImageFilter<ImageType2D>::New();
  watershed->SetThreshold(lower_threshold);
  watershed->SetLevel(1.0f);
  watershed->SetInput(image2D);
typedef unsigned long PixelType1;
 PixelType1  *data = new PixelType1[size[0]*size[1]];
  typedef itk::ImageRegionIterator<TestInputImage>ImageIterator1;
    ImageIterator1  it1(watershed->GetOutput(),watershed->GetOutput()->GetBufferedRegion());
 it1.GoToBegin();
   int i=0;
  while( !it1.IsAtEnd() )
  {
    data[i]=it1.Get( );
    ++it1;
 i++;
  }



---------------------------------
Do You Yahoo!? -- Une adresse @yahoo.fr gratuite et en français !
Testez le nouveau Yahoo! Mail
--0-1693339096-1042051676=:55056
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: 8bit

<P>thank you for your hints.</P>
<P>That what I did,&nbsp; I used an MRI image, with the GradientMagnitudeImageFilter and pass it to the watershed filter. the result is an image with the same intensity value.</P>
<P>In addition&nbsp;to using MRI image, I took the image of the testing example as follows (source code below). The result is&nbsp;an image with the same intensity value everywhere in the image ( like for the MRI). In this case the pixel type is float&nbsp;but still doesn't work. I'll cast the MR image to float but in the meanwhile, could you have&nbsp;a look to my code, maybe something is wrong.&nbsp;&nbsp;</P>
<P>&nbsp;</P>
<P>typedef itk::Image&lt;float, 2&gt; ImageType2D;<BR>&nbsp; itk::ImageRegion&lt;2&gt; Region2D;<BR>&nbsp; itk::Size&lt;2&gt;&nbsp; size2D;<BR>&nbsp;&nbsp; size2D[0] = 256;<BR>&nbsp;&nbsp; size2D[1] = 256;<BR>&nbsp; itk::Index&lt;2&gt; orig2D;<BR>&nbsp;&nbsp; orig2D[0] = 0;<BR>&nbsp;&nbsp; orig2D[1] = 0;<BR><BR>&nbsp; Region2D.SetSize(size2D);<BR>&nbsp; Region2D.SetIndex(orig2D);</P>
<P>&nbsp; ImageType2D::Pointer image2D = ImageType2D::New();<BR>&nbsp;&nbsp; image2D-&gt;SetLargestPossibleRegion(Region2D);<BR>&nbsp;&nbsp; image2D-&gt;SetBufferedRegion(Region2D);<BR>&nbsp;&nbsp; image2D-&gt;SetRequestedRegion(Region2D);<BR>&nbsp;&nbsp; image2D-&gt;Allocate();</P>
<P><BR>itk::ImageRegionIterator&lt;ImageType2D&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp; it2D(image2D, image2D-&gt;GetRequestedRegion());&nbsp; <BR>&nbsp; <BR>&nbsp; float q = 0.00f;<BR>&nbsp; for (; !it2D.IsAtEnd(); ++it2D)<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; it2D.Value() = ::sin(q);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; q = q + 0.10f;<BR>&nbsp;&nbsp;&nbsp; }</P>
<P>&nbsp; float lower_threshold=.05f;<BR>itk::WatershedImageFilter&lt;ImageType2D&gt;::Pointer watershed<BR>&nbsp;&nbsp;&nbsp; = itk::WatershedImageFilter&lt;ImageType2D&gt;::New();<BR>&nbsp; watershed-&gt;SetThreshold(lower_threshold);<BR>&nbsp; watershed-&gt;SetLevel(1.0f);<BR>&nbsp; watershed-&gt;SetInput(image2D);<BR>typedef unsigned long PixelType1;<BR>&nbsp;PixelType1&nbsp; *data = new PixelType1[size[0]*size[1]];<BR>&nbsp; typedef itk::ImageRegionIterator&lt;TestInputImage&gt;ImageIterator1;<BR>&nbsp;&nbsp;&nbsp;&nbsp;ImageIterator1&nbsp; it1(watershed-&gt;GetOutput(),watershed-&gt;GetOutput()-&gt;GetBufferedRegion());<BR>&nbsp;it1.GoToBegin();<BR>&nbsp;&nbsp; int i=0;<BR>&nbsp; while( !it1.IsAtEnd() )<BR>&nbsp; {<BR>&nbsp;&nbsp;&nbsp; data[i]=it1.Get( );<BR>&nbsp;&nbsp;&nbsp; ++it1;<BR>&nbsp;i++;<BR>&nbsp; }</P><p><br><hr size=1>Do You Yahoo!? -- Une adresse @yahoo.fr gratuite et en français !<br>
<a href=http://fr.mail.yahoo.com>Testez le nouveau Yahoo! Mail</a>
--0-1693339096-1042051676=:55056--