- ////////////////////////////////////////////////////////////
- // Reading input image and getting some information //
- ////////////////////////////////////////////////////////////
- //std::cout << "Loading image " << inputfile << std::endl;
- //PixelType* imageData = input->GetPixelContainer()->GetImportPointer();
- uint8_t *imageData = new uint8_t[256*256*10];
- memset( imageData, 0, 256*256*10);
- std::cout << "Image Loaded." << std::endl;
-
- int sizex = 256;
- int sizey = 256;
- int sizez = 10;
- //float spacing[3] = { 1.0, 1.0, 1.5 };
- //float orig[3] = { 0.0, 0.0, 0.0 };
- int sliceSize = sizex*sizey*sizeof(uint8_t);
-
- ////////////////////////////////////////////////////////////
- // compute window center and window width //
- ////////////////////////////////////////////////////////////
- uint8_t min, max; min = max = imageData[0];
- for (int i=1; i<sizex*sizey*sizez; i++)
- {
- uint8_t val = imageData[i];
- if (val > max)
- max = val;
- if (val < min)
- min = val;
- }
- //float wcenter = (max+min) / 2.;
- //float wwidth = (max-min)>0 ? (max-min) : 1.;
-
- ////////////////////////////////////////////////////////////
- // Get file date and time //
- ////////////////////////////////////////////////////////////
- std::string filedate, filetime;
- //GetFileDateAndTime(inputfile, filedate, filetime);
-
- ////////////////////////////////////////////////////////////
- // Create a new dicom header and fill in some info //
- ////////////////////////////////////////////////////////////
- gdcm::File *f = new gdcm::File();
-
- //f->SetDateAndTime(filedate, filetime);
- //f->SetModality("CT");
- //f->SetPatientName( "TestPatient");
- //f->SetPatientID( "TestID");
- //f->SetStudyID( "1");
- //f->SetSeriesNumber( "1");
- //f->SetSliceThickness(spacing[2]);
- //f->SetSpaceBetweenSlices(spacing[2]);
- //f->SetXYSpacing( spacing[0], spacing[1]);
- //f->SetXSize(sizex);
- //f->SetYSize(sizey);
- //f->SetNbBitsAllocated(16);
- //f->SetNbBitsStored(12);
- //f->SetNbBitsStored(12);
- //f->SetPixelSigned(true);
- //f->SetCenter( wcenter);
- //f->SetWindow( wwidth);
-
- ////////////////////////////////////////////////////////////
- // Create a new dicom file object from the header //
- ////////////////////////////////////////////////////////////
- gdcm::FileHelper *fh = new gdcm::FileHelper(f);
- uint8_t *myData = fh->GetImageData(); // Get an Image pointer
- fh->SetImageData( myData, sliceSize); // This callback ensures that the internal
- // Pixel_Data of fh is set correctly
-
-
- ////////////////////////////////////////////////////////////
- // Iterate through the slices and save them to file //
- ////////////////////////////////////////////////////////////
- for (int z=0; z<sizez; z++)
- {
- // Set dicom relevant information for that slice
- //f->SetImageUIDFromSliceNumber(z);
- //f->SetImageLocation(orig[0],orig[1],orig[2]+z*spacing[2]);
-
- // copy image slice content
- memcpy(myData,imageData+z*sizex*sizey,sliceSize);
-
- // write the image
- std::string filename = directory + gdcm::Util::Format("%Image_%05d.dcm", z);
- std::cout << "Writing file " << filename;
- fh->WriteDcmExplVR(filename);
- std::cout << " OK" << std::endl;
- }
-
- ////////////////////////////////////////////////////////////
- // Free the allocated objects //
- ////////////////////////////////////////////////////////////
- // delete fh; // FIXME: these calls sometimes crashes under .NET ????
- // delete f;
-
- return 0;
+ ////////////////////////////////////////////////////////////
+ // Reading input image and getting some information //
+ ////////////////////////////////////////////////////////////
+ //std::cout << "Loading image " << inputfile << std::endl;
+ //PixelType* imageData = input->GetPixelContainer()->GetImportPointer();
+ uint8_t *imageData = new uint8_t[256*256*10];
+ memset( imageData, 0, 256*256*10);
+ std::cout << "Image Loaded." << std::endl;
+
+ int sizex = 256;
+ int sizey = 256;
+ int sizez = 10;
+ //float spacing[3] = { 1.0, 1.0, 1.5 };
+ //float orig[3] = { 0.0, 0.0, 0.0 };
+ int sliceSize = sizex*sizey*sizeof(uint8_t);
+
+ ////////////////////////////////////////////////////////////
+ // compute window center and window width //
+ ////////////////////////////////////////////////////////////
+ uint8_t min, max; min = max = imageData[0];
+ for (int i=1; i<sizex*sizey*sizez; i++)
+ {
+ uint8_t val = imageData[i];
+ if (val > max)
+ max = val;
+ if (val < min)
+ min = val;
+ }
+ //float wcenter = (max+min) / 2.;
+ //float wwidth = (max-min)>0 ? (max-min) : 1.;
+
+ ////////////////////////////////////////////////////////////
+ // Get file date and time //
+ ////////////////////////////////////////////////////////////
+ std::string filedate, filetime;
+ //GetFileDateAndTime(inputfile, filedate, filetime);
+
+ ////////////////////////////////////////////////////////////
+ // Create a new dicom header and fill in some info //
+ ////////////////////////////////////////////////////////////
+ GDCM_NAME_SPACE::File *f = GDCM_NAME_SPACE::File::New();
+
+ ////////////////////////////////////////////////////////////
+ // Create a new dicom file object from the header //
+ ////////////////////////////////////////////////////////////
+ GDCM_NAME_SPACE::FileHelper *fh = GDCM_NAME_SPACE::FileHelper::New(f);
+ uint8_t *myData = fh->GetImageData(); // Get an Image pointer
+ fh->SetImageData( myData, sliceSize); // This callback ensures that the internal
+ // Pixel_Data of fh is set correctly
+
+
+ ////////////////////////////////////////////////////////////
+ // Iterate through the slices and save them to file //
+ ////////////////////////////////////////////////////////////
+ for (int z=0; z<sizez; z++)
+ {
+ // Set dicom relevant information for that slice
+ //f->SetImageUIDFromSliceNumber(z);
+ //f->SetImageLocation(orig[0],orig[1],orig[2]+z*spacing[2]);
+
+ // copy image slice content
+ memcpy(myData,imageData+z*sizex*sizey,sliceSize);
+
+ // write the image
+ std::string filename = directory + GDCM_NAME_SPACE::Util::Format("%Image_%05d.dcm", z);
+ std::cout << "Writing file " << filename;
+ fh->WriteDcmExplVR(filename);
+ std::cout << " OK" << std::endl;
+ }
+
+ ////////////////////////////////////////////////////////////
+ // Free the allocated objects //
+ ////////////////////////////////////////////////////////////
+ fh->Delete();
+ f->Delete();
+
+ return 0;