我可以读取单帧DICOM图像。但我不知道如何阅读多帧DICOM文件,即在单个DICOM文件中有多个图像。这是我用来读取单帧DICOM的代码。我在思考加载图像缓冲区(imageBuf)应该被分成与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];
答案 0 :(得分:1)
您是否尝试过itk :: ImageSeriesReader?