GDCM 3.0.24
CompressImage.cxx
/*=========================================================================
Program: GDCM (Grassroots DICOM). A DICOM library
Copyright (c) 2006-2011 Mathieu Malaterre
All rights reserved.
See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
/*
*
*/
#include "gdcmImage.h"
#include "gdcmWriter.h"
#include "gdcmAttribute.h"
#include <iostream>
#include <fstream>
int main(int argc, char *argv[])
{
if( argc < 3 )
{
std::cerr << argv[0] << " input.dcm output.dcm" << std::endl;
return 1;
}
const char *filename = argv[1];
const char *outfilename = argv[2];
reader.SetFileName( filename );
if( !reader.Read() )
{
std::cerr << "Could not read: " << filename << std::endl;
return 1;
}
// The output of gdcm::Reader is a gdcm::File
//gdcm::File &file = reader.GetFile();
// the dataset is the the set of element we are interested in:
//gdcm::DataSet &ds = file.GetDataSet();
gdcm::Image &image = reader.GetImage();
// image.SetSpacing(0, 0.1);
// image.SetSpacing(1, 0.2);
image.Print( std::cout );
//change.SetTransferSyntax( gdcm::TransferSyntax::JPEGBaselineProcess1 );
//change.SetTransferSyntax( image.GetTransferSyntax() );
change.SetInput( image );
bool b = change.Change();
if( !b )
{
std::cerr << "Could not change the Transfer Syntax" << std::endl;
return 1;
}
//std::ofstream out( outfilename, std::ios::binary );
//image.GetBuffer2(out);
//out.close();
writer.SetImage( change.GetOutput() );
writer.SetFile( reader.GetFile() );
writer.SetFileName( outfilename );
if( !writer.Write() )
{
return 1;
}
return 0;
}
void SetInput(const Bitmap &image)
Set input image.
ImageChangeTransferSyntax class.
Definition gdcmImageChangeTransferSyntax.h:40
void SetTransferSyntax(const TransferSyntax &ts)
Set target Transfer Syntax.
Definition gdcmImageChangeTransferSyntax.h:46
ImageReader.
Definition gdcmImageReader.h:34
const Image & GetImage() const
Return the read image.
bool Read() override
const Image & GetOutput() const
Get Output image.
ImageWriter.
Definition gdcmImageWriter.h:33
bool Write() override
Write.
Image.
Definition gdcmImage.h:47
void Print(std::ostream &os) const override
print
virtual void SetImage(Pixmap const &img)
const File & GetFile() const
Set/Get File.
Definition gdcmReader.h:72
void SetFileName(const char *filename_native)
@ JPEG2000Lossless
Definition gdcmTransferSyntax.h:76
@ JPEGLosslessProcess14_1
Definition gdcmTransferSyntax.h:73
void SetFile(const File &f)
Set/Get the DICOM file (DataSet + Header)
Definition gdcmWriter.h:66
void SetFileName(const char *filename_native)
Set the filename of DICOM file to write: