[Insight-users] watershed with MRI

Joshua Cates cates@sci.utah.edu
Mon, 13 Jan 2003 18:43:43 -0700 (MST)


Hi Lydia,

I was able to successfully run the watersheds on the file you sent me.  
I'll send you some images in a separate mail.  

Here is what I did:  

1) Converted the raw file to a format readable by the
Applications/WatershedSegmentation example program (.pgm, in practice you
will not want to do this step obviously because of loss of information,
just write your code to read 2d unsigned short instead.).

2) Ran itkWatershedSegmentationExample MRRAW.14.pgm MRRAW 1.0 20 0.000
Where 1.0 is conductance term for the diffusion, 20 is number of 
iterations for smoothing, and 0.00 was the lower thresholding for the 
watershed filter.

This example program produces a set of output images which is the 
segmentation at several scales (flood levels).

3) Converted the outputs to color .png using 
Applications/WatershedSegmentation itkWSRawToPNG program.  This just 
randomly colorizes the labeled image so you can view it with a standard 
image viewer.

If you follow these steps, you should be hopefully be able to reproduce my
results.  Let me know if you have any more questions.  THe trickiest part 
is probably converting raw to .pgm.  This can be done by writing a simple 
text header and literally cat'ing your data on the end of it.

See http://netpbm.sourceforge.net/doc/pgm.html for info on pgm format.

Josh.

______________________________
 Josh Cates			
 School of Computer Science	
 University of Utah
 Email: cates@sci.utah.edu
 Phone: (801) 587-7697
 URL:   http://www.sci.utah.edu/~cates


On Thu, 9 Jan 2003, lydia coin wrote:

> 
> Hi Josh
> Did the watershed work on the MRI, could you read the image?
> Sorry for being impatient :)
>  Joshua Cates <cates@sci.utah.edu> wrote:Sure. I'll see what I can do.
> 
> Josh.
> 
> ______________________________
> Josh Cates 
> School of Computer Science 
> University of Utah
> Email: cates@sci.utah.edu
> Phone: (801) 587-7697
> URL: http://www.sci.utah.edu/~cates
> 
> 
> On Wed, 8 Jan 2003, lydia coin wrote:
> 
> > would you mind if I send you one raw MRI image with all the information of dimensions to perform the filter on it? this will be very helpful as I'm stuck with this problem.
> > 
> > Joshua Cates wrote:Hi,
> > 
> > Yes, the test is perhaps misleading as it doesn't really produce any
> > meaningful output, just excercises the code. The filters are fine, the
> > data is just not interesting and only segments to one region at most level
> > values. At some point I will replace the test with one using actual image
> > data that will produce more meaningful results for true regression
> > testing.
> > 
> > I suggest looking at the example in the Applications directory instead
> > (Applications/WatershedSegmentation). This example is more instructive as
> > it shows how to preprocess the data and produce output at different
> > levels. It will read images in ASCII pgm format.
> > 
> > Also, the extremely high value you are seeing looks like the result 
> > of the wrong endianness.
> > 
> > Josh.
> > 
> > ______________________________
> > Josh Cates 
> > School of Computer Science 
> > University of Utah
> > Email: cates@sci.utah.edu
> > Phone: (801) 587-7697
> > URL: http://www.sci.utah.edu/~cates
> > 
> > 
> > On Wed, 8 Jan 2003, lydia coin wrote:
> > 
> > > 
> > > Hi Josh,
> > > I changed the value of the level paramter from 1 to 0.1 and to 0.01, but still the same intensity value of 3452816845 for the whole image. it's really strange, I wonder if this example in the testing folder gives the same result for you
> > > Joshua Cates wrote:Hi Lydia,
> > > 
> > > For your MRI image, make sure that you cast to float (or double) before 
> > > passing to the GradientMagnitudeImageFilter. You might also want to do 
> > > some smoothing on the image first (i.e. 
> > > Gradient/CurvatureAnisotropicDiffusionImageFilter or 
> > > BilateralImageFilter). 
> > > 
> > > In your example code below, you set the Level parameter to 1.0. This 
> > > should result in an output of exactly one region because it is telling the 
> > > filter to merge all of the potential watershed basins up to 100% of the 
> > > possible image height. Try a Level parameter much lower than this, say 
> > > 0.10 (i.e. 10% of the height).
> > > 
> > > Josh.
> > > 
> > > ______________________________
> > > Josh Cates 
> > > School of Computer Science 
> > > University of Utah
> > > Email: cates@sci.utah.edu
> > > Phone: (801) 587-7697
> > > URL: http://www.sci.utah.edu/~cates
> > > 
> > > 
> > > On Wed, 8 Jan 2003, lydia coin wrote:
> > > 
> > > > 
> > > > 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 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
> > > > 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::Pointer watershed
> > > > = itk::WatershedImageFilter::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::ImageRegionIteratorImageIterator1;
> > > > 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
> > > 
> > > 
> > > 
> > > ---------------------------------
> > > Do You Yahoo!? -- Une adresse @yahoo.fr gratuite et en français !
> > > Testez le nouveau Yahoo! Mail
> > 
> > 
> > 
> > 
> > ---------------------------------
> > Do You Yahoo!? -- Une adresse @yahoo.fr gratuite et en français !
> > Testez le nouveau Yahoo! Mail
> 
> 
> 
> ---------------------------------
> Do You Yahoo!? -- Une adresse @yahoo.fr gratuite et en français !
> Testez le nouveau Yahoo! Mail