[Insight-users] FW: Connected Threshold Filter

Wu Zheying u0303820 at nus.edu.sg
Thu Jan 18 03:48:36 EST 2007


Hi Luis,

for your information, i placed my seed in a vessel area where there is a contrast agent, therefore the upper and lower threshold i inputted is 250 - 255, hope it is clearer this way.

rgds
Zach


-----Original Message-----
From: Wu Zheying
Sent: Thu 1/18/2007 4:39 PM
To: Luis Ibanez; Insight Users
Subject: RE: [Insight-users] FW: Connected Threshold Filter
 
Hi Luis,

i am attaching my code here for your reference. I am using unsigned char for the output pixel type. The seed coordinates should be ok because i tried them with fast marching and it worked. Pls let me know if anything is wrong with the code?

rgds,
Zach

code:

#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif

#ifdef __BORLANDC__
#define ITK_LEAN_AND_MEAN
#endif




#include "itkConnectedThresholdImageFilter.h"
#include "itkImage.h"
#include "itkCastImageFilter.h"
#include "itkSubtractImageFilter.h" //added the image subtraction filter, but not used here
#include "itkCurvatureFlowImageFilter.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"


int main( int argc, char *argv[])
{
  if( argc < 8 )
    {
    std::cerr << "Missing Parameters " << std::endl;
    std::cerr << "Usage: " << argv[0];
    std::cerr << " inputImage  outputImage seedX seedY lowerThreshold upperThreshold  seedZ" << std::endl;
    return 1;
    }


  
  typedef   unsigned char          InternalPixelType;
  const     unsigned int    Dimension = 3;
  typedef itk::Image< InternalPixelType, Dimension >  InternalImageType;
  

  typedef unsigned char OutputPixelType;
  typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
  typedef itk::CastImageFilter< InternalImageType, OutputImageType >
    CastFilterType;
  CastFilterType::Pointer caster = CastFilterType::New();
  
  typedef  itk::ImageFileReader< InternalImageType > ReaderType;
  typedef  itk::ImageFileWriter<  OutputImageType  > WriterType;




  ReaderType::Pointer reader = ReaderType::New();
  
  WriterType::Pointer writer = WriterType::New();
  

  reader->SetFileName( argv[1] );
  
  writer->SetFileName( argv[2] );
 
  


    typedef itk::CurvatureFlowImageFilter< InternalImageType, InternalImageType >
    CurvatureFlowImageFilterType;
  


   CurvatureFlowImageFilterType::Pointer smoothing = 
                         CurvatureFlowImageFilterType::New();
  

  typedef itk::ConnectedThresholdImageFilter< InternalImageType, 
                                    InternalImageType > ConnectedFilterType;
    ConnectedFilterType::Pointer connectedThreshold = ConnectedFilterType::New();
  
  typedef itk::SubtractImageFilter< 
                                  InternalImageType, 
                                  InternalImageType, 
                                  InternalImageType > DifferenceFilterType;

  DifferenceFilterType::Pointer difference = DifferenceFilterType::New();

  smoothing->SetInput( reader->GetOutput() );
  connectedThreshold->SetInput( smoothing->GetOutput() );
  caster->SetInput (connectedThreshold->GetOutput());
  writer->SetInput ( caster->GetOutput());

  



  smoothing->SetNumberOfIterations( 1 );
  smoothing->SetTimeStep( 0.0625 );
  



  const InternalPixelType lowerThreshold = atof( argv[5] );
  const InternalPixelType upperThreshold = atof( argv[6] );

  connectedThreshold->SetLower(  lowerThreshold  );
  connectedThreshold->SetUpper(  upperThreshold  );
  


  connectedThreshold->SetReplaceValue( 255 );
  



  InternalImageType::IndexType  index;
  
  index[0] = atoi( argv[3] );
  index[1] = atoi( argv[4] );
  index[2] = atoi( argv[7] );


  connectedThreshold->SetSeed( index );

    try
    {
    writer->Update();
    }
  catch( itk::ExceptionObject & excep )
    {
    std::cerr << "Exception caught !" << std::endl;
    std::cerr << excep << std::endl;
    }
  




  return 0;
}






-----Original Message-----
From: Luis Ibanez [mailto:luis.ibanez at kitware.com]
Sent: Tue 1/16/2007 6:25 AM
To: Wu Zheying; Insight Users
Subject: Re: [Insight-users] FW: Connected Threshold Filter
 


Hi Zach,

 From your limited description is very difficult
to identify what the problem is.

You may have to start eliminating suspects one at
a time.

1) Have you verified that the analyze files are
    read correctly ? For example, pass the output
    of the reader to a writer, save the image and
    open it with a viewer to see if it is the same
    as the original.

2) Have you verified that the seeds are located
    in pixels with values that are inside the range
    defined by the lower,upper thresholds ?

3) What pixel type did you used for instantiating
    the output of the ConnectedThreshold image filter.

4) When you say that "My output is all black and
    has been reduced from 16 bit to 8bit when i view
    in MRIcro. "  do you mean that MRIcro reduced
    the pixel type of the image ? or do you mean
    that you change the pixel type inside your code ?



It will help a lot if you post your source code to
the list.


   Thanks


      Luis



---------------------
Wu Zheying wrote:
> Hi all,
> 
> I am doing the connected threshold filter example using analyze datasets and
> 3d input seeds. My output is all black and has been reduced from 16 bit to
> 8bit when i view in MRIcro. What is the reason for this? and what is the
> proper way to get past this problem?
> 
> much thanks,
> Zach
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20070118/92e8558f/attachment.htm


More information about the Insight-users mailing list