GDCM: iU22tomultisc.cxx

GDCM 3.2.7

iU22tomultisc.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.
=========================================================================*/
/*
* iU22 Raw Data extractor
*/
#include "gdcmReader.h"
#include "gdcmImageWriter.h"
#include "gdcmAttribute.h"
#include "gdcmPrivateTag.h"
#include <math.h>
int main(int argc, char *argv [])
{
if( argc < 2 ) return 1;
// IM_001
const char *filename = argv[1];
gdcm::Reader reader; // Do not use ImageReader
reader. SetFileName( filename );
if( !reader. Read() )
{
std::cerr << "Failed to read: " << filename << std::endl;
return 1;
}
// * The data is simply 8-bit unsigned in the obvious x/y/z order
// * 200D,300B contains the data
// * 200D,3001 contains the no. of voxels (416,412,256 in this case)
// * 200D,3003 contains the voxel sizes (0.156184527398215 /
// 0.1223749613981957 / 0.328479990704639 in this case)
const gdcm::File &file = reader. GetFile();
const gdcm::DataSet &ds = file. GetDataSet();
const gdcm::PrivateTag trawdataus( 0x200d, 0x0b, "Philips US Imaging DD 033" );
const gdcm::DataElement &rawdataus = ds. GetDataElement( trawdataus );
const gdcm::PrivateTag tcolsrowsframes( 0x200d, 0x01, "Philips US Imaging DD 036" );
const gdcm::DataElement &colsrowsframes = ds.GetDataElement( tcolsrowsframes );
// const gdcm::PrivateTag tcolsrowsframes( 0x200d, 0x02, "Philips US Imaging DD 036" );
// this is just a duplicate previous tag.
const gdcm::PrivateTag tvoxelspacing( 0x200d, 0x03, "Philips US Imaging DD 036" );
const gdcm::DataElement &voxelspacing = ds.GetDataElement( tvoxelspacing );
gdcm::Element<gdcm::VR::DS,gdcm::VM::VM3> dims; // Use DS to interpret value stored in LO
dims. SetFromDataElement( colsrowsframes );
gdcm::Element<gdcm::VR::DS,gdcm::VM::VM3> spacing;
spacing.SetFromDataElement( voxelspacing );
gdcm::ImageWriter writer;
gdcm::Image &image = writer. GetImage();
image. SetNumberOfDimensions( 3 ); // good default
image. SetDimension(0, (unsigned int)dims[0] );
image.SetDimension(1, (unsigned int)dims[1] );
image.SetDimension(2, (unsigned int)dims[2] );
image. SetSpacing(0, spacing[0] );
image.SetSpacing(1, spacing[1] );
image.SetSpacing(2, spacing[2] );
gdcm::PixelFormat pixeltype = gdcm::PixelFormat::UINT8;
gdcm::PhotometricInterpretation pi;
pi = gdcm::PhotometricInterpretation::MONOCHROME2;
image. SetPhotometricInterpretation( pi );
image. SetPixelFormat( pixeltype );
image. SetDataElement( rawdataus );
std::string outfilename = "outiu22.dcm";
gdcm::DataElement de( gdcm::Tag(0x8,0x16) ); // SOP Class UID
de. SetVR( gdcm::VR::UI );
gdcm::MediaStorage ms(
gdcm::MediaStorage::UltrasoundMultiFrameImageStorage );
// gdcm::MediaStorage::MultiframeGrayscaleByteSecondaryCaptureImageStorage );
de. SetByteValue( ms. GetString(), (uint32_t)strlen(ms.GetString()));
writer. GetFile().GetDataSet().Replace( de );
writer. SetFileName( outfilename.c_str() );
if( !writer. Write() )
{
std::cerr << "could not write: " << outfilename << std::endl;
return 1;
}
return 0;
}
gdcm::Bitmap::SetNumberOfDimensions
void SetNumberOfDimensions(unsigned int dim)
gdcm::Bitmap::SetDataElement
void SetDataElement(DataElement const &de)
Definition gdcmBitmap.h:76
gdcm::Bitmap::SetDimension
void SetDimension(unsigned int idx, unsigned int dim)
gdcm::Bitmap::SetPhotometricInterpretation
void SetPhotometricInterpretation(PhotometricInterpretation const &pi)
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::SetByteValue
void SetByteValue(const char *array, VL length)
Definition gdcmDataElement.h:126
gdcm::DataElement::SetVR
void SetVR(VR const &vr)
Definition gdcmDataElement.h:88
gdcm::DataSet
Class to represent a Data Set (which contains Data Elements).
Definition gdcmDataSet.h:56
gdcm::DataSet::GetDataElement
const DataElement & GetDataElement(const Tag &t) const
Definition gdcmDataSet.h:188
gdcm::DataSet::Replace
void Replace(const DataElement &de)
Replace a dataelement with another one.
Definition gdcmDataSet.h:150
gdcm::Element
Element class.
Definition gdcmElement.h:70
gdcm::Element::SetFromDataElement
void SetFromDataElement(DataElement const &de)
Definition gdcmElement.h:110
gdcm::File
a DICOM File
Definition gdcmFile.h:34
gdcm::File::GetDataSet
const DataSet & GetDataSet() const
Get Data Set.
Definition gdcmFile.h:57
gdcm::ImageWriter
ImageWriter.
Definition gdcmImageWriter.h:33
gdcm::ImageWriter::Write
bool Write() override
Write.
gdcm::ImageWriter::GetImage
const Image & GetImage() const override
Definition gdcmImageWriter.h:41
gdcm::Image
Image.
Definition gdcmImage.h:47
gdcm::Image::SetSpacing
void SetSpacing(const double spacing[3])
gdcm::MediaStorage
MediaStorage.
Definition gdcmMediaStorage.h:44
gdcm::MediaStorage::UltrasoundMultiFrameImageStorage
@ UltrasoundMultiFrameImageStorage
Definition gdcmMediaStorage.h:60
gdcm::MediaStorage::GetString
const char * GetString() const
Return the Media String of the object.
gdcm::PhotometricInterpretation
Class to represent an PhotometricInterpretation.
Definition gdcmPhotometricInterpretation.h:29
gdcm::PhotometricInterpretation::MONOCHROME2
@ MONOCHROME2
Definition gdcmPhotometricInterpretation.h:34
gdcm::PixelFormat
PixelFormat.
Definition gdcmPixelFormat.h:46
gdcm::PixelFormat::UINT8
@ UINT8
Definition gdcmPixelFormat.h:52
gdcm::PrivateTag
Class to represent a Private DICOM Data Element (Attribute) Tag (Group, Element, Owner).
Definition gdcmPrivateTag.h:39
gdcm::Reader
Reader ala DOM (Document Object Model).
Definition gdcmReader.h:54
gdcm::Reader::GetFile
const File & GetFile() const
Set/Get File.
Definition gdcmReader.h:72
gdcm::Reader::Read
virtual bool Read()
Main function to read a file.
gdcm::Reader::SetFileName
void SetFileName(const char *filename_native)
gdcm::Tag
Class to represent a DICOM Data Element (Attribute) Tag (Group, Element).
Definition gdcmTag.h:39
gdcm::VR::UI
@ UI
Definition gdcmVR.h:87
gdcm::Writer::GetFile
File & GetFile()
Definition gdcmWriter.h:67
gdcm::Writer::SetFileName
void SetFileName(const char *filename_native)
Set the filename of DICOM file to write:
gdcmAttribute.h
gdcmImageWriter.h
gdcmPrivateTag.h
gdcmReader.h