[Insight-users] Problems with casting image types
kumis
kkumis at gmail.com
Tue May 8 22:23:15 EDT 2012
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.
More information about the Insight-users
mailing list