<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>
&nbsp;<BR>
First&nbsp;of all, thank you so much!!!<BR>
&nbsp;<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&nbsp;^_^<BR>
&nbsp;<BR>
here is my code, hope to help someone who meets the same question.<BR>
--code--<BR>
&nbsp;<BR>
int main( )<BR>{<BR>
&nbsp;typedef signed short&nbsp;&nbsp;&nbsp; PixelType;<BR>&nbsp;const unsigned int&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dimension = 3;<BR>
&nbsp;typedef itk::Image&lt; PixelType, Dimension &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ImageType;<BR>
&nbsp;typedef itk::ImageSeriesReader&lt; ImageType &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ReaderType;<BR>&nbsp;ReaderType::Pointer reader1 = ReaderType::New();<BR>
<BR>&nbsp;typedef itk::GDCMImageIO&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ImageIOType;<BR>&nbsp;ImageIOType::Pointer dicomIO = ImageIOType::New();<BR>
&nbsp;reader1-&gt;SetImageIO( dicomIO );<BR>
&nbsp;typedef itk::GDCMSeriesFileNames NamesGeneratorType;<BR>&nbsp;NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();<BR>
&nbsp;nameGenerator-&gt;SetUseSeriesDetails( true );<BR>&nbsp;nameGenerator-&gt;SetDirectory("d:/data/feet");<BR>
<BR>&nbsp;try<BR>&nbsp;{ <BR>&nbsp;&nbsp;typedef std::vector&lt; std::string &gt;&nbsp;&nbsp;&nbsp; SeriesIdContainer;<BR>
&nbsp;&nbsp;const SeriesIdContainer &amp; seriesUID = nameGenerator-&gt;GetSeriesUIDs();<BR>
&nbsp;&nbsp;SeriesIdContainer::const_iterator seriesItr = seriesUID.begin();<BR>&nbsp;&nbsp;SeriesIdContainer::const_iterator seriesEnd = seriesUID.end();<BR>&nbsp;&nbsp;while( seriesItr != seriesEnd )<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;std::cout &lt;&lt; seriesItr-&gt;c_str() &lt;&lt; std::endl;<BR>&nbsp;&nbsp;&nbsp;seriesItr++;<BR>&nbsp;&nbsp;}<BR>
<BR>&nbsp;&nbsp;std::string seriesIdentifier;<BR>
&nbsp;&nbsp;seriesIdentifier = seriesUID.begin()-&gt;c_str();<BR>
&nbsp;&nbsp;std::cout &lt;&lt; std::endl &lt;&lt; std::endl;<BR>&nbsp;&nbsp;std::cout &lt;&lt; "Now reading series: " &lt;&lt; std::endl &lt;&lt; std::endl;<BR>&nbsp;&nbsp;std::cout &lt;&lt; seriesIdentifier &lt;&lt; std::endl;<BR>&nbsp;&nbsp;std::cout &lt;&lt; std::endl &lt;&lt; std::endl;<BR>
<BR>&nbsp;&nbsp;typedef std::vector&lt; std::string &gt;&nbsp;&nbsp; FileNamesContainer;<BR>&nbsp;&nbsp;FileNamesContainer fileNames;<BR>
&nbsp;&nbsp;fileNames = nameGenerator-&gt;GetFileNames( seriesIdentifier );<BR>
<BR>&nbsp;&nbsp;reader1-&gt;SetFileNames( fileNames );<BR>
<BR>&nbsp;&nbsp;try<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;reader1-&gt;Update();<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;catch (itk::ExceptionObject &amp;ex)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;std::cout &lt;&lt; ex &lt;&lt; std::endl;<BR>&nbsp;&nbsp;&nbsp;return EXIT_FAILURE;<BR>&nbsp;&nbsp;}<BR>
&nbsp;}<BR>&nbsp;catch (itk::ExceptionObject &amp;ex)<BR>&nbsp;{<BR>&nbsp;&nbsp;std::cout &lt;&lt; ex &lt;&lt; std::endl;<BR>&nbsp;&nbsp;return EXIT_FAILURE;<BR>&nbsp;}<BR>&nbsp;return EXIT_FAILURE;<BR>
}<BR>&nbsp;<BR>
--code--<BR>
&nbsp;<BR>
thanks again !<BR>
&nbsp;<BR>
Regards,<BR>
&nbsp;<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>&nbsp;<BR>Here I&nbsp;met a problem.<BR>&nbsp;<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>&nbsp;<BR>However, I can not deal with the reading methods, could anyone help me, please? Or just show me some examples.<BR>&nbsp;<BR>Thanks a lot!<BR>&nbsp;<BR>Regards,<BR>&nbsp;<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>&nbsp;&nbsp; &nbsp;typedef itk::GDCMImageIO ImageIO;<BR>&nbsp;&nbsp; &nbsp;typedef itk::Image&lt;int,2&gt; Image2D;<BR>&nbsp;&nbsp; &nbsp;typedef itk::Image&lt;int,3&gt; Image3D;<BR>&nbsp;&nbsp; &nbsp;typedef itk::JoinSeriesImageFilter&lt;Image2D,Image3D&gt; Joiner;<BR>&nbsp;&nbsp; &nbsp;typedef itk::ImageFileReader&lt;Image2D&gt; Reader;<BR>&nbsp;&nbsp; &nbsp;typedef itk::RegionOfInterestImageFilter&lt;Image2D,Image2D&gt; RegionExtractor;<BR><BR>&nbsp;&nbsp; &nbsp;// Set up the desired region for each of the slices.<BR>&nbsp;&nbsp; &nbsp;Image2D::RegionType region;<BR>&nbsp;&nbsp; &nbsp;Image2D::IndexType index = {{m_volumeChoice.minX, m_volumeChoice.minY}};<BR>&nbsp;&nbsp; &nbsp;Image2D::SizeType size = {{m_volumeChoice.maxX + 1 - m_volumeChoice.minX, m_volumeChoice.maxY + 1 - m_volumeChoice.minY}};<BR>&nbsp;&nbsp; &nbsp;region.SetIndex(index);<BR>&nbsp;&nbsp; &nbsp;region.SetSize(size);<BR><BR>&nbsp;&nbsp; &nbsp;std::vector&lt;std::string&gt; imageFilenames = m_dicomdir-&gt;image_filenames(m_volumeChoice.patientKey, m_volumeChoice.studyKey, m_volumeChoice.seriesKey);<BR>&nbsp;&nbsp; &nbsp;std::vector&lt;Image2D::Pointer&gt; images(imageFilenames.size());<BR>&nbsp;&nbsp; &nbsp;for(int i=m_volumeChoice.minZ; i&lt;=m_volumeChoice.maxZ; ++i)<BR>&nbsp;&nbsp; &nbsp;{<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;std::string imageFilename = m_volumeChoice.filePrefix + imageFilenames[i];<BR><BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if(!is_aborted())<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;set_progress(i - m_volumeChoice.minZ);<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;set_status("Loading image " + imageFilename + "...");<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else return;<BR><BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;// Load the image.<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;Reader::Pointer reader = Reader::New();<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;reader-&gt;SetFileName(imageFilename);<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;ImageIO::Pointer gdcmImageIO = ImageIO::New();<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;reader-&gt;SetImageIO(gdcmImageIO);<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;reader-&gt;Update();<BR><BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;// Extract the relevant sub-region.<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;RegionExtractor::Pointer extractor = RegionExtractor::New();<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;extractor-&gt;SetInput(reader-&gt;GetOutput());<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;extractor-&gt;SetRegionOfInterest(region);<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;extractor-&gt;Update();<BR><BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;// Store the image.<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;images[i] = extractor-&gt;GetOutput();<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;images[i]-&gt;SetMetaDataDictionary(reader-&gt;GetMetaDataDictionary());<BR>&nbsp;&nbsp; &nbsp;}<BR><BR>&nbsp;&nbsp; &nbsp;// Get the window centre and width if they haven't been explicitly specified by the user.<BR>&nbsp;&nbsp; &nbsp;if(m_volumeChoice.windowSettings.unspecified())<BR>&nbsp;&nbsp; &nbsp;{<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;std::string windowCentreStr = read_header_field(images[m_volumeChoice.minZ], "0028|1050");<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;std::string windowWidthStr = read_header_field(images[m_volumeChoice.minZ], "0028|1051");<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;std::string validChars = "-0123456789";<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;windowCentreStr = windowCentreStr.substr(0, windowCentreStr.find_first_not_of(validChars));<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;windowWidthStr = windowWidthStr.substr(0, windowWidthStr.find_first_not_of(validChars));<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;double windowCentre = lexical_cast&lt;double&gt;(windowCentreStr);<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;double windowWidth = lexical_cast&lt;double&gt;(windowWidthStr);<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;m_volumeChoice.windowSettings = WindowSettings(windowCentre, windowWidth);<BR>&nbsp;&nbsp; &nbsp;}<BR><BR>&nbsp;&nbsp; &nbsp;// Make the images into a volume.<BR>&nbsp;&nbsp; &nbsp;Joiner::Pointer joiner = Joiner::New();<BR><BR>&nbsp;&nbsp; &nbsp;double minSliceLocation = 0;<BR>&nbsp;&nbsp; &nbsp;try&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; { minSliceLocation = lexical_cast&lt;double&gt;(read_header_field(images[m_volumeChoice.minZ], "0020|1041")); }<BR>&nbsp;&nbsp; &nbsp;catch(bad_lexical_cast&amp;)&nbsp;&nbsp; &nbsp;{ throw Exception("The SliceLocation value for the slice was not of the appropriate type"); }<BR>&nbsp;&nbsp; &nbsp;joiner-&gt;SetOrigin(minSliceLocation);<BR><BR>&nbsp;&nbsp; &nbsp;double sliceThickness = 0;<BR>&nbsp;&nbsp; &nbsp;if(m_volumeChoice.minZ + 1 &lt;= m_volumeChoice.maxZ)<BR>&nbsp;&nbsp; &nbsp;{<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;try<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;double nextSliceLocation = lexical_cast&lt;double&gt;(read_header_field(images[m_volumeChoice.minZ+1], "0020|1041"));<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;sliceThickness = fabs(nextSliceLocation - minSliceLocation);<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;catch(bad_lexical_cast&amp;)&nbsp;&nbsp; &nbsp;{}<BR>&nbsp;&nbsp; &nbsp;}<BR>&nbsp;&nbsp; &nbsp;if(sliceThickness == 0)<BR>&nbsp;&nbsp; &nbsp;{<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;try&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; { sliceThickness = lexical_cast&lt;double&gt;(read_header_field(images[m_volumeChoice.minZ], "0018|0050")); }<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;catch(bad_lexical_cast&amp;)&nbsp;&nbsp; &nbsp;{ throw Exception("The SliceThickness value for the slice was not of the appropriate type"); }<BR>&nbsp;&nbsp; &nbsp;}<BR>&nbsp;&nbsp; &nbsp;joiner-&gt;SetSpacing(sliceThickness);<BR><BR>&nbsp;&nbsp; &nbsp;for(int i=m_volumeChoice.minZ; i&lt;=m_volumeChoice.maxZ; ++i) joiner-&gt;PushBackInput(images[i]);<BR>&nbsp;&nbsp; &nbsp;joiner-&gt;Update();<BR><BR>&nbsp;&nbsp; &nbsp;Image3D::Pointer volumeImage = joiner-&gt;GetOutput();<BR>&nbsp;&nbsp; &nbsp;m_volume.reset(new DICOMVolume(volumeImage));<BR><BR>&nbsp;&nbsp; &nbsp;set_finished();<BR>}<BR>catch(std::exception&amp; e)<BR>{<BR>&nbsp;&nbsp; &nbsp;abort();<BR>&nbsp;&nbsp; &nbsp;set_status(e.what());<BR>}                                               <br /><hr />更多热辣资讯尽在新版MSN首页! <a href='http://cn.msn.com/' target='_new'>立刻访问!</a></body>
</html>