2012-03-23 164 views
1

我可以讀取單幀DICOM圖像。但我不知道如何去閱讀一個多幀DICOM文件,也就是說,在一個DICOM文件中有多個圖像。這是我用來讀取單幀DICOM的代碼。我在想,應該將加載的圖像緩衝區(imageBuf)分成與DICOM中的幀數一樣多的部分,並使用每個部分來構建圖像。可以這樣做嗎?使用ITK讀取多幀DICOM圖像

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]; 

回答

1

您是否嘗試過itk :: ImageSeriesReader?