<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2800.1528" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>Hi!</FONT></DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp; I am trying to segment 2D 
numbered (.1, .2, .3 ,...) raw medical images with 
ConnectedThresholdImageFilter, but for whatever upper and lower threshold 
values&nbsp;I use, the resulting image is a tottaly BLACK one...&nbsp; I'm using 
unsigned short for the pixel type, don't know if that's correct. The images are 
64x64 pixels in dimension, and all index adjustments, file names and threshold 
values seem to be just right. Any ideas on this one?</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Here's the code:</FONT></DIV>
<DIV><FONT face=Arial size=2>//(mscVolumeProperties is a class for storing 
height, width, file names, etc... through the entire app)</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>// rgSeg.h</FONT></DIV><FONT color=#0000ff size=2>
<DIV><FONT face=Arial color=#000000>#include</FONT></FONT><FONT size=2><FONT 
face=Arial> "itkImageFileReader.h"</FONT></DIV></FONT><FONT color=#0000ff 
size=2>
<DIV><FONT face=Arial color=#000000>#include</FONT></FONT><FONT size=2><FONT 
face=Arial> "itkImageFileWriter.h"</FONT></DIV></FONT><FONT color=#0000ff 
size=2>
<DIV><FONT face=Arial color=#000000>#include</FONT></FONT><FONT size=2><FONT 
face=Arial> "itkRawImageIO.h"</FONT></DIV></FONT><FONT color=#0000ff size=2>
<DIV><FONT face=Arial color=#000000>#include</FONT></FONT><FONT size=2><FONT 
face=Arial> "itkVTKImageExport.h"</FONT></DIV></FONT><FONT color=#0000ff size=2>
<DIV><FONT face=Arial color=#000000>#include</FONT></FONT><FONT size=2><FONT 
face=Arial> "itkVTKImageExportBase.h"</FONT></DIV></FONT><FONT color=#0000ff 
size=2>
<DIV><FONT face=Arial color=#000000>#include</FONT></FONT><FONT size=2><FONT 
face=Arial> "itkImage.h"</FONT></DIV></FONT><FONT color=#0000ff size=2>
<DIV><FONT face=Arial color=#000000>#include</FONT></FONT><FONT size=2><FONT 
face=Arial> "itkConnectedThresholdImageFilter.h"</FONT></DIV></FONT><FONT 
color=#0000ff size=2>
<DIV><FONT face=Arial color=#000000>#include</FONT></FONT><FONT size=2><FONT 
face=Arial> &lt;string&gt;</FONT></DIV></FONT><FONT color=#0000ff size=2>
<DIV><FONT face=Arial color=#000000>using</FONT></FONT><FONT size=2><FONT 
face=Arial> std::string;</FONT></DIV></FONT><FONT color=#0000ff size=2>
<DIV><FONT face=Arial color=#000000></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial color=#000000>class</FONT></FONT><FONT size=2><FONT 
face=Arial> mscVolumeProperties;</FONT></DIV></FONT><FONT color=#0000ff size=2>
<DIV><FONT face=Arial color=#000000></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial color=#000000>class</FONT></FONT><FONT size=2><FONT 
face=Arial> RegionGrowingSeg</FONT></DIV>
<DIV><FONT face=Arial>{</FONT></DIV></FONT><FONT color=#0000ff size=2>
<DIV><FONT face=Arial color=#000000>private</FONT></FONT><FONT size=2><FONT 
face=Arial>:</FONT></DIV>
<DIV></FONT><FONT face=Arial><FONT color=#0000ff size=2>&nbsp;&nbsp;&nbsp; 
typedef</FONT><FONT size=2> </FONT><FONT color=#0000ff 
size=2>unsigned</FONT><FONT size=2> </FONT><FONT color=#0000ff 
size=2>short</FONT></FONT><FONT size=2><FONT face=Arial> PixelType;</FONT></DIV>
<DIV></FONT><FONT face=Arial color=#0000ff size=2>&nbsp;&nbsp;&nbsp; 
typedef</FONT><FONT size=2><FONT face=Arial> itk::Image&lt; PixelType &gt; 
ImageType;</FONT></DIV>
<DIV></FONT><FONT face=Arial color=#0000ff size=2>&nbsp;&nbsp;&nbsp; 
typedef</FONT><FONT size=2><FONT face=Arial> itk::RawImageIO&lt;PixelType &gt; 
IOType;</FONT></DIV>
<DIV></FONT><FONT face=Arial color=#0000ff size=2>&nbsp;&nbsp;&nbsp; 
typedef</FONT><FONT size=2><FONT face=Arial> itk::ImageFileReader&lt; ImageType 
&gt; ReaderType;</FONT></DIV>
<DIV></FONT><FONT face=Arial color=#0000ff size=2>&nbsp;&nbsp;&nbsp; 
typedef</FONT><FONT size=2><FONT face=Arial> itk::ImageFileWriter&lt; ImageType 
&gt; WriterType;</FONT></DIV>
<DIV></FONT><FONT face=Arial color=#0000ff size=2>&nbsp;&nbsp;&nbsp; 
typedef</FONT><FONT size=2><FONT face=Arial> 
itk::ConnectedThresholdImageFilter&lt; ImageType,&nbsp;</FONT><FONT 
face=Arial>ImageType &gt; ConnectedFilterType;</FONT></DIV>
<DIV><FONT face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial>&nbsp;&nbsp;&nbsp; string inputFile;</FONT></DIV>
<DIV><FONT face=Arial>&nbsp;&nbsp;&nbsp; string outputFile;</FONT></DIV>
<DIV><FONT face=Arial>&nbsp;&nbsp;&nbsp; mscVolumeProperties* vp;</FONT></DIV>
<DIV><FONT face=Arial>&nbsp;&nbsp;&nbsp; ReaderType::Pointer 
reader;</FONT></DIV>
<DIV><FONT face=Arial>&nbsp;&nbsp;&nbsp; WriterType::Pointer 
writer;</FONT></DIV>
<DIV><FONT face=Arial>&nbsp;&nbsp;&nbsp; IOType::Pointer io;</FONT></DIV>
<DIV><FONT face=Arial>&nbsp;&nbsp;&nbsp; ConnectedFilterType::Pointer 
connectedThreshold ;</FONT></DIV>
<DIV><FONT face=Arial>&nbsp;&nbsp;&nbsp; PixelType lowerThreshold;</FONT></DIV>
<DIV><FONT face=Arial>&nbsp;&nbsp;&nbsp; PixelType upperThreshold;</FONT></DIV>
<DIV><FONT face=Arial>&nbsp;&nbsp;&nbsp; ImageType::IndexType 
index;</FONT></DIV></FONT><FONT color=#0000ff size=2>
<DIV><FONT face=Arial color=#000000></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial color=#000000>public</FONT></FONT><FONT size=2><FONT 
face=Arial>:</FONT></DIV>
<DIV><FONT face=Arial>&nbsp;&nbsp;&nbsp; RegionGrowingSeg(mscVolumeProperties* 
v){vp = v;}</FONT></DIV>
<DIV><FONT face=Arial>&nbsp;&nbsp;&nbsp; RegionGrowingSeg(){ vp = 
NULL;}</FONT></DIV>
<DIV></FONT><FONT face=Arial><FONT color=#0000ff size=2>&nbsp;&nbsp;&nbsp; 
static</FONT><FONT size=2> RegionGrowingSeg* New(mscVolumeProperties* 
v){</FONT><FONT color=#0000ff size=2>return</FONT><FONT size=2> </FONT><FONT 
color=#0000ff size=2>new</FONT></FONT><FONT size=2><FONT face=Arial> 
RegionGrowingSeg(v);}</FONT></DIV>
<DIV></FONT><FONT face=Arial><FONT color=#0000ff size=2>&nbsp;&nbsp;&nbsp; 
static</FONT><FONT size=2> RegionGrowingSeg* New(){</FONT><FONT color=#0000ff 
size=2>return</FONT><FONT size=2> </FONT><FONT color=#0000ff 
size=2>new</FONT></FONT><FONT size=2><FONT face=Arial> 
RegionGrowingSeg();}</FONT></DIV>
<DIV></FONT><FONT face=Arial color=#0000ff size=2>&nbsp;&nbsp;&nbsp; 
void</FONT><FONT size=2><FONT face=Arial> setVP(mscVolumeProperties* v) {vp = 
v;}</FONT></DIV>
<DIV></FONT><FONT face=Arial><FONT color=#0000ff size=2>&nbsp;&nbsp;&nbsp; 
void</FONT><FONT size=2> setInputFileName(</FONT><FONT color=#0000ff 
size=2>const</FONT><FONT size=2> </FONT><FONT color=#0000ff 
size=2>char</FONT></FONT><FONT size=2><FONT face=Arial>* 
ifn){inputFile.assign(ifn);}</FONT></DIV>
<DIV></FONT><FONT face=Arial><FONT color=#0000ff size=2>&nbsp;&nbsp;&nbsp; 
void</FONT><FONT size=2> setOutputFileName(</FONT><FONT color=#0000ff 
size=2>const</FONT><FONT size=2> </FONT><FONT color=#0000ff 
size=2>char</FONT></FONT><FONT size=2><FONT face=Arial>* 
ofn){outputFile.assign(ofn);}</FONT></DIV>
<DIV></FONT><FONT face=Arial><FONT color=#0000ff size=2>&nbsp;&nbsp;&nbsp; 
void</FONT><FONT size=2> setLowerThreshold(</FONT><FONT color=#0000ff 
size=2>unsigned</FONT><FONT size=2> </FONT><FONT color=#0000ff 
size=2>short</FONT></FONT><FONT size=2><FONT face=Arial> lt){lowerThreshold = 
lt;}</FONT></DIV>
<DIV></FONT><FONT face=Arial><FONT color=#0000ff size=2>&nbsp;&nbsp;&nbsp; 
void</FONT><FONT size=2> setUpperThreshold(</FONT><FONT color=#0000ff 
size=2>unsigned</FONT><FONT size=2> </FONT><FONT color=#0000ff 
size=2>short</FONT></FONT><FONT size=2><FONT face=Arial> ut){upperThreshold = 
ut;}</FONT></DIV>
<DIV><FONT face=Arial color=#0000ff></FONT></FONT><FONT face=Arial><FONT 
color=#0000ff size=2></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT color=#0000ff size=2>&nbsp;&nbsp;&nbsp; 
void</FONT><FONT size=2> setIndex(</FONT><FONT color=#0000ff 
size=2>int</FONT></FONT><FONT size=2><FONT face=Arial>* in)</FONT></DIV>
<DIV><FONT face=Arial>&nbsp;&nbsp;&nbsp; {</FONT></DIV>
<DIV><FONT face=Arial>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
index[0]=in[0];</FONT></DIV>
<DIV><FONT face=Arial>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
index[1]=in[1];</FONT></DIV>
<DIV></FONT><FONT size=2><FONT face=Arial>&nbsp;&nbsp;&nbsp; }</FONT></DIV>
<DIV><FONT face=Arial color=#0000ff></FONT></FONT><FONT face=Arial color=#0000ff 
size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial color=#0000ff size=2>&nbsp;&nbsp;&nbsp; void</FONT><FONT 
size=2><FONT face=Arial> segment();</FONT></DIV>
<DIV></FONT><FONT face=Arial><FONT color=#0000ff size=2>&nbsp;&nbsp;&nbsp; 
const</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>char</FONT><FONT 
size=2>* getInputFileName() </FONT><FONT color=#0000ff size=2>const</FONT><FONT 
size=2> {</FONT><FONT color=#0000ff size=2>return</FONT></FONT><FONT 
size=2><FONT face=Arial> inputFile.c_str();}</FONT></DIV>
<DIV></FONT><FONT face=Arial><FONT color=#0000ff size=2>&nbsp;&nbsp;&nbsp; 
const</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>char</FONT><FONT 
size=2>* getOutputFileName() </FONT><FONT color=#0000ff size=2>const</FONT><FONT 
size=2> {</FONT><FONT color=#0000ff size=2>return</FONT></FONT><FONT 
size=2><FONT face=Arial> outputFile.c_str();}</FONT></DIV>
<DIV></FONT><FONT face=Arial><FONT color=#0000ff size=2>&nbsp;&nbsp;&nbsp; 
unsigned</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>short</FONT><FONT 
size=2> getLowerThreshold(){</FONT><FONT color=#0000ff 
size=2>return</FONT></FONT><FONT size=2><FONT face=Arial> 
lowerThreshold;}</FONT></DIV>
<DIV></FONT><FONT face=Arial><FONT color=#0000ff size=2>&nbsp;&nbsp;&nbsp; 
unsigned</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>short</FONT><FONT 
size=2> getUpperThreshold(){</FONT><FONT color=#0000ff 
size=2>return</FONT></FONT><FONT size=2><FONT face=Arial> 
upperThreshold;}</FONT></DIV>
<DIV></FONT><FONT face=Arial color=#0000ff size=2>&nbsp;&nbsp;&nbsp; 
int</FONT><FONT size=2><FONT face=Arial>* getIndex()</FONT></DIV>
<DIV><FONT face=Arial>&nbsp;&nbsp;&nbsp; {</FONT></DIV>
<DIV></FONT><FONT face=Arial color=#0000ff size=2>&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp; int</FONT><FONT size=2><FONT face=Arial> ri[2];</FONT></DIV>
<DIV><FONT face=Arial>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ri[0] = 
index[0];</FONT></DIV>
<DIV><FONT face=Arial>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ri[1] = 
index[1];</FONT></DIV>
<DIV></FONT><FONT face=Arial color=#0000ff size=2>&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp; return</FONT><FONT size=2><FONT face=Arial> ri;</FONT></DIV>
<DIV><FONT face=Arial>&nbsp;&nbsp;&nbsp; }</FONT></DIV>
<DIV><FONT face=Arial>};</FONT></DIV>
<DIV><FONT face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial>// rgSeg.cpp:</FONT></DIV><FONT color=#0000ff size=2>
<DIV><FONT face=Arial color=#000000>#include</FONT></FONT><FONT face=Arial 
size=2> "rgSeg.h"</FONT><FONT color=#008000 size=2></DIV></FONT><FONT 
color=#0000ff size=2>
<DIV><FONT face=Arial color=#000000>void</FONT></FONT><FONT size=2><FONT 
face=Arial> RegionGrowingSeg::segment()</FONT></DIV>
<DIV><FONT face=Arial>{</FONT></DIV>
<DIV><FONT face=Arial>&nbsp;&nbsp;&nbsp; reader = 
ReaderType::New();</FONT></DIV>
<DIV><FONT face=Arial>&nbsp;&nbsp;&nbsp; writer = 
WriterType::New();</FONT></DIV>
<DIV><FONT face=Arial>&nbsp;&nbsp;&nbsp; io = IOType::New();</FONT></DIV>
<DIV></FONT><FONT color=#008000 size=2><FONT face=Arial>&nbsp;&nbsp;&nbsp; 
//Sets para as dimensões da imagem raw:</FONT></DIV></FONT><FONT size=2>
<DIV><FONT face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial>&nbsp;&nbsp;&nbsp; 
io-&gt;SetDimensions(0,vp-&gt;GetHeight());</FONT></DIV>
<DIV><FONT face=Arial>&nbsp;&nbsp;&nbsp; 
io-&gt;SetDimensions(1,vp-&gt;GetWidth() );</FONT></DIV>
<DIV><FONT face=Arial>&nbsp;&nbsp;&nbsp; reader-&gt;SetImageIO( io 
);</FONT></DIV>
<DIV><FONT face=Arial>&nbsp;&nbsp;&nbsp; writer-&gt;SetImageIO( io 
);</FONT></DIV>
<DIV><FONT face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial>&nbsp;&nbsp;&nbsp; reader-&gt;SetFileName( 
inputFile.c_str() );</FONT></DIV>
<DIV><FONT face=Arial>&nbsp;&nbsp;&nbsp; connectedThreshold = 
ConnectedFilterType::New();</FONT></DIV>
<DIV><FONT face=Arial>&nbsp;&nbsp;&nbsp; connectedThreshold-&gt;SetInput( 
reader-&gt;GetOutput() );</FONT></DIV>
<DIV><FONT face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial>&nbsp;&nbsp;&nbsp; connectedThreshold-&gt;SetReplaceValue( 
1 );</FONT></DIV>
<DIV><FONT face=Arial>&nbsp;&nbsp;&nbsp; connectedThreshold-&gt;SetSeed( index 
);</FONT></DIV>
<DIV><FONT face=Arial>&nbsp;&nbsp;&nbsp; connectedThreshold-&gt;SetLower( 
lowerThreshold );</FONT></DIV>
<DIV><FONT face=Arial>&nbsp;&nbsp;&nbsp; connectedThreshold-&gt;SetUpper( 
upperThreshold );</FONT></DIV>
<DIV><FONT face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial>&nbsp;&nbsp;&nbsp; writer-&gt;SetInput( 
connectedThreshold-&gt;GetOutput() );</FONT></DIV>
<DIV><FONT face=Arial>&nbsp;&nbsp;&nbsp; writer-&gt;SetFileName( 
outputFile.c_str() );</FONT></DIV>
<DIV></FONT><FONT face=Arial color=#0000ff size=2>&nbsp;&nbsp;&nbsp; 
try</FONT><FONT size=2><FONT face=Arial>{</FONT></DIV>
<DIV><FONT face=Arial>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
writer-&gt;Update();</FONT></DIV>
<DIV><FONT face=Arial>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</FONT></DIV>
<DIV></FONT><FONT face=Arial color=#0000ff size=2>&nbsp;&nbsp;&nbsp; 
catch</FONT><FONT size=2><FONT face=Arial>( itk::ExceptionObject &amp; err 
){</FONT></DIV>
<DIV><FONT face=Arial>&nbsp;&nbsp;&nbsp; std::cerr&lt;&lt;"Excecao 
capturada!";</FONT></DIV>
<DIV><FONT face=Arial>&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; err &lt;&lt; 
std::endl;</FONT></DIV>
<DIV><FONT face=Arial>&nbsp;&nbsp;&nbsp; }</FONT></DIV>
<DIV><FONT face=Arial>}</FONT></DIV></FONT></FONT></BODY></HTML>