#include "itkPointSet.h"
#include "itkVariableLengthVector.h"
#include "itkRGBPixel.h"
#include "itkImageRegionIterator.h"
#include <iostream>
#include <fstream>
int main(
int argc,
char* argv[])
{
if (argc != 4)
{
std::cerr << "Usage: " << argv[0];
std::cerr << " InputImage OutputImage scales" << std::endl;
return 1;
}
const char* infname = argv[1];
const char* outputImageFilename = argv[2];
const unsigned int scales = atoi(argv[3]);
const unsigned int Dimension = 2;
using RealType = float;
using RealVectorType = itk::VariableLengthVector<RealType>;
using PointSetType = itk::PointSet<RealVectorType, Dimension>;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(infname);
ImageToFastSIFTKeyPointSetFilterType::Pointer filter = ImageToFastSIFTKeyPointSetFilterType::New();
filter->SetInput(reader->GetOutput());
filter->SetScalesNumber(scales);
filter->Update();
using PixelType = unsigned char;
using RGBPixelType = itk::RGBPixel<PixelType>;
OutputImageType::Pointer outputImage = OutputImageType::New();
outputImage->SetRegions(reader->GetOutput()->GetLargestPossibleRegion());
outputImage->Allocate();
itk::ImageRegionIterator<OutputImageType> iterOutput(outputImage, outputImage->GetLargestPossibleRegion());
itk::ImageRegionIterator<ImageType> iterInput(reader->GetOutput(), reader->GetOutput()->GetLargestPossibleRegion());
for (iterOutput.GoToBegin(), iterInput.GoToBegin(); !iterOutput.IsAtEnd(); ++iterOutput, ++iterInput)
{
OutputImageType::PixelType rgbPixel;
rgbPixel.SetRed(static_cast<PixelType>(iterInput.Get()));
rgbPixel.SetGreen(static_cast<PixelType>(iterInput.Get()));
rgbPixel.SetBlue(static_cast<PixelType>(iterInput.Get()));
iterOutput.Set(rgbPixel);
}
ImageType::OffsetType t = {{0, 1}};
ImageType::OffsetType b = {{0, -1}};
ImageType::OffsetType l = {{1, 0}};
ImageType::OffsetType r = {{-1, 0}};
using PointsContainerType = PointSetType::PointsContainer;
using PointsIteratorType = PointsContainerType::Iterator;
PointsIteratorType pIt = filter->GetOutput()->GetPoints()->Begin();
ImageType::SpacingType spacing = reader->GetOutput()->GetSignedSpacing();
ImageType::PointType origin = reader->GetOutput()->GetOrigin();
while (pIt != filter->GetOutput()->GetPoints()->End())
{
ImageType::IndexType index;
index[0] = static_cast<unsigned int>(std::floor(static_cast<double>((pIt.Value()[0] - origin[0]) / spacing[0] + 0.5)));
index[1] = static_cast<unsigned int>(std::floor(static_cast<double>((pIt.Value()[1] - origin[1]) / spacing[1] + 0.5)));
OutputImageType::PixelType keyPixel;
keyPixel.SetRed(0);
keyPixel.SetGreen(255);
keyPixel.SetBlue(0);
if (outputImage->GetLargestPossibleRegion().IsInside(index))
{
outputImage->SetPixel(index, keyPixel);
if (outputImage->GetLargestPossibleRegion().IsInside(index + t))
outputImage->SetPixel(index + t, keyPixel);
if (outputImage->GetLargestPossibleRegion().IsInside(index + b))
outputImage->SetPixel(index + b, keyPixel);
if (outputImage->GetLargestPossibleRegion().IsInside(index + l))
outputImage->SetPixel(index + l, keyPixel);
if (outputImage->GetLargestPossibleRegion().IsInside(index + r))
outputImage->SetPixel(index + r, keyPixel);
}
++pIt;
}
WriterType::Pointer writer = WriterType::New();
writer->SetFileName(outputImageFilename);
writer->SetInput(outputImage);
writer->Update();
return EXIT_SUCCESS;
}