<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7650.28">
<TITLE>RE: [Insight-users] FW: Connected Threshold Filter</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->
<P><FONT SIZE=2>Hi Luis,<BR>
<BR>
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?<BR>
<BR>
rgds,<BR>
Zach<BR>
<BR>
code:<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>
<BR>
<BR>
#include "itkConnectedThresholdImageFilter.h"<BR>
#include "itkImage.h"<BR>
#include "itkCastImageFilter.h"<BR>
#include "itkSubtractImageFilter.h" //added the image subtraction filter, but not used here<BR>
#include "itkCurvatureFlowImageFilter.h"<BR>
#include "itkImageFileReader.h"<BR>
#include "itkImageFileWriter.h"<BR>
<BR>
<BR>
int main( int argc, char *argv[])<BR>
{<BR>
if( argc < 8 )<BR>
{<BR>
std::cerr << "Missing Parameters " << std::endl;<BR>
std::cerr << "Usage: " << argv[0];<BR>
std::cerr << " inputImage outputImage seedX seedY lowerThreshold upperThreshold seedZ" << std::endl;<BR>
return 1;<BR>
}<BR>
<BR>
<BR>
<BR>
typedef unsigned char InternalPixelType;<BR>
const unsigned int Dimension = 3;<BR>
typedef itk::Image< InternalPixelType, Dimension > InternalImageType;<BR>
<BR>
<BR>
typedef unsigned char OutputPixelType;<BR>
typedef itk::Image< OutputPixelType, Dimension > OutputImageType;<BR>
typedef itk::CastImageFilter< InternalImageType, OutputImageType ><BR>
CastFilterType;<BR>
CastFilterType::Pointer caster = CastFilterType::New();<BR>
<BR>
typedef itk::ImageFileReader< InternalImageType > ReaderType;<BR>
typedef itk::ImageFileWriter< OutputImageType > WriterType;<BR>
<BR>
<BR>
<BR>
<BR>
ReaderType::Pointer reader = ReaderType::New();<BR>
<BR>
WriterType::Pointer writer = WriterType::New();<BR>
<BR>
<BR>
reader->SetFileName( argv[1] );<BR>
<BR>
writer->SetFileName( argv[2] );<BR>
<BR>
<BR>
<BR>
<BR>
typedef itk::CurvatureFlowImageFilter< InternalImageType, InternalImageType ><BR>
CurvatureFlowImageFilterType;<BR>
<BR>
<BR>
<BR>
CurvatureFlowImageFilterType::Pointer smoothing =<BR>
CurvatureFlowImageFilterType::New();<BR>
<BR>
<BR>
typedef itk::ConnectedThresholdImageFilter< InternalImageType,<BR>
InternalImageType > ConnectedFilterType;<BR>
ConnectedFilterType::Pointer connectedThreshold = ConnectedFilterType::New();<BR>
<BR>
typedef itk::SubtractImageFilter<<BR>
InternalImageType,<BR>
InternalImageType,<BR>
InternalImageType > DifferenceFilterType;<BR>
<BR>
DifferenceFilterType::Pointer difference = DifferenceFilterType::New();<BR>
<BR>
smoothing->SetInput( reader->GetOutput() );<BR>
connectedThreshold->SetInput( smoothing->GetOutput() );<BR>
caster->SetInput (connectedThreshold->GetOutput());<BR>
writer->SetInput ( caster->GetOutput());<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
smoothing->SetNumberOfIterations( 1 );<BR>
smoothing->SetTimeStep( 0.0625 );<BR>
<BR>
<BR>
<BR>
<BR>
const InternalPixelType lowerThreshold = atof( argv[5] );<BR>
const InternalPixelType upperThreshold = atof( argv[6] );<BR>
<BR>
connectedThreshold->SetLower( lowerThreshold );<BR>
connectedThreshold->SetUpper( upperThreshold );<BR>
<BR>
<BR>
<BR>
connectedThreshold->SetReplaceValue( 255 );<BR>
<BR>
<BR>
<BR>
<BR>
InternalImageType::IndexType index;<BR>
<BR>
index[0] = atoi( argv[3] );<BR>
index[1] = atoi( argv[4] );<BR>
index[2] = atoi( argv[7] );<BR>
<BR>
<BR>
connectedThreshold->SetSeed( index );<BR>
<BR>
try<BR>
{<BR>
writer->Update();<BR>
}<BR>
catch( itk::ExceptionObject & excep )<BR>
{<BR>
std::cerr << "Exception caught !" << std::endl;<BR>
std::cerr << excep << std::endl;<BR>
}<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
return 0;<BR>
}<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
-----Original Message-----<BR>
From: Luis Ibanez [<A HREF="mailto:luis.ibanez@kitware.com">mailto:luis.ibanez@kitware.com</A>]<BR>
Sent: Tue 1/16/2007 6:25 AM<BR>
To: Wu Zheying; Insight Users<BR>
Subject: Re: [Insight-users] FW: Connected Threshold Filter<BR>
<BR>
<BR>
<BR>
Hi Zach,<BR>
<BR>
From your limited description is very difficult<BR>
to identify what the problem is.<BR>
<BR>
You may have to start eliminating suspects one at<BR>
a time.<BR>
<BR>
1) Have you verified that the analyze files are<BR>
read correctly ? For example, pass the output<BR>
of the reader to a writer, save the image and<BR>
open it with a viewer to see if it is the same<BR>
as the original.<BR>
<BR>
2) Have you verified that the seeds are located<BR>
in pixels with values that are inside the range<BR>
defined by the lower,upper thresholds ?<BR>
<BR>
3) What pixel type did you used for instantiating<BR>
the output of the ConnectedThreshold image filter.<BR>
<BR>
4) When you say that "My output is all black and<BR>
has been reduced from 16 bit to 8bit when i view<BR>
in MRIcro. " do you mean that MRIcro reduced<BR>
the pixel type of the image ? or do you mean<BR>
that you change the pixel type inside your code ?<BR>
<BR>
<BR>
<BR>
It will help a lot if you post your source code to<BR>
the list.<BR>
<BR>
<BR>
Thanks<BR>
<BR>
<BR>
Luis<BR>
<BR>
<BR>
<BR>
---------------------<BR>
Wu Zheying wrote:<BR>
> Hi all,<BR>
><BR>
> I am doing the connected threshold filter example using analyze datasets and<BR>
> 3d input seeds. My output is all black and has been reduced from 16 bit to<BR>
> 8bit when i view in MRIcro. What is the reason for this? and what is the<BR>
> proper way to get past this problem?<BR>
><BR>
> much thanks,<BR>
> Zach<BR>
><BR>
><BR>
> ------------------------------------------------------------------------<BR>
><BR>
> _______________________________________________<BR>
> Insight-users mailing list<BR>
> Insight-users@itk.org<BR>
> <A HREF="http://www.itk.org/mailman/listinfo/insight-users">http://www.itk.org/mailman/listinfo/insight-users</A><BR>
<BR>
</FONT>
</P>
</BODY>
</HTML>