I can read single frame DICOM images fine. But I am not sure how to go about reading a multi frame DICOM file, which say, has multiple images in a single DICOM file. Here is the code I use to read single frame DICOM. I am thinking along the lines that the image buffer loaded (imageBuf) should be divided into as many parts as the number of frames in the DICOM and use each part to construct an image. Can that be done?
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];