<HTML>
<HEAD>
<TITLE>How to deform segmentation to compare registration result??</TITLE>
</HEAD>
<BODY>
<FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'>Hi, I just started to use ITK and am comparing the performance of the registration algorithms.<BR>
When I deform a brain label segmentation, I have many artifacts in the segmentation.<BR>
<BR>
The procedure is as follows.<BR>
Let’s say I have 5, 3D brain images with ground truth segmentations.<BR>
So I register all the brains to one specific brain then using the deformation field found, I transform all the segmentation to the same specific brain. Then I measure how well the each segmented region is overlapping each other.<BR>
But problem I have now is that after I transform the segmentation, I observe lots of salt and pepper like noise here there inside each region. <BR>
<BR>
<BR>
One more question is...how long does 3D BSplineTransform usually take??? I have 7*7*7 landmarks and it takes around 2 minutes in intel 2.4 mobile cpu 2GB memory.<BR>
<BR>
Thank you!!!<BR>
<BR>
Here is the code for Bspline deformation that I am using .......<BR>
</SPAN></FONT><SPAN STYLE='font-size:11pt'><FONT FACE="Palatino"><BR>
<FONT COLOR="#BF0090">const</FONT> <FONT COLOR="#BF0090">unsigned</FONT> <FONT COLOR="#BF0090">int</FONT> ImageDimension = </FONT><FONT COLOR="#2800D4"><FONT FACE="Monaco, Courier New">3</FONT></FONT><FONT FACE="Palatino">; <BR>
<BR>
<BR>
<FONT COLOR="#BF0090">typedef</FONT> itk::ImageFileWriter< ITKIMAGE3D > MovingWriterType; <BR>
MovingWriterType::Pointer movingWriter = MovingWriterType::New(); <BR>
<BR>
<FONT COLOR="#BF0090">typedef</FONT> itk::ResampleImageFilter< ITKIMAGE3D, <BR>
ITKIMAGE3D > FilterType;<BR>
ITKIMAGE3D::Pointer fixedImage=itkimage_src;<BR>
<BR>
FilterType::Pointer resampler = FilterType::New(); <BR>
<FONT COLOR="#BF0090">typedef</FONT> itk::LinearInterpolateImageFunction< <BR>
ITKIMAGE3D, <FONT COLOR="#BF0090">double</FONT> > InterpolatorType; <BR>
InterpolatorType::Pointer interpolator = InterpolatorType::New(); <BR>
resampler->SetInterpolator( interpolator ); <BR>
ITKIMAGE3D::SpacingType fixedSpacing = fixedImage->GetSpacing();<BR>
ITKIMAGE3D::PointType fixedOrigin = fixedImage->GetOrigin();<BR>
ITKIMAGE3D::DirectionType fixedDirection = fixedImage->GetDirection();<BR>
<BR>
resampler->SetOutputSpacing( fixedSpacing ); <BR>
resampler->SetOutputOrigin( fixedOrigin ); <BR>
resampler->SetOutputDirection( fixedDirection ); <BR>
<BR>
ITKIMAGE3D::RegionType fixedRegion = fixedImage->GetLargestPossibleRegion();<BR>
ITKIMAGE3D::SizeType fixedSize = fixedRegion.GetSize(); <BR>
resampler->SetSize( fixedSize ); <BR>
resampler->SetOutputStartIndex( fixedRegion.GetIndex() ); <BR>
resampler->SetInput(itkimage_dst ); <BR>
movingWriter->SetInput( resampler->GetOutput() ); <BR>
movingWriter->SetFileName(outputPath);<BR>
</FONT></SPAN><FONT FACE="Palatino"><FONT COLOR="#007600"><FONT SIZE="1"><SPAN STYLE='font-size:9pt'>/*<BR>
We instantiate now the type of the BSplineDeformableTransform using as template param- <BR>
eters the type for coordinates representation, the dimension of the space, and the order of the <BR>
B-spline.*/<BR>
</SPAN></FONT></FONT><FONT SIZE="2"><SPAN STYLE='font-size:10pt'> <BR>
TransformType3D::Pointer bsplineTransform = TransformType3D::New(); <BR>
</SPAN></FONT><FONT COLOR="#007600"><FONT SIZE="1"><SPAN STYLE='font-size:9pt'>/*Since we are using a B-spline of order 3, the coverage of the BSpling grid should exceed by one <BR>
the spatial extent of the image on the lower region of image indices, and by two grid points on <BR>
the upper region of image indices. We choose here to use a 8 <BR>
× 8 B-spline grid, from which only <BR>
a 5 by 5 sub-grid will be covering the input image. If we use an input image of size 500 by 500<BR>
pixels, and pixel spacing 2.0 × 2.0 then we need the 5 × 5 B-spline grid to cover a physical <BR>
extent of 1000 × 1000 mm. This can be achieved by setting the pixel spacing of the B-spline <BR>
grid to 250.0 × 250.0 mm. The origin of the B-spline grid must be set at one grid position away <BR>
from the origin of the desired output image. All this is done with the following lines of code. */<BR>
</SPAN></FONT></FONT><FONT SIZE="2"><SPAN STYLE='font-size:10pt'> <BR>
<FONT COLOR="#BF0090">typedef</FONT> TransformType3D::RegionType RegionType; <BR>
RegionType bsplineRegion; </SPAN></FONT><FONT COLOR="#007600"><FONT SIZE="1"><SPAN STYLE='font-size:9pt'>//itk::BSplineDeformableTransform::RegionType<BR>
</SPAN></FONT></FONT><FONT SIZE="2"><SPAN STYLE='font-size:10pt'> RegionType::SizeType size; </SPAN></FONT><FONT COLOR="#007600"><FONT SIZE="1"><SPAN STYLE='font-size:9pt'>//itk::BSplineDeformableTransform::RegionType::SizeType<BR>
</SPAN></FONT></FONT><FONT SIZE="2"><SPAN STYLE='font-size:10pt'> <FONT COLOR="#BF0090">const</FONT> <FONT COLOR="#BF0090">unsigned</FONT> <FONT COLOR="#BF0090">int</FONT> numberOfGridNodesOutsideTheImageSupport = </SPAN></FONT></FONT><FONT SIZE="2"><SPAN STYLE='font-size:10pt'><FONT COLOR="#2800D4"><FONT FACE="Monaco, Courier New">3</FONT></FONT><FONT FACE="Palatino">; <BR>
<FONT COLOR="#BF0090">const</FONT> <FONT COLOR="#BF0090">unsigned</FONT> <FONT COLOR="#BF0090">int</FONT> numberOfGridNodesInsideTheImageSupportH = nH;<BR>
<FONT COLOR="#BF0090">const</FONT> <FONT COLOR="#BF0090">unsigned</FONT> <FONT COLOR="#BF0090">int</FONT> numberOfGridNodesInsideTheImageSupportW = nW;<BR>
<FONT COLOR="#BF0090">const</FONT> <FONT COLOR="#BF0090">unsigned</FONT> <FONT COLOR="#BF0090">int</FONT> numberOfGridNodesInsideTheImageSupportD = nD; <BR>
<FONT COLOR="#BF0090">const</FONT> <FONT COLOR="#BF0090">unsigned</FONT> <FONT COLOR="#BF0090">int</FONT> numberOfGridNodesH = <BR>
numberOfGridNodesInsideTheImageSupportH + <BR>
numberOfGridNodesOutsideTheImageSupport; <BR>
<FONT COLOR="#BF0090">const</FONT> <FONT COLOR="#BF0090">unsigned</FONT> <FONT COLOR="#BF0090">int</FONT> numberOfGridNodesW = <BR>
numberOfGridNodesInsideTheImageSupportW + <BR>
numberOfGridNodesOutsideTheImageSupport;<BR>
<FONT COLOR="#BF0090">const</FONT> <FONT COLOR="#BF0090">unsigned</FONT> <FONT COLOR="#BF0090">int</FONT> numberOfGridNodesD = <BR>
numberOfGridNodesInsideTheImageSupportD + <BR>
numberOfGridNodesOutsideTheImageSupport;<BR>
<BR>
<BR>
<BR>
</FONT></SPAN></FONT><FONT FACE="Palatino"><FONT COLOR="#007600"><FONT SIZE="1"><SPAN STYLE='font-size:9pt'>//We need to modify this size[0]=m_nW size[1]=m_nH<BR>
</SPAN></FONT></FONT><FONT SIZE="2"><SPAN STYLE='font-size:10pt'> </SPAN></FONT><FONT COLOR="#007600"><FONT SIZE="1"><SPAN STYLE='font-size:9pt'>//itk::BSplineDeformableTransform::RegionType::SizeType.Fill<BR>
</SPAN></FONT></FONT><FONT SIZE="2"><SPAN STYLE='font-size:10pt'> size[</SPAN></FONT></FONT><FONT SIZE="2"><SPAN STYLE='font-size:10pt'><FONT COLOR="#2800D4"><FONT FACE="Monaco, Courier New">0</FONT></FONT><FONT FACE="Palatino">]=numberOfGridNodesW;<BR>
size[</FONT><FONT COLOR="#2800D4"><FONT FACE="Monaco, Courier New">1</FONT></FONT><FONT FACE="Palatino">]=numberOfGridNodesH;<BR>
size[</FONT><FONT COLOR="#2800D4"><FONT FACE="Monaco, Courier New">2</FONT></FONT><FONT FACE="Palatino">]=numberOfGridNodesD; <BR>
bsplineRegion.SetSize( size ); </FONT></SPAN></FONT><FONT FACE="Palatino"><FONT COLOR="#007600"><FONT SIZE="1"><SPAN STYLE='font-size:9pt'>//itk::BSplineDeformableTransform::RegionType::SetSize<BR>
</SPAN></FONT></FONT><FONT SIZE="2"><SPAN STYLE='font-size:10pt'> <FONT COLOR="#BF0090">typedef</FONT> TransformType3D::SpacingType SpacingType; </SPAN></FONT><FONT COLOR="#007600"><FONT SIZE="1"><SPAN STYLE='font-size:9pt'>//itk::BSplineDeformableTransform::SpacingType<BR>
</SPAN></FONT></FONT><FONT SIZE="2"><SPAN STYLE='font-size:10pt'> SpacingType spacing; <BR>
spacing[</SPAN></FONT></FONT><FONT SIZE="2"><SPAN STYLE='font-size:10pt'><FONT COLOR="#2800D4"><FONT FACE="Monaco, Courier New">0</FONT></FONT><FONT FACE="Palatino">] = nHorSpace*fixedSpacing[</FONT><FONT COLOR="#2800D4"><FONT FACE="Monaco, Courier New">0</FONT></FONT><FONT FACE="Palatino">];</FONT></SPAN></FONT><FONT FACE="Palatino"><FONT COLOR="#007600"><FONT SIZE="1"><SPAN STYLE='font-size:9pt'>//floor( fixedSpacing[0] * (fixedSize[0] - 1) / numberOfGridCellsW ); //convert pixel spacing to metric....<BR>
</SPAN></FONT></FONT><FONT SIZE="2"><SPAN STYLE='font-size:10pt'> spacing[</SPAN></FONT></FONT><FONT SIZE="2"><SPAN STYLE='font-size:10pt'><FONT COLOR="#2800D4"><FONT FACE="Monaco, Courier New">1</FONT></FONT><FONT FACE="Palatino">] = nVerSpace*fixedSpacing[</FONT><FONT COLOR="#2800D4"><FONT FACE="Monaco, Courier New">1</FONT></FONT><FONT FACE="Palatino">];</FONT></SPAN></FONT><FONT FACE="Palatino"><FONT COLOR="#007600"><FONT SIZE="1"><SPAN STYLE='font-size:9pt'>//floor( fixedSpacing[1] * (fixedSize[1] - 1) / numberOfGridCellsH );<BR>
</SPAN></FONT></FONT><FONT SIZE="2"><SPAN STYLE='font-size:10pt'> spacing[</SPAN></FONT></FONT><FONT SIZE="2"><SPAN STYLE='font-size:10pt'><FONT COLOR="#2800D4"><FONT FACE="Monaco, Courier New">2</FONT></FONT><FONT FACE="Palatino">] = nSliSpace*fixedSpacing[</FONT><FONT COLOR="#2800D4"><FONT FACE="Monaco, Courier New">2</FONT></FONT><FONT FACE="Palatino">];</FONT></SPAN></FONT><FONT FACE="Palatino"><FONT COLOR="#007600"><FONT SIZE="1"><SPAN STYLE='font-size:9pt'>//floor( fixedSpacing[1] * (fixedSize[1] - 1) / numberOfGridCellsH );<BR>
</SPAN></FONT></FONT><FONT SIZE="2"><SPAN STYLE='font-size:10pt'> <BR>
<FONT COLOR="#BF0090">typedef</FONT> TransformType3D::OriginType OriginType; </SPAN></FONT><FONT COLOR="#007600"><FONT SIZE="1"><SPAN STYLE='font-size:9pt'>//itk::BSplineDeformableTransform::OriginType<BR>
</SPAN></FONT></FONT><FONT SIZE="2"><SPAN STYLE='font-size:10pt'> OriginType origin; <BR>
origin = fixedOrigin - fixedDirection*spacing; </SPAN></FONT><FONT COLOR="#007600"><FONT SIZE="1"><SPAN STYLE='font-size:9pt'>//due to boundary...<BR>
</SPAN></FONT></FONT><FONT SIZE="2"><SPAN STYLE='font-size:10pt'> <BR>
bsplineTransform->SetGridSpacing( spacing ); </SPAN></FONT><FONT COLOR="#007600"><FONT SIZE="1"><SPAN STYLE='font-size:9pt'>//itk::BSplineDeformableTransform->SetGridSpacing<BR>
</SPAN></FONT></FONT><FONT SIZE="2"><SPAN STYLE='font-size:10pt'> bsplineTransform->SetGridOrigin( origin ); </SPAN></FONT><FONT COLOR="#007600"><FONT SIZE="1"><SPAN STYLE='font-size:9pt'>//itk::BSplineDeformableTransform->SetGridOrigin<BR>
</SPAN></FONT></FONT><FONT SIZE="2"><SPAN STYLE='font-size:10pt'> bsplineTransform->SetGridRegion( bsplineRegion );</SPAN></FONT><FONT COLOR="#007600"><FONT SIZE="1"><SPAN STYLE='font-size:9pt'>//itk::BSplineDeformableTransform->SetGridRegion<BR>
</SPAN></FONT></FONT><FONT SIZE="2"><SPAN STYLE='font-size:10pt'> bsplineTransform->SetGridDirection( fixedDirection );<BR>
<BR>
<FONT COLOR="#BF0090">typedef</FONT> TransformType3D::ParametersType ParametersType; </SPAN></FONT><FONT COLOR="#007600"><FONT SIZE="1"><SPAN STYLE='font-size:9pt'>//itk::BSplineDeformableTransform::ParametersType<BR>
</SPAN></FONT></FONT><FONT SIZE="2"><SPAN STYLE='font-size:10pt'> <FONT COLOR="#BF0090">const</FONT> <FONT COLOR="#BF0090">unsigned</FONT> <FONT COLOR="#BF0090">int</FONT> numberOfParameters = <BR>
bsplineTransform->GetNumberOfParameters(); </SPAN></FONT><FONT COLOR="#007600"><FONT SIZE="1"><SPAN STYLE='font-size:9pt'>//itk::BSplineDeformableTransform->GetNumberOfParameters();<BR>
</SPAN></FONT></FONT><FONT SIZE="2"><SPAN STYLE='font-size:10pt'> <FONT COLOR="#BF0090">const</FONT> <FONT COLOR="#BF0090">unsigned</FONT> <FONT COLOR="#BF0090">int</FONT> numberOfNodes = numberOfParameters / ImageDimension; <BR>
ParametersType parameters( numberOfParameters );<BR>
<BR>
</SPAN></FONT><FONT COLOR="#007600"><FONT SIZE="1"><SPAN STYLE='font-size:9pt'>/*<BR>
The B-spline grid should now be fed with coeficients at each node. Since this is a two dimen- <BR>
sional grid, each node should receive two coefficients. Each coefficient pair is representing a <BR>
displacement vector at this node. The coefficients can be passed to the B-spline in the form of <BR>
an array where the first set of elements are the first component of the displacements for all the <BR>
nodes, and the second set of elemets is formed by the second component of the displacements <BR>
for all the nodes. <BR>
In this example we read such displacements from a file, but for convinience we have written this <BR>
file using the pairs of (x, y) displacement for every node. The elements read from the file should <BR>
therefore be reorganized when assigned to the elements of the array. We do this by storing all <BR>
the odd elements from the file in the first block of the array, and all the even elements from the <BR>
file in the second block of the array. Finally the array is passed to the B-spline transform using <BR>
the SetParameters(). */<BR>
</SPAN></FONT></FONT><FONT SIZE="2"><SPAN STYLE='font-size:10pt'> <BR>
<FONT COLOR="#BF0090">int</FONT> nPos=</SPAN></FONT></FONT><FONT SIZE="2"><SPAN STYLE='font-size:10pt'><FONT COLOR="#2800D4"><FONT FACE="Monaco, Courier New">0</FONT></FONT><FONT FACE="Palatino">;<BR>
<FONT COLOR="#BF0090">for</FONT>(<FONT COLOR="#BF0090">int</FONT> z=-</FONT><FONT COLOR="#2800D4"><FONT FACE="Monaco, Courier New">1</FONT></FONT><FONT FACE="Palatino">;z<nD+</FONT><FONT COLOR="#2800D4"><FONT FACE="Monaco, Courier New">2</FONT></FONT><FONT FACE="Palatino">;z++)<BR>
{<BR>
<FONT COLOR="#BF0090">for</FONT>(<FONT COLOR="#BF0090">int</FONT> y=-</FONT><FONT COLOR="#2800D4"><FONT FACE="Monaco, Courier New">1</FONT></FONT><FONT FACE="Palatino">;y<nH+</FONT><FONT COLOR="#2800D4"><FONT FACE="Monaco, Courier New">2</FONT></FONT><FONT FACE="Palatino">;y++)<BR>
{<BR>
<FONT COLOR="#BF0090">for</FONT>(<FONT COLOR="#BF0090">int</FONT> x=-</FONT><FONT COLOR="#2800D4"><FONT FACE="Monaco, Courier New">1</FONT></FONT><FONT FACE="Palatino">;x<nW+</FONT><FONT COLOR="#2800D4"><FONT FACE="Monaco, Courier New">2</FONT></FONT><FONT FACE="Palatino">;x++)<BR>
{<BR>
<FONT COLOR="#BF0090">if</FONT>(z>=</FONT><FONT COLOR="#2800D4"><FONT FACE="Monaco, Courier New">0</FONT></FONT><FONT FACE="Palatino"> &&z< nD && y>=</FONT><FONT COLOR="#2800D4"><FONT FACE="Monaco, Courier New">0</FONT></FONT><FONT FACE="Palatino"> && y< nH && x>=</FONT><FONT COLOR="#2800D4"><FONT FACE="Monaco, Courier New">0</FONT></FONT><FONT FACE="Palatino"> && x<nW)<BR>
{<BR>
parameters[nPos]=disVector[z*nW*nH+y*nW+x].x;<BR>
parameters[nPos+numberOfNodes]=disVector[z*nW*nH+y*nW+x].y;<BR>
parameters[nPos+numberOfNodes*</FONT><FONT COLOR="#2800D4"><FONT FACE="Monaco, Courier New">2</FONT></FONT><FONT FACE="Palatino">]=disVector[z*nW*nH+y*nW+x].z;<BR>
}<BR>
<FONT COLOR="#BF0090">else<BR>
</FONT> {<BR>
parameters[nPos]=</FONT><FONT COLOR="#2800D4"><FONT FACE="Monaco, Courier New">0</FONT></FONT><FONT FACE="Palatino">;</FONT></SPAN></FONT><FONT FACE="Palatino"><FONT COLOR="#007600"><FONT SIZE="1"><SPAN STYLE='font-size:9pt'>//disVector[y*nW+x].x;<BR>
</SPAN></FONT></FONT><FONT SIZE="2"><SPAN STYLE='font-size:10pt'> parameters[nPos+numberOfNodes]=</SPAN></FONT></FONT><FONT SIZE="2"><SPAN STYLE='font-size:10pt'><FONT COLOR="#2800D4"><FONT FACE="Monaco, Courier New">0</FONT></FONT><FONT FACE="Palatino">;</FONT></SPAN></FONT><FONT FACE="Palatino"><FONT COLOR="#007600"><FONT SIZE="1"><SPAN STYLE='font-size:9pt'>//disVector[y*nW+x].y;<BR>
</SPAN></FONT></FONT><FONT SIZE="2"><SPAN STYLE='font-size:10pt'> parameters[nPos+numberOfNodes*</SPAN></FONT></FONT><FONT SIZE="2"><SPAN STYLE='font-size:10pt'><FONT COLOR="#2800D4"><FONT FACE="Monaco, Courier New">2</FONT></FONT><FONT FACE="Palatino">]=</FONT><FONT COLOR="#2800D4"><FONT FACE="Monaco, Courier New">0</FONT></FONT><FONT FACE="Palatino">;<BR>
}<BR>
nPos++;<BR>
}<BR>
}<BR>
}<BR>
bsplineTransform->SetParameters( parameters ); <BR>
<BR>
resampler->SetDefaultPixelValue(</FONT><FONT COLOR="#2800D4"><FONT FACE="Monaco, Courier New">0</FONT></FONT><FONT FACE="Palatino">);<BR>
resampler->SetTransform( bsplineTransform ); <BR>
<FONT COLOR="#BF0090">try</FONT> <BR>
{ <BR>
movingWriter->Update(); <BR>
} <BR>
<FONT COLOR="#BF0090">catch</FONT>( itk::ExceptionObject & excp ) <BR>
{ <BR>
std::cerr << </FONT></SPAN></FONT><FONT COLOR="#DB0500"><FONT SIZE="1"><FONT FACE="Monaco, Courier New"><SPAN STYLE='font-size:9pt'>"Exception thrown "</SPAN></FONT></FONT></FONT><FONT SIZE="2"><FONT FACE="Palatino"><SPAN STYLE='font-size:10pt'> << std::endl; <BR>
std::cerr << excp << std::endl; <BR>
<FONT COLOR="#BF0090">return</FONT> EXIT_FAILURE; <BR>
}<BR>
<BR>
</SPAN></FONT></FONT><FONT FACE="Palatino"><FONT COLOR="#007600"><FONT SIZE="1"><SPAN STYLE='font-size:9pt'>//We just transform segmentation image to evaluate.....<BR>
</SPAN></FONT></FONT><FONT SIZE="2"><SPAN STYLE='font-size:10pt'> <FONT COLOR="#BF0090">if</FONT>(m_strSegPath!=</SPAN></FONT></FONT><FONT COLOR="#DB0500"><FONT SIZE="1"><FONT FACE="Monaco, Courier New"><SPAN STYLE='font-size:9pt'>""</SPAN></FONT></FONT></FONT><FONT SIZE="2"><FONT FACE="Palatino"><SPAN STYLE='font-size:10pt'>)<BR>
{<BR>
<FONT COLOR="#BF0090">if</FONT>(nLevel==</SPAN></FONT><SPAN STYLE='font-size:10pt'><FONT COLOR="#2800D4"><FONT FACE="Monaco, Courier New">0</FONT></FONT><FONT FACE="Palatino">)<BR>
{</FONT></SPAN></FONT><FONT FACE="Palatino"><FONT COLOR="#007600"><FONT SIZE="1"><SPAN STYLE='font-size:9pt'>//input is fixed segmentation image...<BR>
</SPAN></FONT></FONT><FONT SIZE="2"><SPAN STYLE='font-size:10pt'> ITK_IMG_READER_TYPE3D::Pointer seg_reader=ITK_IMG_READER_TYPE3D::New();<BR>
seg_reader->SetFileName(m_strSegPath);<BR>
<BR>
</SPAN></FONT><FONT COLOR="#007600"><FONT SIZE="1"><SPAN STYLE='font-size:9pt'>//we first compute maximum and minimum of the label...and remember it....<BR>
</SPAN></FONT></FONT><FONT SIZE="2"><SPAN STYLE='font-size:10pt'> <FONT COLOR="#BF0090">typedef</FONT> itk::MinimumMaximumImageCalculator<ITKIMAGE3D> calType;<BR>
calType::Pointer cal=calType::New();<BR>
cal->SetImage(seg_reader->GetOutput());<BR>
seg_reader->Update();<BR>
cal->ComputeMaximum();<BR>
cal->ComputeMinimum();<BR>
ITKIMAGE3D::PixelType maxval=cal->GetMaximum();<BR>
ITKIMAGE3D::PixelType minval=cal->GetMinimum();<BR>
<BR>
<BR>
<FONT COLOR="#BF0090">typedef</FONT> itk::RescaleIntensityImageFilter< <BR>
ITKIMAGE3D, ITKIMAGE3D> RescaleFilterType;<BR>
RescaleFilterType::Pointer enlarge_rescaler = RescaleFilterType::New();<BR>
//This rescaler was used to avoid interpolation ambiguity between adjacent labels.<BR>
// in hope for avoiding salt and pepper like noise....<BR>
enlarge_rescaler->SetOutputMinimum( </SPAN></FONT></FONT><FONT SIZE="2"><SPAN STYLE='font-size:10pt'><FONT COLOR="#2800D4"><FONT FACE="Monaco, Courier New">0</FONT></FONT><FONT FACE="Palatino"> );<BR>
enlarge_rescaler->SetOutputMaximum( </FONT><FONT COLOR="#2800D4"><FONT FACE="Monaco, Courier New">30000</FONT></FONT><FONT FACE="Palatino"> );<BR>
enlarge_rescaler->SetInput(seg_reader->GetOutput());<BR>
<BR>
resampler->SetInput(enlarge_rescaler->GetOutput());<BR>
ITK_IMG_WRITER_TYPE3D::Pointer seg_writer=ITK_IMG_WRITER_TYPE3D::New();<BR>
QString strFileName;<BR>
strFileName.sprintf(</FONT></SPAN></FONT><FONT COLOR="#DB0500"><FONT SIZE="1"><FONT FACE="Monaco, Courier New"><SPAN STYLE='font-size:9pt'>"%s%s_seg_deformed%.2d.hdr"</SPAN></FONT></FONT></FONT><FONT SIZE="2"><FONT FACE="Palatino"><SPAN STYLE='font-size:10pt'>,qPrintable(m_strOutPath),qPrintable(m_strFileName),nLevel);<BR>
seg_writer->SetFileName(strFileName);<BR>
<BR>
RescaleFilterType::Pointer shorten_rescaler = RescaleFilterType::New();<BR>
<BR>
shorten_rescaler->SetOutputMinimum(minval);<BR>
shorten_rescaler->SetOutputMaximum(maxval);<BR>
shorten_rescaler->SetInput(resampler->GetOutput());<BR>
seg_writer->SetInput(shorten_rescaler->GetOutput());<BR>
seg_writer->Update();<BR>
}<BR>
<FONT COLOR="#BF0090">else<BR>
</FONT> {</SPAN></FONT></FONT><FONT FACE="Palatino"><FONT COLOR="#007600"><FONT SIZE="1"><SPAN STYLE='font-size:9pt'>//input is transformed segmentation image....<BR>
</SPAN></FONT></FONT><FONT SIZE="2"><SPAN STYLE='font-size:10pt'> QString strFileName;<BR>
strFileName.sprintf(</SPAN></FONT></FONT><FONT COLOR="#DB0500"><FONT SIZE="1"><FONT FACE="Monaco, Courier New"><SPAN STYLE='font-size:9pt'>"%s%s_seg_deformed%.2d.hdr"</SPAN></FONT></FONT></FONT><FONT SIZE="2"><FONT FACE="Palatino"><SPAN STYLE='font-size:10pt'>,qPrintable(m_strOutPath),qPrintable(m_strFileName),nLevel-</SPAN></FONT><SPAN STYLE='font-size:10pt'><FONT COLOR="#2800D4"><FONT FACE="Monaco, Courier New">1</FONT></FONT><FONT FACE="Palatino">);<BR>
<BR>
ITK_IMG_READER_TYPE3D::Pointer seg_reader=ITK_IMG_READER_TYPE3D::New();<BR>
<BR>
</FONT></SPAN></FONT><FONT FACE="Palatino"><FONT COLOR="#007600"><FONT SIZE="1"><SPAN STYLE='font-size:9pt'>//we first compute maximum and minimum of the label...and remember it....<BR>
</SPAN></FONT></FONT><FONT SIZE="2"><SPAN STYLE='font-size:10pt'> <FONT COLOR="#BF0090">typedef</FONT> itk::MinimumMaximumImageCalculator<ITKIMAGE3D> calType;<BR>
calType::Pointer cal=calType::New();<BR>
cal->SetImage(seg_reader->GetOutput());<BR>
seg_reader->Update();<BR>
cal->ComputeMaximum();<BR>
cal->ComputeMinimum();<BR>
ITKIMAGE3D::PixelType maxval=cal->GetMaximum();<BR>
ITKIMAGE3D::PixelType minval=cal->GetMinimum();<BR>
<BR>
<BR>
<FONT COLOR="#BF0090">typedef</FONT> itk::RescaleIntensityImageFilter< <BR>
ITKIMAGE3D, ITKIMAGE3D> RescaleFilterType;<BR>
RescaleFilterType::Pointer enlarge_rescaler = RescaleFilterType::New();<BR>
<BR>
enlarge_rescaler->SetOutputMinimum( </SPAN></FONT></FONT><FONT SIZE="2"><SPAN STYLE='font-size:10pt'><FONT COLOR="#2800D4"><FONT FACE="Monaco, Courier New">0</FONT></FONT><FONT FACE="Palatino"> );<BR>
enlarge_rescaler->SetOutputMaximum( </FONT><FONT COLOR="#2800D4"><FONT FACE="Monaco, Courier New">30000</FONT></FONT><FONT FACE="Palatino"> );<BR>
enlarge_rescaler->SetInput(seg_reader->GetOutput());<BR>
<BR>
resampler->SetInput(enlarge_rescaler->GetOutput());<BR>
<BR>
seg_reader->SetFileName(strFileName);<BR>
<BR>
ITK_IMG_WRITER_TYPE3D::Pointer seg_writer=ITK_IMG_WRITER_TYPE3D::New();<BR>
strFileName.sprintf(</FONT></SPAN></FONT><FONT COLOR="#DB0500"><FONT SIZE="1"><FONT FACE="Monaco, Courier New"><SPAN STYLE='font-size:9pt'>"%s%s_seg_deformed%.2d.hdr"</SPAN></FONT></FONT></FONT><FONT SIZE="2"><FONT FACE="Palatino"><SPAN STYLE='font-size:10pt'>,qPrintable(m_strOutPath),qPrintable(m_strFileName),nLevel);<BR>
seg_writer->SetFileName(strFileName);<BR>
<BR>
RescaleFilterType::Pointer shorten_rescaler = RescaleFilterType::New();<BR>
<BR>
shorten_rescaler->SetOutputMinimum(minval);<BR>
shorten_rescaler->SetOutputMaximum(maxval);<BR>
shorten_rescaler->SetInput(resampler->GetOutput());<BR>
seg_writer->SetInput(shorten_rescaler->GetOutput());<BR>
seg_writer->Update();<BR>
}<BR>
}</SPAN></FONT><SPAN STYLE='font-size:10pt'><FONT FACE="Calibri, Verdana, Helvetica, Arial"> </FONT></SPAN></FONT><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
</SPAN></FONT>
</BODY>
</HTML>