[Insight-developers] Conversion DICOM -> JPEG Problem
Mario Ciampi
ciampi.mario at gmail.com
Wed Mar 25 13:41:15 EDT 2009
Hi,I'm trying to convert a DICOM series to JPEG files. I'm able to write
JPEG files, but the issue is that these ones are coded in 8 bits rather than
in 16 bits, and thus the quality of JPEG images is poor. I report below the
code I use to perform the conversion.
void exportFilter::exportSeriesToJpg(string inputDirectory, string
outputDirectory) {
NamesGeneratorType::Pointer namesGenerator = NamesGeneratorType::New();
namesGenerator->SetInputDirectory(inputDirectory);
typedef itk::RGBPixel < unsigned char > RGBPixelType;
typedef itk::Image < RGBPixelType, 3 > RGBImageType;
typedef itk::ImageSeriesReader<RGBImageType> SeriesReaderType;
const SeriesReaderType::FileNamesContainer & filenames =
namesGenerator->GetInputFileNames();
unsigned int numberOfFilenames = filenames.size();
if(numberOfFilenames) {
SeriesReaderType::Pointer reader = SeriesReaderType::New();
reader->SetFileNames(filenames);
try {
reader->Update();
}
catch (itk::ExceptionObject &) {
return;
}
RGBImageType::Pointer inputImage = reader->GetOutput();
typedef itk::Image < RGBPixelType, 2 > RGBImage2DType;
typedef itk::ImageSeriesWriter <RGBImageType, RGBImage2DType>
SeriesWriterType;
SeriesWriterType::Pointer seriesWriter = SeriesWriterType::New();
seriesWriter->SetInput(inputImage);
namesGenerator->SetOutputDirectory(outputDirectory);
std::vector<std::string> outputFilenamesTemp =
namesGenerator->GetOutputFileNames();
std::vector<std::string> outputFilenames;
string temp;
while(outputFilenamesTemp.size()) {
temp = outputFilenamesTemp.back();
outputFilenamesTemp.pop_back();
temp.replace(temp.size()-3,temp.size()-1,"jpg");
outputFilenames.push_back(temp);
}
seriesWriter->SetFileNames(outputFilenames);
try {
seriesWriter->Update();
}
catch( itk::ExceptionObject & ) {
return;
}
}
else return;
}
Instead, I'm not able even to write JPEG files if I execute the code
reported below, in which input images are coded in 16 bits (using short).
void exportFilter::exportSeriesToJpg(string inputDirectory, string
outputDirectory) {
NamesGeneratorType::Pointer namesGenerator = NamesGeneratorType::New();
namesGenerator->SetInputDirectory(inputDirectory);
typedef short PixelType;
typedef itk::Image < PixelType, 3 > ImageType;
typedef itk::ImageSeriesReader<ImageType> SeriesReaderType;
const SeriesReaderType::FileNamesContainer & filenames =
namesGenerator->GetInputFileNames();
unsigned int numberOfFilenames = filenames.size();
if(numberOfFilenames) {
SeriesReaderType::Pointer reader = SeriesReaderType::New();
reader->SetFileNames(filenames);
try {
reader->Update();
}
catch (itk::ExceptionObject &) {
return;
}
ImageType::Pointer inputImage = reader->GetOutput();
typedef itk::Image < PixelType, 2 > Image2DType;
typedef itk::ImageSeriesWriter <ImageType, Image2DType> SeriesWriterType;
SeriesWriterType::Pointer seriesWriter = SeriesWriterType::New();
seriesWriter->SetInput(inputImage);
namesGenerator->SetOutputDirectory(outputDirectory);
std::vector<std::string> outputFilenamesTemp =
namesGenerator->GetOutputFileNames();
std::vector<std::string> outputFilenames;
string temp;
while(outputFilenamesTemp.size()) {
temp = outputFilenamesTemp.back();
outputFilenamesTemp.pop_back();
temp.replace(temp.size()-3,temp.size()-1,"jpg");
outputFilenames.push_back(temp);
}
seriesWriter->SetFileNames(outputFilenames);
try {
seriesWriter->Update();
}
catch( itk::ExceptionObject & ) {
return;
}
}
else return;
}
I appreciate any help!
Thanks in advance,
Mario
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/mailman/private/insight-developers/attachments/20090325/7a69e3f3/attachment.htm>
More information about the Insight-developers
mailing list