简体   繁体   English

iOS上的ITK库-加载DICOM

[英]ITK library on iOS - Loading DICOM

I have built the ITK library for the ipad - and it works. 我已经为ipad构建了ITK库-并且它可以工作。 Then I tried to make an ITK example - something like that: 然后,我尝试制作一个ITK示例-像这样:

// Load DICOM files
typedef itk::ImageSeriesReader< InputImageType > ReaderType;
ReaderType::Pointer reader = ReaderType::New();
typedef itk::GDCMImageIO ImageIOType;
typedef itk::GDCMSeriesFileNames NamesGeneratorType;
ImageIOType::Pointer gdcmIO = ImageIOType::New();
NamesGeneratorType::Pointer namesGenerator = NamesGeneratorType::New();
namesGenerator->SetInputDirectory( "C:/test" );

But I tried a lot of possibilites to load a DICOM stack in a directory on the documents folder of the ipad instead of the c:/test path. 但是我尝试了很多可能的方法来将DICOM堆栈加载到ipad文件文件夹的目录中,而不是c:/test路径中。 But that didn't work. 但那没用。

So my idea is to load a DICOM like that over the internet: 所以我的想法是通过互联网加载这样的DICOM

NSData *dicomImage = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.someurl.ch/dicom/blabla.dcm"]];   

And now I think about trying to get out the dicom data (patient name etc) and separate it from the image data. 现在,我考虑尝试找出dicom数据(患者姓名等)并将其与图像数据分开。 Then I think it must be possible to have at the end an UIImage to display on the IPAD. 然后,我认为最后必须有一个UIImage可以显示在IPAD上。

I searched for an example for that, but sadly...i didnt found something good. 我为此寻找了一个例子,但可悲的是……我没有发现什么好东西。 If anybody has got an idea how to load a dcm on the ipad through ITK or an idea how to get the image data out of the NSData object? 如果有人知道如何通过ITK在ipad上加载dcm,还是知道如何从NSData对象中获取图像数据?

ITK actually uses GDCM to read DICOM files, so it's probably easier to use GDCM directly. ITK实际上使用GDCM读取DICOM文件,因此直接使用GDCM可能更容易。 http://sourceforge.net/apps/mediawiki/gdcm/index.php http://sourceforge.net/apps/mediawiki/gdcm/index.php

As for loading DICOM files on the iPad (or any mobile device), I would be careful when doing so. 至于在iPad(或任何移动设备)上加载DICOM文件,我会小心谨慎。 Some DICOM files are very large (on the order of GBs), and that would probably just crash your application. 一些DICOM文件非常大(约为GB),这可能会使您的应用程序崩溃。 Of course, you'd probably have a difficult time loading files that large onto the iPad anyway :) 当然,无论如何,您可能都很难在iPad上加载大文件:)


The pixel data is not necessarily RGB data as you would expect to find in a JPEG. 像素数据不一定是您希望在JPEG中找到的RGB数据。 Check the photometric interpretation. 检查光度学解释。 If it's RGB, then you're good to go (after decoding & decompression). 如果是RGB,则最好进行解码和解压缩后。 If it's monochrome, you may need to convert to RGB values (see How to translate DICOM image width and level to JPEG brightness and contrast? ) before passing the data to UIImage. 如果是单色,则在将数据传递到UIImage之前,可能需要转换为RGB值(请参阅如何将DICOM图像的宽度和水平转换为JPEG亮度和对比度? )。

You may want to investigate DCMTK. 您可能要调查DCMTK。 On an iphone you will likely need the network protocol capabilities that are in DCMTK. 在iphone上,您可能需要DCMTK中的网络协议功能。

Since my last post, I have now a little solution for my problem. 自从上一篇文章以来,我现在对我的问题有了一些解决方案。

namesGenerator->SetInputDirectory( documentFolderPath );
typedef std::vector<std::string> FileNamesContainer; 
FileNamesContainer fileNames = nameGenerator->GetInputFileNames();
reader->SetFileNames( fileNames );
reader->Update();
ImageType *  imageTest = reader->GetOutput(); // get 3d volume
PixelType * pixelData = imageTest->GetBufferPointer(); // get bufferpointer

With that, I can load DICOM stacks and get out the whole dicom header information :) Now my problem is about getting the image pixel data into an UIImage. 这样,我就可以加载DICOM堆栈并获取整个dicom标头信息:)现在,我的问题是将图像像素数据放入UIImage中。 I can load single pixelvalues with this code:(just for a test, getPixel is a slow method) 我可以用以下代码加载单个pixelvalues :(仅出于测试目的,getPixel是一种缓慢的方法)

ImageType::IndexType pixelIndex;
pixelIndex[0] = 100; 
pixelIndex[1] = 100; 
pixelIndex[2] = 0;

ImageType::PixelType pixelValue = imageTest->GetPixel( pixelIndex );

But my problem is, that I dont understand how I can handle the data of *pixeldata (the bufferpointer) to create a UIImage. 但是我的问题是,我不了解如何处理* pixeldata(缓冲区指针)的数据来创建UIImage。 Sadly I didnt found some example in the ITK documentation :( 遗憾的是,我没有在ITK文档中找到一些示例:(

//assume that the image width is 880 and the image height is 635
int imageWidth = 880;
int imageHeight = 635;
NSString *dicomPath = [[[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/"] stringByAppendingString:@"your dicom file name"];
const char *c_dicomPath = [dicomPath UTF8String];

typedef unsigned char InputPixelType; 
const unsigned int InputDimension = 3;
typedef itk::Image< InputPixelType, InputDimension > InputImageType;

typedef itk::ImageFileReader< InputImageType > ReaderType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(c_dicomPath);

typedef itk::GDCMImageIO ImageIOType; 
ImageIOType::Pointer gdcmImageIO = ImageIOType::New(); 
reader->SetImageIO(gdcmImageIO);

InputPixelType *imageBuf = (InputPixelType*)malloc(sizeof(InputPixelType)*imageHeight*imageWidth*3);
reader->Update();

//get dicom image
memset(imageBuf, 0, sizeof(InputPixelType)*imageHeight*imageWidth*3);

gdcmImageIO->Read(imageBuf);
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
CGDataProviderRef provider = CGDataProviderCreateWithData(nil, imageBuf, imageWidth*imageHeight*3*sizeof(InputPixelType), nil);  

CGImageRef imageRef = CGImageCreate(imageWidth,//width
                                    imageHeight,//height 
                                    8,//size_t bitsPerComponent, 
                                    24,//size_t bitsPerPixel,
                                    imageWidth*sizeof(InputPixelType)*3,//size_t bytesPerRow, 
                                    colorspace,//CGColorSpaceRef space,
                                    kCGBitmapByteOrderDefault,//CGBitmapInfo bitmapInfo,
                                    provider,//CGDataProviderRef provider,
                                    nil,//const CGFloat *decode,
                                    NO,//bool shouldInterpolate, 
                                    kCGRenderingIntentDefault//CGColorRenderingIntent intent
                                    );
//here is the dicom image decode from dicom file
UIImage *dicomImage = [[UIImage alloc] initWithCGImage:imageRef scale:1.0 orientation:UIImageOrientationUp];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM