[Insight-users] How to Decode MultiFrame DICOM Image by Using ITK

Terran Wu Terran.Wu at semt.com.cn
Tue Mar 6 22:41:47 EST 2012


Hi All,

I am currently write a application that reading and display DICOM image on IPAD2. Now I am able to read and decode DICOM files that contain only one frame, here is the code(using ITK LIB and object-c) that decode one frame DICOM file on IPAD:

//assume that the size of image is 880*635

    int imageWidth = 880;

    int imageHeight = 635;



    NSString *dicomPath = [[[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/"] stringByAppendingString:@"dicomfilename"];

    const char *c_dicomPath = [dicomPath UTF8String];



    typedef unsigned char InputPixelType;

    const unsigned int InputDimension = 2;

    typedef itk::Image< InputPixelType, InputDimension > InputImageType;



    typedef itk::ImageSeriesReader< InputImageType > ReaderType;

    ReaderType::Pointer reader = ReaderType::New();

    reader->SetFileName(c_dicomPath);



    typedef itk::GDCMImageIO ImageIOType;

    ImageIOType::Pointer gdcmImageIO = ImageIOType::New();



    reader->SetImageIO(gdcmImageIO);



    int frame_num = 1;

    InputPixelType *imageBuf = new InputPixelType[imageHeight*imageWidth*3*frame_num];



    try

    {

        reader->Update();

        printf("image size in bytes = %d\n", gdcmImageIO->GetImageSizeInBytes());

        printf("image size in pixel = %d\n", gdcmImageIO->GetImageSizeInPixels());

        printf("image size in Components = %d\n", gdcmImageIO->GetImageSizeInComponents());

        printf("pixel stride = %d\n", gdcmImageIO->GetPixelStride());

        printf("Dimensions = %d\n", gdcmImageIO->GetNumberOfDimensions());

        printf("file type = %d\n", gdcmImageIO->GetFileType());

        std::cout << "file type = " << gdcmImageIO->GetFileTypeAsString(gdcmImageIO->GetFileType()) << std::endl;

        std::cout << "Pixel type = " << gdcmImageIO->GetPixelTypeAsString(gdcmImageIO->GetPixelType()) << std::endl;

        std::cout << "Byte order = " << gdcmImageIO->GetByteOrderAsString(gdcmImageIO->GetByteOrder()) << std::endl;

        gdcmImageIO->GetPixelType();

    }

    catch (itk::ExceptionObject & e)

    {

        std::cerr << "exception in file reader " << std::endl; std::cerr << e << std::endl;

        exit(EXIT_FAILURE);

    }



    //get dicom image

    memset(imageBuf, 0, sizeof(InputPixelType)*imageHeight*imageWidth*3*frame_num);

    gdcmImageIO->Read(imageBuf);//get decoded image data



    CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();

    CGDataProviderRef provider = CGDataProviderCreateWithData(nil, imageBuf, imageWidth*imageHeight*3, 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

                                        );

    UIImage *dicomImage = [[UIImage alloc] initWithCGImage:imageRef scale:1.0 orientation:UIImageOrientationUp];//here is the decoded image

But I don't know how to decode and read a DICOM file that has MultiFrame, and how to get the decoded image data to display them on IPAD screen?

Can anybody help me on this issue?

 Thank you very much!

--
Best Regards
Terran Wu
巫幪

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20120307/09faca83/attachment.htm>


More information about the Insight-users mailing list