GDCM: CompressImage.cxx

GDCM 3.2.7

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 "gdcmImageReader.h"
#include "gdcmImage.h"
#include "gdcmWriter.h"
#include "gdcmAttribute.h"
#include "gdcmImageWriter.h"
#include "gdcmImageChangeTransferSyntax.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];
gdcm::ImageReader reader;
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 );
gdcm::ImageChangeTransferSyntax change;
change. SetTransferSyntax( gdcm::TransferSyntax::JPEG2000Lossless );
change.SetTransferSyntax( gdcm::TransferSyntax::JPEGLosslessProcess14_1 );
//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();
gdcm::ImageWriter writer;
writer. SetImage( change. GetOutput() );
writer. SetFile( reader. GetFile() );
writer. SetFileName( outfilename );
if( !writer. Write() )
{
return 1;
}
return 0;
}
gdcm::BitmapToBitmapFilter::SetInput
void SetInput(const Bitmap &image)
Set input image.
gdcm::ImageChangeTransferSyntax
ImageChangeTransferSyntax class.
Definition gdcmImageChangeTransferSyntax.h:40
gdcm::ImageChangeTransferSyntax::SetTransferSyntax
void SetTransferSyntax(const TransferSyntax &ts)
Set target Transfer Syntax.
Definition gdcmImageChangeTransferSyntax.h:46
gdcm::ImageChangeTransferSyntax::Change
bool Change()
Change.
gdcm::ImageReader
ImageReader.
Definition gdcmImageReader.h:34
gdcm::ImageReader::GetImage
const Image & GetImage() const
Return the read image.
gdcm::ImageReader::Read
bool Read() override
gdcm::ImageToImageFilter::GetOutput
const Image & GetOutput() const
Get Output image.
gdcm::ImageWriter
ImageWriter.
Definition gdcmImageWriter.h:33
gdcm::ImageWriter::Write
bool Write() override
Write.
gdcm::Image
Image.
Definition gdcmImage.h:47
gdcm::Image::Print
void Print(std::ostream &os) const override
print
gdcm::PixmapWriter::SetImage
virtual void SetImage(Pixmap const &img)
gdcm::Reader::GetFile
const File & GetFile() const
Set/Get File.
Definition gdcmReader.h:72
gdcm::Reader::SetFileName
void SetFileName(const char *filename_native)
gdcm::TransferSyntax::JPEG2000Lossless
@ JPEG2000Lossless
Definition gdcmTransferSyntax.h:76
gdcm::TransferSyntax::JPEGLosslessProcess14_1
@ JPEGLosslessProcess14_1
Definition gdcmTransferSyntax.h:73
gdcm::Writer::SetFile
void SetFile(const File &f)
Set/Get the DICOM file (DataSet + Header).
Definition gdcmWriter.h:66
gdcm::Writer::SetFileName
void SetFileName(const char *filename_native)
Set the filename of DICOM file to write:
gdcmAttribute.h
gdcmImageChangeTransferSyntax.h
gdcmImageReader.h
gdcmImageWriter.h
gdcmImage.h
gdcmWriter.h