[Insight-users] Regarding bad_alloc while loading DICOM

Luis Ibanez luis.ibanez at kitware.com
Fri Nov 9 17:20:21 EST 2007


Hi Hauke,

How much memory do you have in your computer ?

An image of 1024 x 1024 x 187 pixels, in unsigned short / pixel
should take about 374 Mb.

...


How did you do an in-place casting ?



    Please let us know,



       Thanks


           Luis


-------------------
Hauke Heibel wrote:
> Hi again,
> 
>  
> 
> I felt a little bit guilty since I did not provide any evidence for the 
> issue posted right before. So now I added the source code that causes 
> the bad_alloc.
> 
>  
> 
> A few specs regarding the DICOM file:
> 
> Dimensions: 1024 1024 187
> 
> Data Type: unsigned short
> 
>  
> 
> This should already be sufficient. As you can see from the source code I 
> wanted to load the file as ‘signed short’ which causes temporary buffers 
> to be allocated and thus the bad_alloc exception. And as said before to 
> circumvent the problem I loaded the image as unsigned short, as it is 
> stored on disc and then I tried to use the ImageAdapter to write the 
> image back to the hard disc to prevent additional memory allocations 
> which also did not work.
> 
>  
> 
> In the meantime I actually went for the in-place data type conversion 
> that finally worked.
> 
>  
> 
> Regards and good night,
> 
> Hauke
> 
> 
> ------------------------------------------------------------------------
> 
> #include "itkGDCMImageIO.h"
> #include "itkGDCMSeriesFileNames.h"
> #include "itkImageSeriesReader.h"
> 
> using namespace itk;
> using namespace std;
> 
> int main(int argc, char* argv[])
> {
>   const std::string fileName = argv[1];
>   
>   typedef signed short PixelType;
>   const unsigned int   Dimension = 3;
> 
>   typedef itk::Image<PixelType, Dimension> ImageType;
>   typedef ImageSeriesReader<ImageType>     ReaderType;
>   typedef GDCMImageIO                      ImageIOType;
>   
>   ReaderType::Pointer reader = ReaderType::New();
>   ImageIOType::Pointer dicomIO = ImageIOType::New();
> 
>   reader->SetImageIO(dicomIO);
>   
>   FilenamesContainer fileNames;
>   fileNames.push_back(fileName);
>   
>   reader->SetFileNames(fileNames);
>   
>   try
>   {
>     reader->Update();
>   } 
>   catch (std::bad_alloc& ae)
>   {
>     std::cout << ae.what() << std::endl;
>     return -1;
>   }
>   
>   return 0;
> }
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users


More information about the Insight-users mailing list