GDCM: CompressLossyJPEG.cs

GDCM 3.2.10

CompressLossyJPEG.cs
/*=========================================================================
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.
=========================================================================*/
/*
* Usage:
* $ export LD_LIBRARY_PATH=$HOME/Perso/gdcm/debug-gcc/bin
* $ mono bin/CompressLossyJPEG.exe input.dcm output.dcm
*/
using System;
using gdcm;
public class CompressLossyJPEG
{
public static int Main(string[] args)
{
if( args.Length < 2 )
{
System.Console.WriteLine( " input.dcm output.dcm" );
return 1;
}
string filename = args[0];
string outfilename = args[1];
ImageReader reader = new ImageReader();
reader. SetFileName( filename );
if( !reader. Read() )
{
System.Console.WriteLine( "Could not read: " + filename );
return 1;
}
// The output of gdcm::Reader is a gdcm::File
File file = reader. GetFile();
// the dataset is the the set of element we are interested in:
DataSet ds = file. GetDataSet();
Image image = reader. GetImage();
//image.Print( cout );
ImageChangeTransferSyntax change = new ImageChangeTransferSyntax();
TransferSyntax targetts = new TransferSyntax( TransferSyntax. TSType.JPEGBaselineProcess1 );
change. SetTransferSyntax( targetts );
// Setup our JPEGCodec, warning it should be compatible with JPEGBaselineProcess1
JPEGCodec jpegcodec = new JPEGCodec();
if( !jpegcodec. CanCode( targetts ) )
{
System.Console.WriteLine( "Something went really wrong, JPEGCodec cannot handle JPEGBaselineProcess1" );
return 1;
}
jpegcodec. SetLossless( false );
jpegcodec. SetQuality( 50 ); // poor quality !
change. SetUserCodec( jpegcodec ); // specify the codec to use to the ImageChangeTransferSyntax
change. SetInput( image );
bool b = change. Change();
if( !b )
{
System.Console.WriteLine( "Could not change the Transfer Syntax" );
return 1;
}
ImageWriter writer = new ImageWriter();
writer. SetImage( (gdcm.Image)change. GetOutput() );
writer. SetFile( reader.GetFile() );
writer. SetFileName( outfilename );
if( !writer. Write() )
{
System.Console.WriteLine( "Could not write: " + outfilename );
return 1;
}
return 0;
}
}
gdcm::BitmapToBitmapFilter::SetInput
void SetInput(const Bitmap &image)
Set input image.
gdcm::DataSet
Class to represent a Data Set (which contains Data Elements).
Definition gdcmDataSet.h:56
gdcm::File
a DICOM File
Definition gdcmFile.h:34
gdcm::File::GetDataSet
const DataSet & GetDataSet() const
Get Data Set.
Definition gdcmFile.h:57
gdcm::ImageChangeTransferSyntax
ImageChangeTransferSyntax class.
Definition gdcmImageChangeTransferSyntax.h:40
gdcm::ImageChangeTransferSyntax::SetUserCodec
void SetUserCodec(ImageCodec *ic)
Definition gdcmImageChangeTransferSyntax.h:68
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::JPEGCodec
JPEG codec.
Definition gdcmJPEGCodec.h:41
gdcm::JPEGCodec::CanCode
bool CanCode(TransferSyntax const &ts) const override
Return whether this coder support this transfer syntax (can code it).
gdcm::JPEGCodec::SetLossless
void SetLossless(bool l)
gdcm::JPEGCodec::SetQuality
void SetQuality(double q)
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::System
Class to do system operation.
Definition gdcmSystem.h:27
gdcm::TransferSyntax
Class to manipulate Transfer Syntax.
Definition gdcmTransferSyntax.h:40
gdcm::TransferSyntax::TSType
TSType
Definition gdcmTransferSyntax.h:61
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:
gdcm
Definition gdcmASN1.h:21