<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=GB2312" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
noc wrote:
<blockquote cite="mid:SNT138-w426C1BDEF51315A1740D37BAD20@phx.gbl"
 type="cite">
  <style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
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>
}
</body>
</html>