#include "itksys/SystemTools.hxx"
static void CreateImage(ImageType::Pointer image);
int main(int argc, char *argv[])
{
ImageType::Pointer image = ImageType::New();
std::stringstream desc;
if (argc > 1)
{
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( argv[1] );
if (argc > 2)
{
cropSize[0] = atoi(argv[2]);
cropSize[1] = atoi(argv[3]);
}
reader->Update();
image = reader->GetOutput();
desc << itksys::SystemTools::GetFilenameName(argv[1]);
}
else
{
CreateImage(image);
cropSize[0] = 10;
cropSize[1] = 14;
desc << "Synthetic image";
}
CropImageFilterType::Pointer cropFilter
= CropImageFilterType::New();
cropFilter->SetInput(image);
cropFilter->SetBoundaryCropSize(cropSize);
image.GetPointer(),
true,
desc.str());
std::stringstream desc2;
desc2 << "CropImageFilter, crop size = {"
<< cropSize[0] << ", " << cropSize[1] << "}";
cropFilter->GetOutput(),
true,
desc2.str());
return EXIT_SUCCESS;
}
void CreateImage(ImageType::Pointer image)
{
start[0] = 0;
start[1] = 0;
unsigned int NumRows = 200;
unsigned int NumCols = 300;
size[0] = NumRows;
size[1] = NumCols;
region.SetIndex(start);
image->SetRegions(region);
image->Allocate();
image->FillBuffer( itk::NumericTraits<ImageType::PixelType>::Zero);
for(unsigned int r = 20; r < 180; r++)
{
for(unsigned int c = 30; c < 270; c++)
{
pixelIndex[0] = r;
pixelIndex[1] = c;
image->SetPixel(pixelIndex, 200);
}
}
}