GDCM 3.0.24
StandardizeFiles.cs

This is a C++ example on how to use ImageChangeTransferSyntax

/*=========================================================================
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.
=========================================================================*/
/*
* Simple C# example to show how one would 'Standardize' a DICOM File-Set
*
* Usage:
* $ export LD_LIBRARY_PATH=$HOME/Projects/gdcm/debug-gcc/bin
* $ mono bin/StandardizeFiles.exe input_path output_path
*/
using System;
using gdcm;
public class StandardizeFiles
{
public static bool ProcessOneFile( string filename, string outfilename )
{
PixmapReader reader = new PixmapReader();
reader.SetFileName( filename );
if( !reader.Read() )
{
System.Console.WriteLine( "Could not read: " + filename );
return false;
}
change.SetForce( false ); // do we really want to recompress when input is already compressed in same alg ?
change.SetCompressIconImage( false ); // Keep it simple
change.SetTransferSyntax( new TransferSyntax( TransferSyntax.TSType.JPEG2000Lossless ) );
change.SetInput( reader.GetPixmap() );
if( !change.Change() )
{
System.Console.WriteLine( "Could not change: " + filename );
return false;
}
// The following three lines make sure to regenerate any value:
fmi.Remove( new gdcm.Tag(0x0002,0x0012) );
fmi.Remove( new gdcm.Tag(0x0002,0x0013) );
fmi.Remove( new gdcm.Tag(0x0002,0x0016) );
PixmapWriter writer = new PixmapWriter();
writer.SetFileName( outfilename );
writer.SetFile( reader.GetFile() );
gdcm.Pixmap pixout = ((PixmapToPixmapFilter)change).GetOutput();
writer.SetPixmap( pixout );
if( !writer.Write() )
{
System.Console.WriteLine( "Could not write: " + outfilename );
return false;
}
return true;
}
public static int Main(string[] args)
{
// http://www.oid-info.com/get/1.3.6.1.4.17434
string THERALYS_ORG_ROOT = "1.3.6.1.4.17434";
gdcm.UIDGenerator.SetRoot( THERALYS_ORG_ROOT );
System.Console.WriteLine( "Root dir is now: " + gdcm.UIDGenerator.GetRoot() );
string dir1 = args[0];
string dir2 = args[1];
// Check input is valid:
if( !gdcm.PosixEmulation.FileIsDirectory(dir1) )
{
System.Console.WriteLine( "Input directory: " + dir1 + " does not exist. Sorry" );
return 1;
}
if( !gdcm.PosixEmulation.FileIsDirectory(dir2) )
{
System.Console.WriteLine( "Output directory: " + dir2 + " does not exist. Sorry" );
return 1;
}
Directory d = new Directory();
uint nfiles = d.Load( dir1, true );
if(nfiles == 0) return 1;
// Process all filenames:
FilenamesType filenames = d.GetFilenames();
for( uint i = 0; i < nfiles; ++i )
{
string filename = filenames[ (int)i ];
string outfilename = filename.Replace( dir1, dir2 );
System.Console.WriteLine( "Filename: " + filename );
System.Console.WriteLine( "Out Filename: " + outfilename );
if( !ProcessOneFile( filename, outfilename ) )
{
System.Console.WriteLine( "Could not process filename: " + filename );
//return 1;
}
}
return 0;
}
}
void SetInput(const Bitmap &image)
Set input image.
SizeType Remove(const Tag &tag)
Completely remove a dataelement from the dataset.
Definition gdcmDataSet.h:172
Class for manipulation directories.
Definition gdcmDirectory.h:43
unsigned int Load(FilenameType const &name, bool recursive=false)
FilenamesType const & GetFilenames() const
Set/Get the file names within the directory.
Definition gdcmDirectory.h:58
Class to represent a File Meta Information.
Definition gdcmFileMetaInformation.h:41
static void SetSourceApplicationEntityTitle(const char *title)
const FileMetaInformation & GetHeader() const
Get File Meta Information.
Definition gdcmFile.h:48
ImageChangeTransferSyntax class.
Definition gdcmImageChangeTransferSyntax.h:40
void SetCompressIconImage(bool b)
Definition gdcmImageChangeTransferSyntax.h:55
void SetTransferSyntax(const TransferSyntax &ts)
Set target Transfer Syntax.
Definition gdcmImageChangeTransferSyntax.h:46
void SetForce(bool f)
Definition gdcmImageChangeTransferSyntax.h:61
PixmapReader.
Definition gdcmPixmapReader.h:40
const Pixmap & GetPixmap() const
Return the read image (need to call Read() first)
bool Read() override
PixmapToPixmapFilter class.
Definition gdcmPixmapToPixmapFilter.h:28
PixmapWriter.
Definition gdcmPixmapWriter.h:37
bool Write() override
Write.
void SetPixmap(Pixmap const &img)
Pixmap class.
Definition gdcmPixmap.h:33
const File & GetFile() const
Set/Get File.
Definition gdcmReader.h:72
void SetFileName(const char *filename_native)
Class to do system operation.
Definition gdcmSystem.h:27
Class to represent a DICOM Data Element (Attribute) Tag (Group, Element).
Definition gdcmTag.h:39
Class to manipulate Transfer Syntax.
Definition gdcmTransferSyntax.h:40
TSType
Definition gdcmTransferSyntax.h:61
Class for generating unique UID.
Definition gdcmUIDGenerator.h:28
static void SetRoot(const char *root)
static const char * GetRoot()
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:
Definition gdcmASN1.h:21