<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
--></style>
</head>
<body class='hmmessage'>
Hi Stu,<BR>
<BR>
First of all, thank you so much!!!<BR>
<BR>
I tried the way in the ITK Software Guide, and it works!!!<BR>
Your codes work as well, however, it's a little difficult to understand ^_^<BR>
<BR>
here is my code, hope to help someone who meets the same question.<BR>
--code--<BR>
<BR>
int main( )<BR>{<BR>
typedef signed short PixelType;<BR> const unsigned int Dimension = 3;<BR>
typedef itk::Image< PixelType, Dimension > ImageType;<BR>
typedef itk::ImageSeriesReader< ImageType > ReaderType;<BR> ReaderType::Pointer reader1 = ReaderType::New();<BR>
<BR> typedef itk::GDCMImageIO ImageIOType;<BR> ImageIOType::Pointer dicomIO = ImageIOType::New();<BR>
reader1->SetImageIO( dicomIO );<BR>
typedef itk::GDCMSeriesFileNames NamesGeneratorType;<BR> NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();<BR>
nameGenerator->SetUseSeriesDetails( true );<BR> nameGenerator->SetDirectory("d:/data/feet");<BR>
<BR> try<BR> { <BR> typedef std::vector< std::string > SeriesIdContainer;<BR>
const SeriesIdContainer & seriesUID = nameGenerator->GetSeriesUIDs();<BR>
SeriesIdContainer::const_iterator seriesItr = seriesUID.begin();<BR> SeriesIdContainer::const_iterator seriesEnd = seriesUID.end();<BR> while( seriesItr != seriesEnd )<BR> {<BR> std::cout << seriesItr->c_str() << std::endl;<BR> seriesItr++;<BR> }<BR>
<BR> std::string seriesIdentifier;<BR>
seriesIdentifier = seriesUID.begin()->c_str();<BR>
std::cout << std::endl << std::endl;<BR> std::cout << "Now reading series: " << std::endl << std::endl;<BR> std::cout << seriesIdentifier << std::endl;<BR> std::cout << std::endl << std::endl;<BR>
<BR> typedef std::vector< std::string > FileNamesContainer;<BR> FileNamesContainer fileNames;<BR>
fileNames = nameGenerator->GetFileNames( seriesIdentifier );<BR>
<BR> reader1->SetFileNames( fileNames );<BR>
<BR> try<BR> {<BR> reader1->Update();<BR> }<BR> catch (itk::ExceptionObject &ex)<BR> {<BR> std::cout << ex << std::endl;<BR> return EXIT_FAILURE;<BR> }<BR>
}<BR> catch (itk::ExceptionObject &ex)<BR> {<BR> std::cout << ex << std::endl;<BR> return EXIT_FAILURE;<BR> }<BR> return EXIT_FAILURE;<BR>
}<BR> <BR>
--code--<BR>
<BR>
thanks again !<BR>
<BR>
Regards,<BR>
<BR>
Danile<BR>
<HR id=stopSpelling>
Date: Fri, 4 Jun 2010 11:53:34 +0100<BR>From: itk@gxstudios.net<BR>To: hawkingyy@hotmail.com<BR>CC: insight-users@itk.org<BR>Subject: Re: [Insight-users] How can I read DICOM files (more than 2 slices) by using ITK ?<BR><BR>noc wrote:
<BLOCKQUOTE cite=mid:SNT138-w426C1BDEF51315A1740D37BAD20@phx.gbl>
<STYLE>
.ExternalClass .ecxhmmessage P
{padding:0px;}
.ExternalClass body.ecxhmmessage
{font-size:10pt;font-family:Verdana;}
</STYLE>
Hi all,<BR> <BR>Here I met a problem.<BR> <BR>I wanna use ITK to read many slices of DICOM files, and make them go though the BilateralImageFilter,<BR>then, do marching cubes.<BR> <BR>However, I can not deal with the reading methods, could anyone help me, please? Or just show me some examples.<BR> <BR>Thanks a lot!<BR> <BR>Regards,<BR> <BR>Danile<BR></BLOCKQUOTE><BR>Not sure if this will help or not (hope so), but the way I currently read a DICOM series looks like the below. It assumes that you've loaded in the set of image filenames you want to load from elsewhere (specifically, from a DICOMDIR file, for which I had to use the gdcm library separately from ITK). If you're doing it a different way, you can just specify imageFilenames explicitly. For an alternative method, see 7.11 in the ITK Software Guide (unless it's been updated since I downloaded my copy).<BR><BR>Cheers,<BR>Stu<BR><BR>void DICOMVolumeLoader::execute()<BR>try<BR>{<BR> typedef itk::GDCMImageIO ImageIO;<BR> typedef itk::Image<int,2> Image2D;<BR> typedef itk::Image<int,3> Image3D;<BR> typedef itk::JoinSeriesImageFilter<Image2D,Image3D> Joiner;<BR> typedef itk::ImageFileReader<Image2D> Reader;<BR> typedef itk::RegionOfInterestImageFilter<Image2D,Image2D> RegionExtractor;<BR><BR> // Set up the desired region for each of the slices.<BR> Image2D::RegionType region;<BR> Image2D::IndexType index = {{m_volumeChoice.minX, m_volumeChoice.minY}};<BR> Image2D::SizeType size = {{m_volumeChoice.maxX + 1 - m_volumeChoice.minX, m_volumeChoice.maxY + 1 - m_volumeChoice.minY}};<BR> region.SetIndex(index);<BR> region.SetSize(size);<BR><BR> std::vector<std::string> imageFilenames = m_dicomdir->image_filenames(m_volumeChoice.patientKey, m_volumeChoice.studyKey, m_volumeChoice.seriesKey);<BR> std::vector<Image2D::Pointer> images(imageFilenames.size());<BR> for(int i=m_volumeChoice.minZ; i<=m_volumeChoice.maxZ; ++i)<BR> {<BR> std::string imageFilename = m_volumeChoice.filePrefix + imageFilenames[i];<BR><BR> if(!is_aborted())<BR> {<BR> set_progress(i - m_volumeChoice.minZ);<BR> set_status("Loading image " + imageFilename + "...");<BR> }<BR> else return;<BR><BR> // Load the image.<BR> Reader::Pointer reader = Reader::New();<BR> reader->SetFileName(imageFilename);<BR> ImageIO::Pointer gdcmImageIO = ImageIO::New();<BR> reader->SetImageIO(gdcmImageIO);<BR> reader->Update();<BR><BR> // Extract the relevant sub-region.<BR> RegionExtractor::Pointer extractor = RegionExtractor::New();<BR> extractor->SetInput(reader->GetOutput());<BR> extractor->SetRegionOfInterest(region);<BR> extractor->Update();<BR><BR> // Store the image.<BR> images[i] = extractor->GetOutput();<BR> images[i]->SetMetaDataDictionary(reader->GetMetaDataDictionary());<BR> }<BR><BR> // Get the window centre and width if they haven't been explicitly specified by the user.<BR> if(m_volumeChoice.windowSettings.unspecified())<BR> {<BR> std::string windowCentreStr = read_header_field(images[m_volumeChoice.minZ], "0028|1050");<BR> std::string windowWidthStr = read_header_field(images[m_volumeChoice.minZ], "0028|1051");<BR> std::string validChars = "-0123456789";<BR> windowCentreStr = windowCentreStr.substr(0, windowCentreStr.find_first_not_of(validChars));<BR> windowWidthStr = windowWidthStr.substr(0, windowWidthStr.find_first_not_of(validChars));<BR> double windowCentre = lexical_cast<double>(windowCentreStr);<BR> double windowWidth = lexical_cast<double>(windowWidthStr);<BR> m_volumeChoice.windowSettings = WindowSettings(windowCentre, windowWidth);<BR> }<BR><BR> // Make the images into a volume.<BR> Joiner::Pointer joiner = Joiner::New();<BR><BR> double minSliceLocation = 0;<BR> try { minSliceLocation = lexical_cast<double>(read_header_field(images[m_volumeChoice.minZ], "0020|1041")); }<BR> catch(bad_lexical_cast&) { throw Exception("The SliceLocation value for the slice was not of the appropriate type"); }<BR> joiner->SetOrigin(minSliceLocation);<BR><BR> double sliceThickness = 0;<BR> if(m_volumeChoice.minZ + 1 <= m_volumeChoice.maxZ)<BR> {<BR> try<BR> {<BR> double nextSliceLocation = lexical_cast<double>(read_header_field(images[m_volumeChoice.minZ+1], "0020|1041"));<BR> sliceThickness = fabs(nextSliceLocation - minSliceLocation);<BR> }<BR> catch(bad_lexical_cast&) {}<BR> }<BR> if(sliceThickness == 0)<BR> {<BR> try { sliceThickness = lexical_cast<double>(read_header_field(images[m_volumeChoice.minZ], "0018|0050")); }<BR> catch(bad_lexical_cast&) { throw Exception("The SliceThickness value for the slice was not of the appropriate type"); }<BR> }<BR> joiner->SetSpacing(sliceThickness);<BR><BR> for(int i=m_volumeChoice.minZ; i<=m_volumeChoice.maxZ; ++i) joiner->PushBackInput(images[i]);<BR> joiner->Update();<BR><BR> Image3D::Pointer volumeImage = joiner->GetOutput();<BR> m_volume.reset(new DICOMVolume(volumeImage));<BR><BR> set_finished();<BR>}<BR>catch(std::exception& e)<BR>{<BR> abort();<BR> set_status(e.what());<BR>}                                            <br /><hr />更多热辣资讯尽在新版MSN首页! <a href='http://cn.msn.com/' target='_new'>立刻访问!</a></body>
</html>