Frame 使用ITK读取多帧DICOM图像

Frame 使用ITK读取多帧DICOM图像,frame,dicom,itk,gdcm,Frame,Dicom,Itk,Gdcm,我可以很好地阅读单帧DICOM图像。但我不知道如何读取多帧DICOM文件,也就是说,在一个DICOM文件中有多个图像。下面是我用来读取单帧DICOM的代码。我的想法是,加载的图像缓冲区(imageBuf)应该被划分为与DICOM中的帧数相同的多个部分,并使用每个部分来构建图像。那能做到吗 int imageWidth = 880; int imageHeight = 635; NSString *dicomPath = [[[[NSBundle mainBundle] resourcePath]

我可以很好地阅读单帧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];
int-imageWidth=880;
int imageHeight=635;
NSString*dicomPath=[[[[NSBundle mainBundle]resourcePath]stringByAppendingString:@/“]stringByAppendingString:@“您的dicom文件名”];
const char*c_dicomPath=[dicomPath UTF8String];
typedef无符号字符InputPixelType;
常量无符号整数InputDimension=3;
typedef itk::ImageInputImageType;
typedef itk::ImageFileReaderReaderType;
ReaderType::Pointer reader=ReaderType::New();
读卡器->设置文件名(c_dicomPath);
类型定义itk::GDCMImageIO ImageIOType;
ImageIOType::指针gdcmImageIO=ImageIOType::New();
读卡器->设置图像IO(gdcmImageIO);
InputPixelType*imageBuf=(InputPixelType*)malloc(sizeof(InputPixelType)*图像高度*图像宽度*3);
阅读器->更新();
//获取dicom图像
memset(imageBuf,0,sizeof(InputPixelType)*图像高度*图像宽度*3);
gdcmImageIO->读取(imageBuf);
CGColorSpaceRef colorspace=CGColorSpaceCreateDeviceRGB();
CGDataProviderRef provider=CGDataProviderCreateWithData(无,imageBuf,imageWidth*imageHeight*3*sizeof(InputPixelType),无);
CGImageRef imageRef=CGImageCreate(imageWidth,//宽度
imageHeight,//高度
8,//大小\u t比特组件,
24,//大小\u t比特像素,
imageWidth*sizeof(InputPixelType)*3,//size\u t bytesPerRow,
colorspace,//CGCOLORSPACTEREF空间,
kCGBitmapByteOrderDefault,//CGBitmapInfo-bitmapInfo,
provider,//CGDataProviderRef provider,
nil,//const CGFloat*解码,
不,//布尔应该是中间的,
KCgrenderingEntentDefault//CGColorRenderingIntent意图
);
//这是dicom文件中的dicom图像解码
UIImage*dicomImage=[[UIImage alloc]initWithCGImage:imageRef比例:1.0方向:UIImageOrientationUp];

您尝试过itk::ImageSeriesReader吗?

您尝试过itk::ImageSeriesReader吗