GDCM 3.0.24
DecompressImage.cs

This is a C# example on how to use Image

/*=========================================================================
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/Projects/gdcm/debug-gcc/bin
* $ mono bin/DecompressImage.exe gdcmData/012345.002.050.dcm decompress.dcm
*/
using System;
using gdcm;
public class DecompressImage
{
public static int Main(string[] args)
{
string file1 = args[0];
string file2 = args[1];
ImageReader reader = new ImageReader();
reader.SetFileName( file1 );
bool ret = reader.Read();
if( !ret )
{
return 1;
}
// check that one can access a Fragment from C#:
var de = reader.GetFile().GetDataSet().GetDataElement(new Tag(0x7fe0, 0x0010));
var sq = de.GetSequenceOfFragments();
sq.GetFragment(0);
Image image = new Image();
Image ir = reader.GetImage();
//Just for fun:
//int dircos = ir.GetDirectionCosines();
//t = gdcm.Orientation.GetType(dircos);
//int l = gdcm.Orientation.GetLabel(t);
//System.Console.WriteLine( "Orientation label:" + l );
// Set the dimensions,
// 1. either one at a time
//image.SetDimension(0, ir.GetDimension(0) );
//image.SetDimension(1, ir.GetDimension(1) );
// 2. the array at once
uint[] dims = {0, 0};
// Just for fun let's invert the dimensions:
dims[0] = ir.GetDimension(1);
dims[1] = ir.GetDimension(0);
ir.SetDimensions( dims );
PixelFormat pixeltype = ir.GetPixelFormat();
image.SetPixelFormat( pixeltype );
DataElement pixeldata = new DataElement( new Tag(0x7fe0,0x0010) );
byte[] str1 = new byte[ ir.GetBufferLength()];
ir.GetBuffer( str1 );
//System.Console.WriteLine( ir.GetBufferLength() );
pixeldata.SetByteValue( str1, new VL( (uint)str1.Length ) );
//image.SetDataElement( pixeldata );
ir.SetDataElement( pixeldata );
ImageWriter writer = new ImageWriter();
writer.SetFileName( file2 );
writer.SetFile( reader.GetFile() );
writer.SetImage( ir );
ret = writer.Write();
if( !ret )
{
return 1;
}
return 0;
}
}
void SetNumberOfDimensions(unsigned int dim)
unsigned long GetBufferLength() const
void SetDimensions(const unsigned int dims[3])
void SetDataElement(DataElement const &de)
Definition gdcmBitmap.h:76
const PixelFormat & GetPixelFormat() const
Get/Set PixelFormat.
Definition gdcmBitmap.h:107
const PhotometricInterpretation & GetPhotometricInterpretation() const
return the photometric interpretation
bool GetBuffer(char *buffer) const
Access the raw data.
void SetPhotometricInterpretation(PhotometricInterpretation const &pi)
unsigned int GetDimension(unsigned int idx) const
unsigned int GetNumberOfDimensions() const
Return the number of dimension of the pixel data bytes; for example 2 for a 2D matrices of values.
void SetPixelFormat(PixelFormat const &pf)
Definition gdcmBitmap.h:115
Class to represent a Data Element either Implicit or Explicit.
Definition gdcmDataElement.h:59
const SequenceOfFragments * GetSequenceOfFragments() const
void SetByteValue(const char *array, VL length)
Definition gdcmDataElement.h:126
const DataElement & GetDataElement(const Tag &t) const
Definition gdcmDataSet.h:188
const DataSet & GetDataSet() const
Get Data Set.
Definition gdcmFile.h:57
ImageReader.
Definition gdcmImageReader.h:34
const Image & GetImage() const
Return the read image.
bool Read() override
ImageWriter.
Definition gdcmImageWriter.h:33
bool Write() override
Write.
Image.
Definition gdcmImage.h:47
Class to represent an PhotometricInterpretation.
Definition gdcmPhotometricInterpretation.h:29
PixelFormat.
Definition gdcmPixelFormat.h:46
virtual void SetImage(Pixmap const &img)
const File & GetFile() const
Set/Get File.
Definition gdcmReader.h:72
void SetFileName(const char *filename_native)
const Fragment & GetFragment(SizeType num) const
Class to represent a DICOM Data Element (Attribute) Tag (Group, Element).
Definition gdcmTag.h:39
Value Length.
Definition gdcmVL.h:30
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