<html>
  <head>

  </head>
  <body style="margin-bottom: 1px; margin-top: 4px; font-weight: normal; line-height: normal; font-family: Times New Roman; font-style: normal; font-size: 16pt; font-variant: normal; margin-left: 4px; margin-right: 4px">
    <p style="margin-top: 0; margin-bottom: 0">
      <font size="5" face="Times New Roman">Kumis&#44;</font>    </p>
<br>      
    <p style="margin-top: 0; margin-bottom: 0">
      <font size="5" face="Times New Roman">Unsigned short is a 16 bit integer on my Windows 7 machine. &nbsp;Char is 8 bit&#44; so you are likely truncating your data. &nbsp;What are the actual data values like&#63; </font>    </p>
<br>      
    <p style="margin-top: 0; margin-bottom: 0">
      <font size="5" face="Times New Roman">Kent</font>    </p>
<br>      
    <p style="margin-top: 0; margin-bottom: 0">
      <br>
      <br>
      &gt;&gt;&gt; kumis &lt;kkumis@gmail.com&gt; 5/8/2012 10:23 PM &gt;&gt;&gt;<br>Hi everyone&#44;<br>I&#39;m trying to do some labeling operations on an DICOM CT image. To do this I<br>need &#40;I suppose I need&#41; cast the DICOM signed short pixel format to unsigned<br>char. I want perform this operation after initial thresholding &#40; the<br>threshold operation is working on signed short type&#41; but I found a strange<br>problem here. When I use the CastImageFilter to convert singed short to<br>unsigned char the output image is completly dark/empty. Could You give me<br>some advice how to deal with this problem&#63; You can find the code below:<br><br><br>typedef itk::Image&lt;signed short &#44;2&gt; ImageType&#59;<br>typedef itk::Image&lt;unsigned char&#44; 2&gt;&#160;&#32;UCImageType&#59;<br><br>int main&#40; int argc&#44; char&#42; argv&#91;&#93; &#41;&#123;<br><br>typedef itk::ImageFileReader&lt;ImageType&gt; ImageFileReaderType&#59;<br>ImageFileReaderType::Pointer imageReader &#61; ImageFileReaderType::New&#40;&#41;&#59;<br>imageReader-&gt;SetFileName&#40;argv&#91;1&#93;&#41;&#59;<br>typedef itk::GDCMImageIO ImageIOType&#59;<br>ImageIOType::Pointer gdcmIO &#61; ImageIOType::New&#40;&#41;&#59;<br>imageReader-&gt;SetImageIO&#40;gdcmIO&#41;&#59;<br><br><br>int lowerThreshold &#61; atoi&#40;argv&#91;2&#93;&#41;&#59;<br>int upperThreshold &#61; atoi&#40;argv&#91;3&#93;&#41;&#59;<br><br>if&#40;lowerThreshold&gt;upperThreshold&#41;&#123;<br>std::cout&lt;&lt;&quot;incorrect threshold values&quot;&lt;&lt;&quot;&#92;n&quot;&#59;<br>return EXIT_FAILURE&#59;<br>&#125;<br><br>typedef itk::BinaryThresholdImageFilter&lt;ImageType&#44;ImageType&gt;<br>ThresholdImageFilterType&#59;<br>ThresholdImageFilterType::Pointer thresholdFilter &#61;<br>ThresholdImageFilterType::New&#40;&#41;&#59;<br>thresholdFilter-&gt;SetInput&#40;imageReader-&gt;GetOutput&#40;&#41;&#41;&#59;<br>thresholdFilter-&gt;SetLowerThreshold&#40;lowerThreshold&#41;&#59;<br>thresholdFilter-&gt;SetUpperThreshold&#40;upperThreshold&#41;&#59;<br>thresholdFilter-&gt;SetInsideValue&#40;1&#41;&#59;<br>thresholdFilter-&gt;SetOutsideValue&#40;0&#41;&#59;<br>thresholdFilter-&gt;Update&#40;&#41;&#59;<br><br>typedef itk::CastImageFilter&lt;ImageType&#44;UCImageType&gt;<br>CastImageFilterSS2UCType&#59;<br>CastImageFilterSS2UCType::Pointer castImageFilterSS2UC &#61;<br>CastImageFilterSS2UCType::New&#40;&#41;&#59;<br>castImageFilterSS2UC-&gt;SetInput&#40;thresholdFilter-&gt;GetOutput&#40;&#41;&#41;&#59;<br><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#32;QuickView viewer&#59;<br>viewer.AddImage&#40;imageReader-&gt;GetOutput&#40;&#41;&#41;&#59;<br>viewer.AddImage&#40;thresholdFilter-&gt;GetOutput&#40;&#41;&#41;&#59;<br>viewer.AddImage&#40;castImageFilterSS2UC-&gt;GetOutput&#40;&#41;&#41;&#59;<br>viewer.Visualize&#40;&#41;&#59;<br><br>return EXIT_SUCCESS&#59;<br>&#125;<br><br><br>--<br>View this message in context: <a href="http://itk-insight-users.2283740.n2.nabble.com/Problems-with-casting-image-types-tp7541500.html">http://itk-insight-users.2283740.n2.nabble.com/Problems-with-casting-image-types-tp7541500.html</a><br>Sent from the ITK Insight Users mailing list archive at Nabble.com.<br>_____________________________________<br>Powered by www.kitware.com<br><br>Visit other Kitware open-source projects at<br><a href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</a><br><br>Kitware offers ITK Training Courses&#44; for more information visit:<br><a href="http://www.kitware.com/products/protraining.php">http://www.kitware.com/products/protraining.php</a><br><br>Please keep messages on-topic and check the ITK FAQ at:<br><a href="http://www.itk.org/Wiki/ITK_FAQ">http://www.itk.org/Wiki/ITK_FAQ</a><br><br>Follow this link to subscribe/unsubscribe:<br><a href="http://www.itk.org/mailman/listinfo/insight-users">http://www.itk.org/mailman/listinfo/insight-users</a><br>
    </p>
  </body>
</html>