dicom图像读取c 语言,如何在c中读取dicom像素

您可以使用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

#include

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

for(int x=0; x

Color color = pixels[w * y + x];

cout << x << "," << y << ":" << color.redQuantum() << "/" << color.greenQuantum() << "/" << color.blueQuantum() << endl;

}

}

}

Sample Output

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的技术here .

或者,在终端的命令行中,您可以将文件转换为原始的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

或者,在终端的命令行中,您可以将图像数据转储为十六进制:

convert sample.dcm -depth 8 txt: | more

Sample Output

# 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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值