<!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> I am trying to segment 2D
numbered (.1, .2, .3 ,...) raw medical images with
ConnectedThresholdImageFilter, but for whatever upper and lower threshold
values I use, the resulting image is a tottaly BLACK one... 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> </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> </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> <string></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> </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> </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>
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>
typedef</FONT><FONT size=2><FONT face=Arial> itk::Image< PixelType >
ImageType;</FONT></DIV>
<DIV></FONT><FONT face=Arial color=#0000ff size=2>
typedef</FONT><FONT size=2><FONT face=Arial> itk::RawImageIO<PixelType >
IOType;</FONT></DIV>
<DIV></FONT><FONT face=Arial color=#0000ff size=2>
typedef</FONT><FONT size=2><FONT face=Arial> itk::ImageFileReader< ImageType
> ReaderType;</FONT></DIV>
<DIV></FONT><FONT face=Arial color=#0000ff size=2>
typedef</FONT><FONT size=2><FONT face=Arial> itk::ImageFileWriter< ImageType
> WriterType;</FONT></DIV>
<DIV></FONT><FONT face=Arial color=#0000ff size=2>
typedef</FONT><FONT size=2><FONT face=Arial>
itk::ConnectedThresholdImageFilter< ImageType, </FONT><FONT
face=Arial>ImageType > ConnectedFilterType;</FONT></DIV>
<DIV><FONT face=Arial></FONT> </DIV>
<DIV><FONT face=Arial> string inputFile;</FONT></DIV>
<DIV><FONT face=Arial> string outputFile;</FONT></DIV>
<DIV><FONT face=Arial> mscVolumeProperties* vp;</FONT></DIV>
<DIV><FONT face=Arial> ReaderType::Pointer
reader;</FONT></DIV>
<DIV><FONT face=Arial> WriterType::Pointer
writer;</FONT></DIV>
<DIV><FONT face=Arial> IOType::Pointer io;</FONT></DIV>
<DIV><FONT face=Arial> ConnectedFilterType::Pointer
connectedThreshold ;</FONT></DIV>
<DIV><FONT face=Arial> PixelType lowerThreshold;</FONT></DIV>
<DIV><FONT face=Arial> PixelType upperThreshold;</FONT></DIV>
<DIV><FONT face=Arial> ImageType::IndexType
index;</FONT></DIV></FONT><FONT color=#0000ff size=2>
<DIV><FONT face=Arial color=#000000></FONT> </DIV>
<DIV><FONT face=Arial color=#000000>public</FONT></FONT><FONT size=2><FONT
face=Arial>:</FONT></DIV>
<DIV><FONT face=Arial> RegionGrowingSeg(mscVolumeProperties*
v){vp = v;}</FONT></DIV>
<DIV><FONT face=Arial> RegionGrowingSeg(){ vp =
NULL;}</FONT></DIV>
<DIV></FONT><FONT face=Arial><FONT color=#0000ff size=2>
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>
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>
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>
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>
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>
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>
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> </DIV>
<DIV><FONT face=Arial><FONT color=#0000ff size=2>
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> {</FONT></DIV>
<DIV><FONT face=Arial>
index[0]=in[0];</FONT></DIV>
<DIV><FONT face=Arial>
index[1]=in[1];</FONT></DIV>
<DIV></FONT><FONT size=2><FONT face=Arial> }</FONT></DIV>
<DIV><FONT face=Arial color=#0000ff></FONT></FONT><FONT face=Arial color=#0000ff
size=2></FONT> </DIV>
<DIV><FONT face=Arial color=#0000ff size=2> void</FONT><FONT
size=2><FONT face=Arial> segment();</FONT></DIV>
<DIV></FONT><FONT face=Arial><FONT color=#0000ff size=2>
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>
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>
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>
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>
int</FONT><FONT size=2><FONT face=Arial>* getIndex()</FONT></DIV>
<DIV><FONT face=Arial> {</FONT></DIV>
<DIV></FONT><FONT face=Arial color=#0000ff size=2>
int</FONT><FONT size=2><FONT face=Arial> ri[2];</FONT></DIV>
<DIV><FONT face=Arial> ri[0] =
index[0];</FONT></DIV>
<DIV><FONT face=Arial> ri[1] =
index[1];</FONT></DIV>
<DIV></FONT><FONT face=Arial color=#0000ff size=2>
return</FONT><FONT size=2><FONT face=Arial> ri;</FONT></DIV>
<DIV><FONT face=Arial> }</FONT></DIV>
<DIV><FONT face=Arial>};</FONT></DIV>
<DIV><FONT face=Arial></FONT> </DIV>
<DIV><FONT face=Arial></FONT> </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> reader =
ReaderType::New();</FONT></DIV>
<DIV><FONT face=Arial> writer =
WriterType::New();</FONT></DIV>
<DIV><FONT face=Arial> io = IOType::New();</FONT></DIV>
<DIV></FONT><FONT color=#008000 size=2><FONT face=Arial>
//Sets para as dimensões da imagem raw:</FONT></DIV></FONT><FONT size=2>
<DIV><FONT face=Arial></FONT> </DIV>
<DIV><FONT face=Arial>
io->SetDimensions(0,vp->GetHeight());</FONT></DIV>
<DIV><FONT face=Arial>
io->SetDimensions(1,vp->GetWidth() );</FONT></DIV>
<DIV><FONT face=Arial> reader->SetImageIO( io
);</FONT></DIV>
<DIV><FONT face=Arial> writer->SetImageIO( io
);</FONT></DIV>
<DIV><FONT face=Arial></FONT> </DIV>
<DIV><FONT face=Arial> reader->SetFileName(
inputFile.c_str() );</FONT></DIV>
<DIV><FONT face=Arial> connectedThreshold =
ConnectedFilterType::New();</FONT></DIV>
<DIV><FONT face=Arial> connectedThreshold->SetInput(
reader->GetOutput() );</FONT></DIV>
<DIV><FONT face=Arial></FONT> </DIV>
<DIV><FONT face=Arial> connectedThreshold->SetReplaceValue(
1 );</FONT></DIV>
<DIV><FONT face=Arial> connectedThreshold->SetSeed( index
);</FONT></DIV>
<DIV><FONT face=Arial> connectedThreshold->SetLower(
lowerThreshold );</FONT></DIV>
<DIV><FONT face=Arial> connectedThreshold->SetUpper(
upperThreshold );</FONT></DIV>
<DIV><FONT face=Arial></FONT> </DIV>
<DIV><FONT face=Arial> writer->SetInput(
connectedThreshold->GetOutput() );</FONT></DIV>
<DIV><FONT face=Arial> writer->SetFileName(
outputFile.c_str() );</FONT></DIV>
<DIV></FONT><FONT face=Arial color=#0000ff size=2>
try</FONT><FONT size=2><FONT face=Arial>{</FONT></DIV>
<DIV><FONT face=Arial>
writer->Update();</FONT></DIV>
<DIV><FONT face=Arial> }</FONT></DIV>
<DIV></FONT><FONT face=Arial color=#0000ff size=2>
catch</FONT><FONT size=2><FONT face=Arial>( itk::ExceptionObject & err
){</FONT></DIV>
<DIV><FONT face=Arial> std::cerr<<"Excecao
capturada!";</FONT></DIV>
<DIV><FONT face=Arial> std::cout << err <<
std::endl;</FONT></DIV>
<DIV><FONT face=Arial> }</FONT></DIV>
<DIV><FONT face=Arial>}</FONT></DIV></FONT></FONT></BODY></HTML>