📄 itkregiongrow2dtest.cxx
字号:
KLMFilter->SetMaximumLambda( 1e51 );
LOCAL_TEST_EXCEPTION_MACRO( KLMFilter );
if( KLMFilter->GetNumberOfRegions() !=
KLMFilter->GetMaximumNumberOfRegions() )
{
std::cout << "Test FAILED" << std::endl;
return EXIT_FAILURE;
}
// Test the functions useful to test the region and border statistics
// as the regions are merged. Primarily useful for debug operations and are
// called several times, so prudent usage is advisable.
KLMFilter->PrintAlgorithmRegionStats();
// KLMFilter->PrintAlgorithmBorderStats();
std::cout << "Extracting and checking approximation image" << std::endl;
std::cout << "Extracting and checking label image" << std::endl;
OutputImageType::Pointer outImage2 = KLMFilter->GetOutput();
OutputImageIterator outIt2( outImage2, outImage2->GetBufferedRegion() );
OutputImageIterator outItEnd2 = outIt2.End();
OutputImageData pixelOut2a;
OutputImageData pixelOut2b;
LabelledImageType::Pointer labelledImage2 = KLMFilter->GetLabelledImage();
LabelImageIterator labelIt2( labelledImage2,
labelledImage2->GetBufferedRegion() );
pixelOut2a[0] = (numPixelsHalf-1)*numPixelsHalf/2;
pixelOut2a[1] = (numPixels-1)*numPixels/2 - pixelOut2a[0];
pixelOut2a[0] /= numPixelsHalf;
pixelOut2a[1] /= numPixelsHalf;
pixelOut2a[2] = 47;
pixelOut2b[0] = pixelOut2a[1];
pixelOut2b[1] = pixelOut2a[0];
pixelOut2b[2] = 247;
LabelType ma = 1;
LabelType mb = 2;
k = 0;
while ( outIt2 != outItEnd2 )
{
pixelOut = outIt2.Get();
pixelLabel = labelIt2.Get();
if ( k < numPixelsHalf )
{
if ( pixelOut != pixelOut2a || pixelLabel != ma )
{
std::cout << "Test FAILED" << std::endl;
if ( pixelLabel != ma)
{
std::cout << "pixelLabel: " << pixelLabel
<< " != "
<< "ma: " << ma
<< std::endl;
}
if ( pixelOut != pixelOut2a)
{
std::cout << "pixelOut: " << pixelOut
<< " != "
<< "pixelOut2a: " << pixelOut2a
<< std::endl;
}
return EXIT_FAILURE;
}
}
else
{
if ( pixelOut != pixelOut2b || pixelLabel != mb )
{
std::cout << "Test FAILED" << std::endl;
if ( pixelLabel != ma)
{
std::cout << "pixelLabel: " << pixelLabel
<< " != "
<< "mb: " << mb
<< std::endl;
}
if ( pixelOut != pixelOut2b)
{
std::cout << "pixelOut: " << pixelOut
<< " != "
<< "pixelOut2b: " << pixelOut2b
<< std::endl;
}
return EXIT_FAILURE;
}
}
++outIt2;
++labelIt2;
++k;
} //end while iterator loop
std::cout << "Test PASSED" << std::endl;
KLMFilter->ResetPipeline();
// THIRD TEST:
// merge to 4 regions
nregions = 4;
std::cout << std::endl << "Third test, merge to " << nregions <<
" regions" << std::endl;
unsigned int numPixelsQtr = numPixelsHalf / 2;
k = 0;
inIt.GoToBegin();
while ( inIt != inItEnd ) {
pixelData[0] = static_cast<unsigned char>( k );
pixelData[1] = static_cast<unsigned char>( numPixels - k - 1 );
if ( k < numPixelsQtr ) pixelData[2] = 127;
else if ( k < 2 * numPixelsQtr ) pixelData[2] = 27;
else if ( k < 3 * numPixelsQtr ) pixelData[2] = 127;
else pixelData[2] = 227;
inIt.Set( pixelData );
++inIt;
++k;
}
KLMFilter->SetMaximumLambda( 1e51 );
KLMFilter->SetMaximumNumberOfRegions( nregions );
LOCAL_TEST_EXCEPTION_MACRO( KLMFilter );
if( KLMFilter->GetNumberOfRegions() !=
KLMFilter->GetMaximumNumberOfRegions() )
{
std::cout << "Test FAILED" << std::endl;
return EXIT_FAILURE;
}
// Test the functions useful to test the region and border statistics
// as the regions are merged. Primarily useful for debug operations and are
// called several times, so prudent usage is advisable.
KLMFilter->PrintAlgorithmRegionStats();
// KLMFilter->PrintAlgorithmBorderStats();
std::cout << "Extracting and checking approximation image" << std::endl;
std::cout << "Extracting and checking label image" << std::endl;
OutputImageType::Pointer outImage3 = KLMFilter->GetOutput();
OutputImageIterator outIt3( outImage3, outImage3->GetBufferedRegion() );
OutputImageIterator outItEnd3 = outIt3.End();
OutputImageData pixelOut3a;
OutputImageData pixelOut3b;
OutputImageData pixelOut3c;
OutputImageData pixelOut3d;
LabelledImageType::Pointer labelledImage3 = KLMFilter->GetLabelledImage();
LabelImageIterator labelIt3( labelledImage3,
labelledImage3->GetBufferedRegion() );
pixelOut3a[0] = (numPixelsQtr - 1) * numPixelsQtr / 2;
pixelOut3a[1] = (numPixels - 1) * numPixels / 2 -
(3 * numPixelsQtr - 1) * (3 * numPixelsQtr) / 2;
pixelOut3a[0] /= numPixelsQtr;
pixelOut3a[1] /= numPixelsQtr;
pixelOut3a[2] = 127;
pixelOut3b[0] = (numPixelsHalf - 1) * numPixelsHalf / 2 -
(numPixelsQtr - 1) * numPixelsQtr / 2;
pixelOut3b[1] = (3 * numPixelsQtr - 1) * (3 * numPixelsQtr) / 2 -
(numPixelsHalf - 1) * numPixelsHalf / 2;
pixelOut3b[0] /= numPixelsQtr;
pixelOut3b[1] /= numPixelsQtr;
pixelOut3b[2] = 27;
pixelOut3c[0] = pixelOut3b[1];
pixelOut3c[1] = pixelOut3b[0];
pixelOut3c[2] = 127;
pixelOut3d[0] = pixelOut3a[1];
pixelOut3d[1] = pixelOut3a[0];
pixelOut3d[2] = 227;
LabelType mc = 3;
LabelType md = 4;
k = 0;
while ( outIt3 != outItEnd3 )
{
pixelOut = outIt3.Get();
pixelLabel = labelIt3.Get();
if ( k < numPixelsHalf / 2 )
{
if ( pixelOut != pixelOut3a || pixelLabel != ma )
{
std::cout << "Test FAILED" << std::endl;
if ( pixelLabel != ma)
{
std::cout << "pixelLabel: " << pixelLabel
<< " != "
<< "ma: " << ma
<< std::endl;
}
if ( pixelOut != pixelOut3a)
{
std::cout << "pixelOut: " << pixelOut
<< " != "
<< "pixelOut3a: " << pixelOut3a
<< std::endl;
}
return EXIT_FAILURE;
}
}
else if ( k < numPixelsHalf )
{
if ( pixelOut != pixelOut3b || pixelLabel != mb )
{
std::cout << "Test FAILED" << std::endl;
if ( pixelLabel != mb)
{
std::cout << "pixelLabel: " << pixelLabel
<< " != "
<< "mb: " << mb
<< std::endl;
}
if ( pixelOut != pixelOut3b)
{
std::cout << "pixelOut: " << pixelOut
<< " != "
<< "pixelOut3b: " << pixelOut3b
<< std::endl;
}
return EXIT_FAILURE;
}
}
else if ( k < 3 * numPixelsHalf / 2 )
{
if ( pixelOut != pixelOut3c || pixelLabel != mc )
{
std::cout << "Test FAILED" << std::endl;
if ( pixelLabel != ma)
{
std::cout << "pixelLabel: " << pixelLabel
<< " != "
<< "mc: " << mc
<< std::endl;
}
if ( pixelOut != pixelOut3c)
{
std::cout << "pixelOut: " << pixelOut
<< " != "
<< "pixelOut3c: " << pixelOut3c
<< std::endl;
}
return EXIT_FAILURE;
}
}
else
{
if ( pixelOut != pixelOut3d || pixelLabel != md )
{
std::cout << "Test FAILED" << std::endl;
if ( pixelLabel != md)
{
std::cout << "pixelLabel: " << pixelLabel
<< " != "
<< "md: " << md
<< std::endl;
}
if ( pixelOut != pixelOut3d)
{
std::cout << "pixelOut: " << pixelOut
<< " != "
<< "pixelOut3d: " << pixelOut3d
<< std::endl;
}
return EXIT_FAILURE;
}
}
++outIt3;
++labelIt3;
++k;
} //end while iterator loop
std::cout << "Test PASSED" << std::endl;
KLMFilter->ResetPipeline();
// FOURTH TEST:
// set image spacing
std::cout << std::endl << "Fourth test, spacing set to 0.25: "
<< "area of final regions should be 1 as seen in printed region stats"
<< std::endl;
ImageType::SpacingType spacing = image->GetSpacing();
spacing.Fill(.04);
image->SetSpacing(spacing);
LOCAL_TEST_EXCEPTION_MACRO( KLMFilter );
if( KLMFilter->GetNumberOfRegions() !=
KLMFilter->GetMaximumNumberOfRegions() )
{
std::cout << "Test FAILED" << std::endl;
return EXIT_FAILURE;
}
// Test the functions useful to test the region and border statistics
// as the regions are merged. Primarily useful for debug operations and are
// called several times, so prudent usage is advisable.
KLMFilter->PrintAlgorithmRegionStats();
// KLMFilter->PrintAlgorithmBorderStats();
std::cout << "Test PASSED" << std::endl;
KLMFilter->ResetPipeline();
// FIFTH TEST:
// large gridsize no merging
int gridWidth = 5;
gridSize.Fill(gridWidth);
std::cout << std::endl << "Fifth test, gridSize = "
<< gridWidth << " no merging" << std::endl;
KLMFilter->SetMaximumLambda( -1 );
KLMFilter->SetGridSize(gridSize);
LOCAL_TEST_EXCEPTION_MACRO( KLMFilter );
if( KLMFilter->GetNumberOfRegions() != numPixels / gridWidth )
{
std::cout << "Test FAILED" << std::endl;
return EXIT_FAILURE;
}
// Test the functions useful to test the region and border statistics
// as the regions are merged. Primarily useful for debug operations and are
// called several times, so prudent usage is advisable.
KLMFilter->PrintAlgorithmRegionStats();
// KLMFilter->PrintAlgorithmBorderStats();
std::cout << "Extracting and checking approximation image" << std::endl;
std::cout << "Extracting and checking label image" << std::endl;
OutputImageType::Pointer outImage5 = KLMFilter->GetOutput();
OutputImageIterator outIt5( outImage5, outImage5->GetBufferedRegion() );
OutputImageIterator outItEnd5 = outIt5.End();
LabelledImageType::Pointer labelledImage5 = KLMFilter->GetLabelledImage();
LabelImageIterator labelIt5( labelledImage5,
labelledImage5->GetBufferedRegion() );
OutputImageData pixelOut5in;
OutputImageData pixelOut5out;
k = 1;
inIt.GoToBegin();
while ( outIt5 != outItEnd5 )
{
pixelOut5in[0] = 0;
pixelOut5in[1] = 0;
pixelOut5in[2] = 0;
for ( int idx = 0; idx < gridWidth; idx++ )
{
pixelIn = inIt.Get();
pixelOut5in[0] += pixelIn[0];
pixelOut5in[1] += pixelIn[1];
pixelOut5in[2] += pixelIn[2];
pixelLabel = labelIt5.Get();
if ( pixelLabel != k )
{
std::cout << "Test FAILED" << std::endl;
std::cout << "pixelLabel: " << pixelLabel
<< " != "
<< "k : " << k
<< std::endl;
return EXIT_FAILURE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -