简体   繁体   中英

How to Extract Pixel data from DIcom image to view it in a n iPhone

I have been using the following code to read a dicom image using DCMTK frame work to display it in a UIImage view.

NSString *dcmFilename   = [[NSBundle mainBundle] pathForResource:@"1" ofType:@"dcm"];
 const void* buffer = dcmFilename;


// Set the dimensions of the current context
size_t width = 250; // set manually, but correct
size_t height = 252;

// 1 byte per component
size_t bitsPerComponent = 8;





bitsPerComponent *= 2; // short = 2 byte

size_t bitsPerPixel, bytesPerRow;
CGColorSpaceRef colorSpace;
CGBitmapInfo bitmapInfo;
CGDataProviderRef theDataProvider;
CFDataRef theDataReference;
bool shouldInterpolate = NO;
CGColorRenderingIntent theIntent;


bitsPerPixel = bitsPerComponent * 1; // because of grayscale image
colorSpace = CGColorSpaceCreateDeviceGray();
bitmapInfo = kCGImageAlphaNone | kCGBitmapByteOrder32Big;

// cg data provider to build the cg image
const UInt8* rawData = static_cast<const UInt8*>(buffer);

// For some reason initiating a CGImage uses BITS per pixel, so we need to divide by 8 to get BYTES
// per pixel
bytesPerRow = (bitsPerPixel/8) * width;

theDataReference = CFDataCreate(NULL,
                                rawData,
                                (bytesPerRow*height));

theDataProvider = CGDataProviderCreateWithCFData(theDataReference);





// Finally create the image reference
CGImageRef theImageRef = CGImageCreate(width,
                                       height,
                                       bitsPerComponent,
                                       bitsPerPixel,
                                       bytesPerRow,
                                       colorSpace,
                                       bitmapInfo,
                                       theDataProvider,
                                       nil,
                                       shouldInterpolate,
                                       theIntent);


// Construct an output image
UIImage *myImage = [UIImage imageWithCGImage:(theImageRef)];
NSLog(@"image-- %@", myImage);
patientImageView.image = myImage;

I am getting the output as this. where i went wrong in processing the dcm image??? 在此处输入图片说明

My guess is the image is compressed. DCMTK, by default, only supports some forms of compression. JPEG2000, for example, is not supported by default. Check the transfer syntax of the image to see if it is a compression format DCMTK supports. See here for more information about transfer syntax.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM