GDCM: DecompressImage.cs

GDCM 3.2.8

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();
image. SetNumberOfDimensions( ir. GetNumberOfDimensions() );
//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 );
PhotometricInterpretation pi = ir. GetPhotometricInterpretation();
image. SetPhotometricInterpretation( pi );
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;
}
}
gdcm::Bitmap::SetNumberOfDimensions
void SetNumberOfDimensions(unsigned int dim)
gdcm::Bitmap::GetBufferLength
unsigned long GetBufferLength() const
gdcm::Bitmap::SetDimensions
void SetDimensions(const unsigned int dims[3])
gdcm::Bitmap::SetDataElement
void SetDataElement(DataElement const &de)
Definition gdcmBitmap.h:76
gdcm::Bitmap::GetPixelFormat
const PixelFormat & GetPixelFormat() const
Get/Set PixelFormat.
Definition gdcmBitmap.h:107
gdcm::Bitmap::GetPhotometricInterpretation
const PhotometricInterpretation & GetPhotometricInterpretation() const
return the photometric interpretation
gdcm::Bitmap::GetBuffer
bool GetBuffer(char *buffer) const
Access the raw data.
gdcm::Bitmap::SetPhotometricInterpretation
void SetPhotometricInterpretation(PhotometricInterpretation const &pi)
gdcm::Bitmap::GetDimension
unsigned int GetDimension(unsigned int idx) const
gdcm::Bitmap::GetNumberOfDimensions
unsigned int GetNumberOfDimensions() const
Return the number of dimension of the pixel data bytes; for example 2 for a 2D matrices of values.
gdcm::Bitmap::SetPixelFormat
void SetPixelFormat(PixelFormat const &pf)
Definition gdcmBitmap.h:115
gdcm::DataElement
Class to represent a Data Element either Implicit or Explicit.
Definition gdcmDataElement.h:59
gdcm::DataElement::GetSequenceOfFragments
const SequenceOfFragments * GetSequenceOfFragments() const
gdcm::DataElement::SetByteValue
void SetByteValue(const char *array, VL length)
Definition gdcmDataElement.h:126
gdcm::DataSet::GetDataElement
const DataElement & GetDataElement(const Tag &t) const
Definition gdcmDataSet.h:188
gdcm::File::GetDataSet
const DataSet & GetDataSet() const
Get Data Set.
Definition gdcmFile.h:57
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::ImageWriter
ImageWriter.
Definition gdcmImageWriter.h:33
gdcm::ImageWriter::Write
bool Write() override
Write.
gdcm::Image
Image.
Definition gdcmImage.h:47
gdcm::PhotometricInterpretation
Class to represent an PhotometricInterpretation.
Definition gdcmPhotometricInterpretation.h:29
gdcm::PixelFormat
PixelFormat.
Definition gdcmPixelFormat.h:46
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::SequenceOfFragments::GetFragment
const Fragment & GetFragment(SizeType num) const
gdcm::Tag
Class to represent a DICOM Data Element (Attribute) Tag (Group, Element).
Definition gdcmTag.h:39
gdcm::VL
Value Length.
Definition gdcmVL.h:30
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