[Insight-users] Problems with casting image types

Kent Ogden ogdenk at upstate.edu
Wed May 9 09:34:24 EDT 2012


Kumis, 

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?  

Kent 



>>> kumis <kkumis at gmail.com> 5/8/2012 10:23 PM >>>
Hi everyone,
I'm trying to do some labeling operations on an DICOM CT image. To do this I
need (I suppose I need) cast the DICOM signed short pixel format to unsigned
char. I want perform this operation after initial thresholding ( the
threshold operation is working on signed short type) but I found a strange
problem here. When I use the CastImageFilter to convert singed short to
unsigned char the output image is completly dark/empty. Could You give me
some advice how to deal with this problem? You can find the code below:


typedef itk::Image<signed short ,2> ImageType;
typedef itk::Image<unsigned char, 2>  UCImageType;

int main( int argc, char* argv[] ){

typedef itk::ImageFileReader<ImageType> ImageFileReaderType;
ImageFileReaderType::Pointer imageReader = ImageFileReaderType::New();
imageReader->SetFileName(argv[1]);
typedef itk::GDCMImageIO ImageIOType;
ImageIOType::Pointer gdcmIO = ImageIOType::New();
imageReader->SetImageIO(gdcmIO);


int lowerThreshold = atoi(argv[2]);
int upperThreshold = atoi(argv[3]);

if(lowerThreshold>upperThreshold){
std::cout<<"incorrect threshold values"<<"\n";
return EXIT_FAILURE;
}

typedef itk::BinaryThresholdImageFilter<ImageType,ImageType>
ThresholdImageFilterType;
ThresholdImageFilterType::Pointer thresholdFilter =
ThresholdImageFilterType::New();
thresholdFilter->SetInput(imageReader->GetOutput());
thresholdFilter->SetLowerThreshold(lowerThreshold);
thresholdFilter->SetUpperThreshold(upperThreshold);
thresholdFilter->SetInsideValue(1);
thresholdFilter->SetOutsideValue(0);
thresholdFilter->Update();

typedef itk::CastImageFilter<ImageType,UCImageType>
CastImageFilterSS2UCType;
CastImageFilterSS2UCType::Pointer castImageFilterSS2UC =
CastImageFilterSS2UCType::New();
castImageFilterSS2UC->SetInput(thresholdFilter->GetOutput());

        QuickView viewer;
viewer.AddImage(imageReader->GetOutput());
viewer.AddImage(thresholdFilter->GetOutput());
viewer.AddImage(castImageFilterSS2UC->GetOutput());
viewer.Visualize();

return EXIT_SUCCESS;
}


--
View this message in context: http://itk-insight-users.2283740.n2.nabble.com/Problems-with-casting-image-types-tp7541500.html
Sent from the ITK Insight Users mailing list archive at Nabble.com.
_____________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
http://www.itk.org/mailman/listinfo/insight-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20120509/5d1ceefa/attachment.htm>


More information about the Insight-users mailing list