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.Answer1:
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 <a href="http://www.insight-journal.org/browse/publication/755" rel="nofollow">ITK</a>.
Here's how I got it to compile for iOS:<ol><li>Downloaded source from sourceforge, installed cmake via ports. You'll need a recent version of cmake (I'm using 2.8.2)</li> <li>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 <strong>ccmake -GXCode ../gdcm-2.0.17/</strong> 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.</li> <li>Follow the directions in the ITK paper on changing the build options (step #7 on page 4).</li> <li>Then link GDCM into your project using the excellent instructions at <a href="http://www.clintharris.net/2009/iphone-app-shared-libraries/" rel="nofollow">Clint Harris' blog</a></li> <li>When you're setting up the header search path in your project to GDCM - you have to enter two paths: <em>blah</em>/gdcm-2.0.17/Source/** and <em>blah</em>/gdcmbin/**. The trailing '/Source' on the first path is necessary - otherwise you get headers that aren't appropriate for your architecture.</li> <li>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 :-).</li> </ol>
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)Answer2:
If you want to find DICOM software, look at <a href="http://idoimaging.com" rel="nofollow">idoimaging.com</a>, 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:<ul><li>input format: DICOM</li> <li>platform: Macintosh</li> <li>language: C</li> </ul>
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.