1

ピクセル処理を行うために DICOM ファイルを解析したいと考えています。DCMTK ライブラリを試しましたが、うまくいきません。DICOM ファイルを読みたいだけなので、C++ の軽量クロスプラットフォーム ライブラリのような非常に単純なものが必要です。

どんな提案でも大歓迎です。

4

1 に答える 1

1

ImageMagick を使用して DICOM ファイルを読み取ることができます。これは無料でクロスプラットフォームであり、通常は Linux ディストリビューションにインストールされ、OSX および Windows で利用できます。

バージョン 6.x のサンプルは次のとおりです...

////////////////////////////////////////////////////////////////////////////////
// sample.cpp
// Mark Setchell
//
// ImageMagick Magick++ sample code
//
// Compile with:
// g++ sample.cpp -o sample $(Magick++-config --cppflags --cxxflags --ldflags --libs)
////////////////////////////////////////////////////////////////////////////////
#include <Magick++.h> 
#include <iostream> 

using namespace std; 
using namespace Magick; 

int main(int argc,char **argv) 
{ 
   // Initialise ImageMagick library
   InitializeMagick(*argv);

   // Create Image object and read in DICOM image
   Image image("sample.dcm"); 

   // Get dimensions
   int w = image.columns();
   int h = image.rows();
   cout << "Dimensions: " << w << "x" << h << endl;

   PixelPacket *pixels = image.getPixels(0, 0, w, h);

   for(int y=0; y<h; y++){
      for(int x=0; x<w; x++){
         Color color = pixels[w * y + x];
         cout << x << "," << y << ":" << color.redQuantum() << "/" << color.greenQuantum() << "/" << color.blueQuantum() << endl;
      }
   }
}

サンプル出力

Dimensions: 512x512
0,0:0/0/0
1,0:0/0/0
2,0:0/0/0
3,0:0/0/0
4,0:0/0/0
5,0:0/0/0
6,0:0/0/0
7,0:0/0/0
8,0:0/0/0
9,0:0/0/0
10,0:0/0/0
11,0:0/0/0
12,0:0/0/0
13,0:0/0/0
14,0:0/0/0
15,0:0/0/0
16,0:0/0/0
17,0:0/0/0
18,0:0/0/0
19,0:0/0/0
20,0:0/0/0
21,0:0/0/0
22,0:0/0/0
23,0:0/0/0
24,0:0/0/0
25,0:0/0/0
...
...
260,18:80/80/80
261,18:144/144/144
262,18:192/192/192
263,18:80/80/80
264,18:32/32/32
265,18:144/144/144
...
...

バージョン 7.x を使用する場合は、ここでEric の手法を参照してください。

または、ターミナルのコマンド ラインで、次のようにファイルを生の 8 ビット RGB バイナリ データに変換できます。

# Convert 512x512 image to 8-bit RGB binary file
convert sample.dcm -depth 8 rgb:image.bin

ls -l image.bin
-rw-r--r--    1 mark  staff    786432 30 Jun 15:29 image.bin

ファイル サイズから、イメージが 786,432 バイト (512x512 ピクセルごとに 3 バイト) になっていることがわかると思います。したがって、データを C++ プログラムに直接読み取って、次の結果が得られることがわかります。

RGB RGB RGB RGB ... RGB

または、ターミナルのコマンド ラインで、イメージ データを 16 進数としてダンプできます。

convert sample.dcm -depth 8 txt: | more

サンプル出力

# ImageMagick pixel enumeration: 512,512,65535,gray
0,0: (0,0,0)  #000000  gray(0)
1,0: (0,0,0)  #000000  gray(0)
2,0: (0,0,0)  #000000  gray(0)
于 2016-06-30T14:24:48.583 に答える