[Insight-users] Watershed Behavior

Richard Beare richard.beare at gmail.com
Thu Feb 8 20:49:44 EST 2007


Hi,

I've built your code but get a segmentation fault under linux. I'm not
sure which version of the morphological watershed code you're using.
Gaetan mentioned that it is in the latest version of ITK - I'm using
3.0.1 and it doesn't seem to be there. So I'm using the version from
Gaetan's repository.

A couple of things stand out that you might want to check:

The images are 2D - you've defined them as 3D in the default.h

You're explicitly calling the reader and writers for specific file
types. This isn't necessary. Setting the extensions on the command
line will do the job for you. My reader and writer helper functions
look like this:

#include <itkImageFileWriter.h>
#include <itkImageFileReader.h>
template <class TImage>
void writeIm(typename TImage::Pointer Im, std::string filename)
{
  typedef typename itk::ImageFileWriter<TImage> WriterType;
  typename WriterType::Pointer writer = WriterType::New();
  writer->SetInput(Im);
  writer->SetFileName(filename.c_str());
  writer->Update();
}
template <class TImage>
typename TImage::Pointer readIm(std::string filename)
{
  typedef typename itk::ImageFileReader<TImage> ReaderType;
  typename ReaderType::Pointer reader = ReaderType::New();
  reader->SetFileName(filename.c_str());
  typename TImage::Pointer result = reader->GetOutput();
  try
    {
    result->Update();
    }
  catch(itk::ExceptionObject &ex)
    {
    std::cout << ex << std::endl;
    std::cout << filename << std::endl;
    return 0;
    }
    result->DisconnectPipeline();
    return(result);
}


I've packaged them in functions, which you may not want to do, but the
critical thing to note is that pretty much everything can be done by
calling the ImageFileReader and ImageFileWriter directly.

On 2/9/07, Albert Huang <alberth+itk at ece.ubc.ca> wrote:
> Hi Richard
>
> You can find my input file and code setup here here:
>     http://www.ece.ubc.ca/~alberth/checker_debug.zip
> It outputs both the gradient magnitude and the watershed labels.
>
> The only problem I have with this code is that the (unsigned int) filewriter
> writes header as 32-bit real. Walkaround is to manually change the output
> header from 32-bit real to 32-bit int in MRIcro.
>
> Look forward to the bug fixes.
> Thanks!
> Albert
>
> ----- Original Message -----
> From: "Richard Beare" <richard.beare at gmail.com>
> To: "Albert Huang" <alberth+itk at ece.ubc.ca>
> Cc: "Gaetan Lehmann" <gaetan.lehmann at jouy.inra.fr>; <insight-users at itk.org>
> Sent: Thursday, February 08, 2007 4:58 PM
> Subject: Re: [Insight-users] Watershed Behavior
>
> I see what you mean. That is a mystery.
>
> Can you package the code and input image too. This certainly suggests
> a bug that we should sort out.
>
> On 2/9/07, Albert Huang <alberth+itk at ece.ubc.ca> wrote:
> > Sorry. I can't seem to be able to save anything correctly. So I've
> > attached
> > my ANALYZE output volume in 32 bit int format which can be opened with
> > MRIcro.
> >
> >     http://www.ece.ubc.ca/~alberth/watershed_checker_label.img.gz
> >     http://www.ece.ubc.ca/~alberth/watershed_checker_label.hdr
> >
> > Thanks
> > Albert
> >
> > ----- Original Message -----
> > From: "Richard Beare" <richard.beare at gmail.com>
> > To: "Albert Huang" <alberth+itk at ece.ubc.ca>
> > Cc: "Gaetan Lehmann" <gaetan.lehmann at jouy.inra.fr>;
> > <insight-users at itk.org>
> > Sent: Thursday, February 08, 2007 4:33 PM
> > Subject: Re: [Insight-users] Watershed Behavior
> >
> > The png I get from the website is 8 bit - I can't see the problem.
> >
> > Can you try unsigned short tif or your current pixel type as nii.
> >
> > Thanks
> >
> > On 2/9/07, Albert Huang <alberth+itk at ece.ubc.ca> wrote:
> > > Thanks for the fast reply Richard.
> > >
> > > I quickly remove the relabel filter and save the output of watershed as
> > > unsigned int. As you can see with the grayscale image here:
> > >     http://www.ece.ubc.ca/~alberth/watershed_morph2.png
> > > The outputs are labeled as:
> > >     001 002 003 004 005 006 007 ... 018 <---------- topmost
> > >     325 326 327 328 329 330 331 ... 342
> > >             ..........
> > >     019 020 021 022 023 024 025 ... 036
> > >     001 002 003 004 005 006 007 ... 018 <---------- bottommost
> > > Where the topmost and bottommost rows are labeled as the same numbers or
> > > wrap around as I called it.
> > >
> > > Albert
> > >
> > > ----- Original Message -----
> > > From: "Richard Beare" <richard.beare at gmail.com>
> > > To: "Albert Huang" <alberth+itk at ece.ubc.ca>
> > > Cc: "Gaetan Lehmann" <gaetan.lehmann at jouy.inra.fr>;
> > > <insight-users at itk.org>
> > > Sent: Thursday, February 08, 2007 2:58 PM
> > > Subject: Re: [Insight-users] Watershed Behavior
> > >
> > > Hi,
> > > I'm having difficulty determining what you mean by wrap around - from
> > > the example it looks as though it could be wrap around of the
> > > colormap, rather than the watershed.
> > >
> > > Try saving the output of the watershed filter, rather than the
> > > relabeller/coloring step and probe the values. For example, save as
> > > unsigned short tif and use the ImageView or some other tool to check
> > > the values. There shouldn't be any wrap around, but you never know.
> > >
> > > On 2/9/07, Albert Huang <alberth+itk at ece.ubc.ca> wrote:
> > > > Thanks Richard and Gaetan
> > > >
> > > > The new filter works very well on the edges for my application.
> > > > However,
> > > > when I relabel my image after the morphological watershed, I get a
> > > > wrap
> > > > around on the very top and bottom grids (even though they are
> > > > alternating
> > > > intensity blocks). Is that a known behavior?
> > > >
> > > >         http://www.ece.ubc.ca/~alberth/watershed_morph.png
> > > >
> > > > The left and right image edge labels are ok with no wrap around.
> > > > Checking
> > > > the gradient magnitude image, all image edges have 0 gradient (top,
> > > > bottom,
> > > > left, right).
> > > >
> > > > My morphological watershed filter has
> > > >     input (double)
> > > >     output (unsigned long)
> > > >     SetMarkWatershedLine=false.
> > > > My relabel component image filter has
> > > >     input (unsigned long)
> > > >     output (unsigned int)
> > > > The relabeler outputs for my example are [1...342] which seems to be
> > > > still
> > > > well within the range of my output type.
> > > >
> > > > Albert
> > > >
> > > > ----- Original Message -----
> > > > From: "Gaetan Lehmann" <gaetan.lehmann at jouy.inra.fr>
> > > > To: "Albert Huang" <alberth+itk at ece.ubc.ca>
> > > > Cc: <Richard.Beare at ieee.org>; <insight-users at itk.org>
> > > > Sent: Thursday, February 08, 2007 1:48 AM
> > > > Subject: Re: [Insight-users] Watershed Behavior
> > > >
> > > >
> > > > Hi,
> > > >
> > > > You may also want to test the morphological watershed Richard and I
> > > > have
> > > > contributed, and see if it gives better results.
> > > >
> > > > http://hdl.handle.net/1926/202
> > > >
> > > > You can also found this new filter in ITK cvs now.
> > > >
> > > > Regards,
> > > >
> > > > Gaetan
> > > >
> > > >
> > > > On Thu, 08 Feb 2007 04:34:39 +0100, Richard Beare
> > > > <richard.beare at gmail.com> wrote:
> > > >
> > > > > Have a look at the gradient image and dheck whether there are
> > > > > plateaus
> > > > > in the zig-zag area. The behaviour of the standard itk watershed is
> > > > > somewhat arbitary in the presence of plateaus.
> > > > >
> > > > >
> > > > > On 2/8/07, Albert Huang <alberth+itk at ece.ubc.ca> wrote:
> > > > >>
> > > > >>
> > > > >> Dear experts
> > > > >>
> > > > >> I was just playing with the watershed pipeline a few days ago using
> > > > >> a
> > > > >> checkerboard pattern (with uint8 grids of black=64, gray=153,
> > > > >> white=192),
> > > > >> and observed a zig-zaggy pattern on some edges (see
> > > > >> http://www.ece.ubc.ca/~alberth/watershed.png). Adding a
> > > > >> smooth field on the checkboard results in more zig-zaggy behaviors
> > > > >> on
> > > > >> edges
> > > > >> that seem fairly strong in the input image. I am wondering if this
> > > > >> is
> > > > >> normal
> > > > >> behavior for the itkWatershedImageFilter?
> > > > >>
> > > > >> My pipeline (ITK 3.0.1) setup is as below:
> > > > >>     file reader ->
> > > > >>     vector gradient magnitude image filter (pca off) ->
> > > > >>     watershed (level=0.2, threshold=0.0) ->
> > > > >>     relabel component
> > > > >>
> > > > >> p.s. The black regions in the outputs are colormap problems and not
> > > > >> a
> > > > >> watershed issue. =)
> > > > >>
> > > > >> Thanks
> > > > >> Albert
> > > > >>
> > > > >> _______________________________________________
> > > > >> Insight-users mailing list
> > > > >> Insight-users at itk.org
> > > > >> http://www.itk.org/mailman/listinfo/insight-users
> > > > >>
> > > > >>
> > > > > _______________________________________________
> > > > > Insight-users mailing list
> > > > > Insight-users at itk.org
> > > > > http://www.itk.org/mailman/listinfo/insight-users
> > > >
> > > >
> > > >
> > > > --
> > > > Gaëtan Lehmann
> > > > Biologie du Développement et de la Reproduction
> > > > INRA de Jouy-en-Josas (France)
> > > > tel: +33 1 34 65 29 66    fax: 01 34 65 29 09
> > > > http://voxel.jouy.inra.fr
> > > >
> > > >
> > >
> >
>


More information about the Insight-users mailing list