DICOM画像とNAS その3


DICOMファイルから、患者名を直接読み取ったが、文字化けは、ありません

 
1.Grassroots DICOM library を使う

    Grassroots DICOM library は、SourceForgenetからダウンロードできます。

    DICOMファイルを読み取るための、専用のライブラリーです。

    GDCM開発チームの皆様に、御礼申し上げます。

Digital Imaging and Communications in Medicine (DICOM) is a standard that governs this capability by specifying handling, storing, printing, and transmitting information in medical imaging.

Grassroots DICOM (GDCM) is an implementation of the DICOM standard designed to be open source so that researchers may access clinical data directly. GDCM includes a file format definition and a network communications protocol, both of which should be extended to provide a full set of tools for a researcher or small medical imaging vendor to interface with an existing medical database.

GDCM is an open source implementation of the DICOM standard. It offers some compatibility with ACR-NEMA 1.0 & 2.0 files (raw files). It is written in C++ and offers wrapping to the following target languages (via the use of swig):

  • Python (supported),
  • C# (supported),
  • Java (testing),
  • PHP (experimental).

It attempts to support all possible DICOM image encodings, namely:

  • RAW,
  • JPEG lossy 8 & 12 bits (ITU-T T.81, ISO/IEC IS 10918-1),
  • JPEG lossless 8-16 bits (ITU-T T.81, ISO/IEC IS 10918-1),
  • JPEG 2000 reversible & irreversible (ITU-T T.800, ISO/IEC IS 15444-1),
  • RLE,
  • Deflated (compression at DICOM Dataset level),
  • JPEG-LS (testing) (ITU-T T.87, ISO/IEC IS 14495-1),
  • JPEG 2000 Multi-component reversible & irreversible (ISO/IEC IS 15444-2) (not supported for now),
  • MPEG-2 (not supported for now).

   (出典 SourceForgenet

    Tagの情報、raw data等を、得る事ができます。

 //GDCM part
                    ImageReader reader = new ImageReader();
                    reader.SetFileName(fileName);
                    if (!reader.Read())
                    {
                        return;
                    }
                  
                    gdcm.Image image = reader.GetImage();
                   
                    int height = (int)image.GetRows();
                    int width = (int)image.GetColumns();
                    byte[] origin_Data = new byte[width * height * 2];
                   
                    image.GetBuffer(origin_Data);

                    PixelFormat pf = image.GetPixelFormat();
                    ushort bits_allocated = pf.GetBitsAllocated();
                    ushort bits_stored = pf.GetBitsStored();
                    ushort high_bit = pf.GetHighBit();
                    gdcm.DataSet ds = reader.GetFile().GetDataSet();

                 //window center=Tag[0028,0050]、window=Tag[0028,0051]は、float文字列を返すので、数値に変換する
                   
         string wc = ds.GetDataElement(new Tag(0x0028, 0x1050)).GetValue().toString();
                    string _window = ds.GetDataElement(new Tag(0x0028, 0x1051)).GetValue().toString();
                   
                    int window_center = (int)(float.Parse(wc));     //window center=>levelの事
                    int window = (int)(float.Parse(_window));        //window =>window widthの事

    このように、C#のプログラム上から、画像表示に必要な情報を、得る事ができます。

    患者名を、DICOMファイルから直接読み込むには

         gdcm.DataSet ds = reader.GetFile().GetDataSet();
                  
                    //ここで患者名を dicom file から読み込んで見た                             
                    string patient_name = ds.GetDataElement(new Tag(0x0010, 0x0010)).GetByteValue().GetPointer();

    readerからDataSetを得て、Tag(0x0010,0x0010)の患者名を、ByteValueとして得る事ができるから

    文字化けしません、素晴らしい! 

2.何故 Grassroots DICOM (GDCM)が必要か?

    私は、Tag情報をファイルの最初から、順番に読み込もうとしたのですが

    中々、画像のrawdataにたどり着けませんでした。

    なぜなら、

   DICOM DataElementの中には、Tag情報のバイト数が未定義のものも、存在するからです。


   
    出典
   

    もう、やっとられん.....

    で、

    GDCMを見つけた訳です、救いの神様が現れたっ! GDCMチームの皆様に、感謝いたします。

3.GDCMのwindows C#での開発環境は

    @VisualStudio 2005

    AGDCM2.015(SourceForgeNetから、大文字のGDCMは、コンパイルされたdllを持ち、小文字のgdcmxx−xxは、sourceを意味します。)

    BVisual C++ 2008 Redistributable Package (x86) - Microsoft


    以上の構成で、開発できています。

    GDCM2.015に含まれる dllファイルは、、Bが必要らしい.....

    この開発環境で出来上がったプログラムは、

      プログラム自体は、.NET 2.0 で構成され、

      GDCMの dllファイルは、Bを参照しているらしい....、
    
      よく考えたら、dllは nativeなのだから、Bは要らんかも。

    自分に配布する時は、

    Bと、.NET2.0 の両方が要るのでしょうかね、ようわからん。

    .NETが混在する時、この事を、サイドバイサイドと、言うらしい。

4.DICOMファイル内の、bitmapが表示できれば

    bitmapの拡大、縮小、回転等は、沢山の資料を、webで公開して下さってるので、

    もう、一歩進みたいです。

    大変 お世話になったサイト

  簡易DICOM Viewerをつくろう
  
   
 GDCM examples

H.23.09.15