#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;
bool
ConvertImage(const std::string & inputFile, const std::string & outputFile, unsigned int newWidth = 0)
{
try
{
if (imageSize.size() == 3 && imageSize[2] == 1)
{
imageSize[2] = 0;
image = extractFilter.
Execute(image);
}
if (newWidth > 0)
{
auto originalSize = image.GetSize();
auto originalSpacing = image.GetSpacing();
double newSpacing = ((originalSize[0] - 1) * originalSpacing[0]) / (newWidth - 1);
unsigned int newHeight = static_cast<unsigned int>(((originalSize[1] - 1) * originalSpacing[1]) / newSpacing);
{ newWidth, newHeight },
image.GetOrigin(),
{ newSpacing, newSpacing },
image.GetDirection(),
0,
image.GetPixelID());
}
if (image.GetNumberOfComponentsPerPixel() == 1)
{
}
return true;
}
catch (...)
{
return false;
}
}
int
main(int argc, char * argv[])
{
if (argc < 3)
{
std::cout << "Usage: DicomConvert <input_file> <output_file> [--w width]\n";
return 1;
}
std::string inputFile = argv[1];
std::string outputFile = argv[2];
int width = 0;
for (int i = 3; i < argc; ++i)
{
if (std::string(argv[i]) == "--w" && i + 1 < argc)
{
width = std::stoi(argv[++i]);
}
}
if (ConvertImage(inputFile, outputFile, width))
{
return 0;
}
return 1;
}
Read an image file and return a SimpleITK Image.
void SetFileName(const PathType &fn)
virtual void SetImageIO(const std::string &imageio)
Set/Get name of ImageIO to use.
std::vector< unsigned int > GetSize() const
@ sitkLinear
N-D linear interpolation.
SITKBasicFilters_EXPORT Image Resample(const Image &image1, Transform transform=itk::simple::Transform(), InterpolatorEnum interpolator=itk::simple::sitkLinear, double defaultPixelValue=0.0, PixelIDValueEnum outputPixelType=sitkUnknown, bool useNearestNeighborExtrapolator=false)
itk::simple::ResampleImageFilter Procedural Interface
SITKIO_EXPORT void WriteImage(const Image &image, const PathType &fileName, bool useCompression=false, int compressionLevel=-1)
WriteImage is a procedural interface to the ImageFileWriter. class which is convenient for many image...
Image RescaleIntensity(Image &&image1, double outputMinimum=0, double outputMaximum=255)
Applies a linear transformation to the intensity levels of the input Image .
Image Cast(const Image &image, PixelIDValueEnum pixelID)