-->

How do I extract pixel data from DICOM files on iO

2019-01-14 14:48发布

问题:

Does anyone know how I can extract the pixel data from a DICOM file and pass it to an image viewer on iOS?

Sorry if this is a simple question, but it seems to be a major component to a huge can of worms I have opened.

回答1:

I'm using GDCM on iOS. I haven't pushed it very hard yet but it's working well so far. I basically followed the directions for hacking XCode projects to run in iOS in this excellent article on ITK.

Here's how I got it to compile for iOS:

  1. Downloaded source from sourceforge, installed cmake via ports. You'll need a recent version of cmake (I'm using 2.8.2)
  2. If the source is in a folder called gdcm-2.0.17/, then create another directory at that level (say gdcmbin), cd to that directory, and enter ccmake -GXCode ../gdcm-2.0.17/ in the terminal window. This creates the XCode project. When I did this I didn't create any of the example programs or create shared libraries (which won't work in iOS). Just run the defaults.
  3. Follow the directions in the ITK paper on changing the build options (step #7 on page 4).
  4. Then link GDCM into your project using the excellent instructions at Clint Harris' blog
  5. When you're setting up the header search path in your project to GDCM - you have to enter two paths: blah/gdcm-2.0.17/Source/** and blah/gdcmbin/**. The trailing '/Source' on the first path is necessary - otherwise you get headers that aren't appropriate for your architecture.
  6. One glitch (annoying but haven't spent the time to figure it out yet): you get a bunch of linking errors when you switch from simulator to device (or vice versa). This is because the gdcm project doesn't put the outputs into different directories for different targets. So - run a clean and rebuild in the gdcm project when you're switching. I'll probably get annoyed by this soon enough to change it :-).

Here's a rough snippet of how you'd call the library and put the results in an Objective-C dictionary:

NSMutableDictionary * imageDictionary = [[NSMutableDictionary alloc] initWithCapacity:40];
// The output of gdcm::Reader is a gdcm::File
gdcm::File &file = reader.GetFile();

// the dataset is the the set of element we are interested in:
gdcm::DataSet &ds = file.GetDataSet();
const Tag studyInstance(0x0020,0x000d); // Study Instance UID
const DataElement &dicomVal = ds.GetDataElement(studyInstance);
std::string stringVal( dicomVal.GetByteValue()->GetPointer(), dicomVal.GetByteValue()->GetLength() );
NSString *val = [NSString stringWithCString:stringVal.c_str() encoding:[NSString defaultCStringEncoding]];
[imageDictionary setObject:val forKey:@"studyInstanceUID"];

(Note: this is in an *.mm file that mixes C++ and ObjectiveC)



回答2:

If you want to find DICOM software, look at idoimaging.com, a clearinghouse for medical imaging software. You can choose your platform, input format, output format, language, etc. iOS isn't listed as a format, but much of the software listed there is available with source, useful in library form, and available for MacOS X. For example, I selected:

  • input format: DICOM
  • platform: Macintosh
  • language: C

and found several packages. Given the similarities between MacOS and iOS and the fact that some of these are cross-platform with source included, it shouldn't be too difficult to get one of them working on iOS.



标签: iphone ios dicom