[Insight-users] About openjpeg

Mathieu Malaterre mathieu.malaterre at gmail.com
Fri Apr 24 07:35:27 EDT 2009


[always CC the itk user mailing list, please]

On Fri, Apr 24, 2009 at 5:31 AM, kongdewen1 kong <kongdewen1 at gmail.com> wrote:
> Hi, sorry for being boring you.there is something wrong with my program and
> I cannot find what it is? during my program running, there is nothing wrong.
> But I i can not find any result.
> Here is my program. would you check for me?
>
> # include "itkGDCMImageIO.h"
> # include "itkGDCMSeriesFileNames.h"
> # include "itkImageSeriesReader.h"
> # include "itkImageFileWriter.h"
> # include "itkImage.h"
> # include <string>
> using namespace std;
> int main()
> {
>  /* define the pixel type and dimension */
> typedef signed short  PixelType;
> const unsigned int    Dimension=3;
> typedef itk::Image< PixelType,Dimension> ImageType;
> /* the image type for instantiating the type of the series reader
> and for cinstructing one object of its type*/
> typedef itk::ImageSeriesReader<ImageType> ReaderType;
> ReaderType::Pointer reader=ReaderType::New();
> /* the internal intricacies of the DICOM format*/
> typedef itk::GDCMImageIO ImageIOType;
> ImageIOType::Pointer  dicomIO=ImageIOType::New();
> reader->SetImageIO(dicomIO);
> /* identify from a given directionary the set of the falenames
> that belong together to the same valumetric image*/
> typedef itk::GDCMSeriesFileNames NamesGeneratorType;
> NamesGeneratorType::Pointer nameGenerator=NamesGeneratorType::New();
> nameGenerator->SetUseSeriesDetails(true);
> string argv="F:\\Medical imaging\\001\\prone";
> nameGenerator->SetDirectory(argv);/*Diectionary!! */
>  /*a try/catch block*/
> typedef std::vector<std::string>  SeriesIdContainer;
> const SeriesIdContainer & seriesUID=nameGenerator->GetSeriesUIDs();
> SeriesIdContainer::const_iterator seriesItr=seriesUID.begin();
> SeriesIdContainer::const_iterator seriesEnd=seriesUID.end();
> while(seriesItr!=seriesEnd)
> {
>  std::cout<<seriesItr->c_str()<<std::endl;
>  seriesItr++;
> }
> //check if the user has provided a series identifier in the command line
> arguments
> std::string seriesIdentifier;
> int argc=2;
> if(argc>3) //if no optional series identifier
> {
>  seriesIdentifier=1;
> }
> else
> {
>   seriesIdentifier=seriesUID.begin()->c_str();
> }
> typedef std::vector<std::string> FileNamesContainer;
> FileNamesContainer fileNames;
> fileNames=nameGenerator->GetFileNames(seriesIdentifier);
> // the list of filenames can now be passed to the itk::ImageSeriesReader
> using
> //the setFileNames() method
> reader->SetFileNames(fileNames);
> //trigger the reading process by invoking the update() method in the reader.
> try
> {
>  reader->Update();
> }
> catch (itk::ExceptionObject &ex)
> {
>  std::cout<<ex<<std::endl;
>  return EXIT_FAILURE;
> }

Here is the culprit part:

> typedef itk::ImageFileWriter< ImageType>WriterType;
> WriterType::Pointer writer=WriterType::New();
> //  Explicitely specify which compression type to use
>   dicomIO->SetCompressionType(itk::GDCMImageIO::JPEG2000);
>   // Request compression of the ImageIO
>   writer->UseCompressionOn();
>   string filedirect="F:\\Medical imaging\\001";
>   writer->SetFileName(filedirect);
>   writer->SetInput(reader->GetOutput());
>   try
>     {
>     writer->Update();
>     }
<...>

You are neither :
1. Specifying explicitely which ImageIO to use to the FileWriter
2. Nor setting a filename extension which would hint the FileWriter
what type of file you are interested in.

As a side note, always report the actual error (copy/paste) do not
paraphrase. Simple cut/paste of errore are much more valuable than
anything else. The exception error message (in your try/catch) should
have helped you on that.

2cts
-- 
Mathieu


More information about the Insight-users mailing list