<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,</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. Char is 8 bit, so you are likely truncating your data. What are the actual data values like? </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>
>>> kumis <kkumis@gmail.com> 5/8/2012 10:23 PM >>><br>Hi everyone,<br>I'm trying to do some labeling operations on an DICOM CT image. To do this I<br>need (I suppose I need) cast the DICOM signed short pixel format to unsigned<br>char. I want perform this operation after initial thresholding ( the<br>threshold operation is working on signed short type) 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? You can find the code below:<br><br><br>typedef itk::Image<signed short ,2> ImageType;<br>typedef itk::Image<unsigned char, 2>  UCImageType;<br><br>int main( int argc, char* argv[] ){<br><br>typedef itk::ImageFileReader<ImageType> ImageFileReaderType;<br>ImageFileReaderType::Pointer imageReader = ImageFileReaderType::New();<br>imageReader->SetFileName(argv[1]);<br>typedef itk::GDCMImageIO ImageIOType;<br>ImageIOType::Pointer gdcmIO = ImageIOType::New();<br>imageReader->SetImageIO(gdcmIO);<br><br><br>int lowerThreshold = atoi(argv[2]);<br>int upperThreshold = atoi(argv[3]);<br><br>if(lowerThreshold>upperThreshold){<br>std::cout<<"incorrect threshold values"<<"\n";<br>return EXIT_FAILURE;<br>}<br><br>typedef itk::BinaryThresholdImageFilter<ImageType,ImageType><br>ThresholdImageFilterType;<br>ThresholdImageFilterType::Pointer thresholdFilter =<br>ThresholdImageFilterType::New();<br>thresholdFilter->SetInput(imageReader->GetOutput());<br>thresholdFilter->SetLowerThreshold(lowerThreshold);<br>thresholdFilter->SetUpperThreshold(upperThreshold);<br>thresholdFilter->SetInsideValue(1);<br>thresholdFilter->SetOutsideValue(0);<br>thresholdFilter->Update();<br><br>typedef itk::CastImageFilter<ImageType,UCImageType><br>CastImageFilterSS2UCType;<br>CastImageFilterSS2UCType::Pointer castImageFilterSS2UC =<br>CastImageFilterSS2UCType::New();<br>castImageFilterSS2UC->SetInput(thresholdFilter->GetOutput());<br><br>        QuickView viewer;<br>viewer.AddImage(imageReader->GetOutput());<br>viewer.AddImage(thresholdFilter->GetOutput());<br>viewer.AddImage(castImageFilterSS2UC->GetOutput());<br>viewer.Visualize();<br><br>return EXIT_SUCCESS;<br>}<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, 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>