namespace
{
}
static void CreateImage(UnsignedCharImageType::Pointer image);
static void CreateHalfMask(UnsignedCharImageType::Pointer image, UnsignedCharImageType::Pointer mask);
int main(int, char *[])
{
UnsignedCharImageType::Pointer image = UnsignedCharImageType::New();
CreateImage(image);
UnsignedCharImageType::Pointer mask = UnsignedCharImageType::New();
CreateHalfMask(image, mask);
SobelOperatorType sobelOperator;
sobelOperator.SetDirection(0);
sobelOperator.CreateToRadius(radius);
MaskNeighborhoodOperatorImageFilterType::Pointer maskNeighborhoodOperatorImageFilter =
MaskNeighborhoodOperatorImageFilterType::New();
maskNeighborhoodOperatorImageFilter->SetInput(image);
maskNeighborhoodOperatorImageFilter->SetMaskImage(mask);
maskNeighborhoodOperatorImageFilter->SetOperator(sobelOperator);
maskNeighborhoodOperatorImageFilter->Update();
RescaleFilterType::Pointer rescaleFilter = RescaleFilterType::New();
rescaleFilter->SetInput(maskNeighborhoodOperatorImageFilter->GetOutput());
rescaleFilter->Update();
WriterType::Pointer writer = WriterType::New();
writer->SetFileName("output.png");
writer->SetInput(rescaleFilter->GetOutput());
writer->Update();
return EXIT_SUCCESS;
}
void CreateHalfMask(UnsignedCharImageType::Pointer image, UnsignedCharImageType::Pointer mask)
{
mask->SetRegions(region);
mask->Allocate();
mask->FillBuffer(0);
while(!imageIterator.IsAtEnd())
{
if(static_cast<unsigned int>(imageIterator.GetIndex()[0]) > regionSize[0] / 2)
{
imageIterator.Set(0);
}
else
{
imageIterator.Set(1);
}
++imageIterator;
}
RescaleFilterType::Pointer rescaleFilter = RescaleFilterType::New();
rescaleFilter->SetInput(mask);
rescaleFilter->Update();
WriterType::Pointer writer = WriterType::New();
writer->SetFileName("mask.png");
writer->SetInput(rescaleFilter->GetOutput());
writer->Update();
}
void CreateImage(UnsignedCharImageType::Pointer image)
{
image->SetRegions(region);
image->Allocate();
image->FillBuffer(0);
for(unsigned int r = 30; r < 70; r++)
{
for(unsigned int c = 30; c < 70; c++)
{
FloatImageType::IndexType pixelIndex;
pixelIndex[0] = r;
pixelIndex[1] = c;
image->SetPixel(pixelIndex, 255);
}
}
WriterType::Pointer writer = WriterType::New();
writer->SetFileName("input.png");
writer->SetInput(image);
writer->Update();
}