Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
//
// This program is used to convert huge amounts of functionnal (3D + T) MR images
// into 'image tiles' (one title per volume) processable by clinical softwares
=========================================================================*/
//
// This program is used to convert huge amounts of functionnal (3D + T) MR images
// into 'image tiles' (one title per volume) processable by clinical softwares
#include <string.h> // for memset
int main(int argc, char *argv[])
#include <string.h> // for memset
int main(int argc, char *argv[])
START_USAGE(usage)
"\n exConvert3plusT :\n ",
" Converts the Dicom files inside a single-level Directory ",
START_USAGE(usage)
"\n exConvert3plusT :\n ",
" Converts the Dicom files inside a single-level Directory ",
" [pixelsize = ] [imagesinvolume = ] ",
" ",
" studyUID : *aware* user wants to add the serie ",
" [pixelsize = ] [imagesinvolume = ] ",
" ",
" studyUID : *aware* user wants to add the serie ",
" imdimx,imdimy : 'elementary image' size (default : 64) ",
" used to reject erroneous images ",
" imgline, imgcol : sizes of the 'image tile' defaulted as 6x6 ",
" imdimx,imdimy : 'elementary image' size (default : 64) ",
" used to reject erroneous images ",
" imgline, imgcol : sizes of the 'image tile' defaulted as 6x6 ",
" verbose : user wants to run the program in 'verbose mode' ",
" debug : developper wants to run the program in 'debug mode' ",
FINISH_USAGE
" verbose : user wants to run the program in 'verbose mode' ",
" debug : developper wants to run the program in 'debug mode' ",
FINISH_USAGE
std::string patName = am->ArgMgrGetString("patname", "g^PatientName");
//float zSpacing = am->ArgMgrGetFloat("zSpacing", 1.0);
std::string patName = am->ArgMgrGetString("patname", "g^PatientName");
//float zSpacing = am->ArgMgrGetFloat("zSpacing", 1.0);
bool userDefinedStudy = am->ArgMgrDefined("studyUID");
const char *studyUID = am->ArgMgrGetString("studyUID");
bool userDefinedStudy = am->ArgMgrDefined("studyUID");
const char *studyUID = am->ArgMgrGetString("studyUID");
-// not described *on purpose* in the Usage !
- bool userDefinedSerie = am->ArgMgrDefined("serieUID");
- const char *serieUID = am->ArgMgrGetString("serieUID");
-
+// not described *on purpose* in the Usage !
+ bool userDefinedSerie = am->ArgMgrDefined("serieUID");
+ const char *serieUID = am->ArgMgrGetString("serieUID");
int imageDimX = am->ArgMgrGetInt("imdimx",64);
int imageDimY = am->ArgMgrGetInt("imdimy",64);
int imagePixelSize = am->ArgMgrGetInt("pixelsize", 2);
int imageDimX = am->ArgMgrGetInt("imdimx",64);
int imageDimY = am->ArgMgrGetInt("imdimy",64);
int imagePixelSize = am->ArgMgrGetInt("pixelsize", 2);
int nbOfImagesInVolume = am->ArgMgrGetInt("imagesinvolume",
imagetteLineNumber*imagetteRowNumber);
int nbOfImagesInVolume = am->ArgMgrGetInt("imagesinvolume",
imagetteLineNumber*imagetteRowNumber);
{
systemCommand = "mkdir " +strDirNameout; // create it!
if (verbose)
std::cout << systemCommand << std::endl;
system (systemCommand.c_str());
{
systemCommand = "mkdir " +strDirNameout; // create it!
if (verbose)
std::cout << systemCommand << std::endl;
system (systemCommand.c_str());
- gdcm::DirList dirList(dirIn,false); // gets (at single level) the file list
- gdcm::DirListType fileList = dirList.GetFilenames();
-
+ GDCM_NAME_SPACE::DirList dirList(dirIn,false); // gets (at single level) the file list
+ GDCM_NAME_SPACE::DirListType fileList = dirList.GetFilenames();
// hope sorting on the filename is enough!
// anyway, *no* filed is available to perform anything more clever.
// hope sorting on the filename is enough!
// anyway, *no* filed is available to perform anything more clever.
// keeping the same 'Serie Instance UID' for various images
// The user shouldn't add any image to a 'Manufacturer Serie'
// but there is no way no to prevent him for doing that
// keeping the same 'Serie Instance UID' for various images
// The user shouldn't add any image to a 'Manufacturer Serie'
// but there is no way no to prevent him for doing that
-
- std::string strSerieUID;
- if ( !userDefinedSerie)
- strSerieUID = gdcm::Util::CreateUniqueUID();
- else
+ std::string strSerieUID;
+ if ( !userDefinedSerie)
+ strSerieUID = GDCM_NAME_SPACE::Util::CreateUniqueUID();
+ else
-
- size_t totalNumberOfPixels = imageDimX*imageDimY * imagetteLineNumber*imagetteRowNumber;
- int16_t *imageTable = new int16_t[totalNumberOfPixels];
-
+ size_t totalNumberOfPixels = imageDimX*imageDimY * imagetteLineNumber*imagetteRowNumber;
+ int16_t *imageTable = new int16_t[totalNumberOfPixels];
+
-
- int16_t **tabImageData = new int16_t *[nbOfImagesInVolume];
- gdcm::File **f = new gdcm::File *[nbOfImagesInVolume];
- gdcm::FileHelper **fh = new gdcm::FileHelper *[nbOfImagesInVolume];
-
+
+ int16_t **tabImageData = new int16_t *[nbOfImagesInVolume];
+ GDCM_NAME_SPACE::File **f = new GDCM_NAME_SPACE::File *[nbOfImagesInVolume];
+ GDCM_NAME_SPACE::FileHelper **fh = new GDCM_NAME_SPACE::FileHelper *[nbOfImagesInVolume];
+
std::string fullFilename, lastFilename;
float zPositionComponent = 0.0;
std::string fullFilename, lastFilename;
float zPositionComponent = 0.0;
f[imageNumber]->SetLoadMode(loadMode);
f[imageNumber]->SetFileName( it->c_str() );
if (verbose)
std::cout << "file [" << it->c_str() << "], as imageNumber : " << imageNumber << std::endl;
f[imageNumber]->SetLoadMode(loadMode);
f[imageNumber]->SetFileName( it->c_str() );
if (verbose)
std::cout << "file [" << it->c_str() << "], as imageNumber : " << imageNumber << std::endl;
// Don't convert (Gray Pixels + LUT) into (RGB pixels) ?!?
tabImageData[imageNumber] = (int16_t *)fh[imageNumber]->GetImageDataRaw();
// Don't convert (Gray Pixels + LUT) into (RGB pixels) ?!?
tabImageData[imageNumber] = (int16_t *)fh[imageNumber]->GetImageDataRaw();
for(imageNumber=0; imageNumber < nbOfImagesInVolume; imageNumber++)
{
int debMove = (imageNumber%imagetteRowNumber) * imageDimX
for(imageNumber=0; imageNumber < nbOfImagesInVolume; imageNumber++)
{
int debMove = (imageNumber%imagetteRowNumber) * imageDimX
imageTable[debLigne + j] = *(tabImageData[imageNumber] + i*imageDimY + j);
if (imageTable[debLigne + j] < 0) imageTable[debLigne + j]=0;
//std::cout << debLigne + j << " : " << imageTable[debLigne + j] << std::endl;
imageTable[debLigne + j] = *(tabImageData[imageNumber] + i*imageDimY + j);
if (imageTable[debLigne + j] < 0) imageTable[debLigne + j]=0;
//std::cout << debLigne + j << " : " << imageTable[debLigne + j] << std::endl;
if (*(tabImageData[imageNumber] + i*imageDimY + j) < mini)
mini=*(tabImageData[imageNumber] + i*imageDimY + j);
else if (*(tabImageData[imageNumber] + i*imageDimY + j) > maxi)
maxi=*(tabImageData[imageNumber] + i*imageDimY + j);
}
if (*(tabImageData[imageNumber] + i*imageDimY + j) < mini)
mini=*(tabImageData[imageNumber] + i*imageDimY + j);
else if (*(tabImageData[imageNumber] + i*imageDimY + j) > maxi)
maxi=*(tabImageData[imageNumber] + i*imageDimY + j);
}
- fh[imageNumber]->InsertEntryString(str.str(),0x0028,0x0010, "US"); // Rows
+ fh[imageNumber]->InsertEntryString(str.str(),0x0028,0x0010, "US"); // Rows
- fh[imageNumber]->InsertEntryString(strStudyUID,0x0020,0x000d,"UI");
+ fh[imageNumber]->InsertEntryString(strStudyUID,0x0020,0x000d,"UI");
fh[imageNumber]->InsertEntryString(strSerieUID,0x0020,0x000e,"UI");
fh[imageNumber]->InsertEntryString(patName,0x0010,0x0010, "PN"); // Patient's Name
fh[imageNumber]->InsertEntryString(strSerieUID,0x0020,0x000e,"UI");
fh[imageNumber]->InsertEntryString(patName,0x0010,0x0010, "PN"); // Patient's Name
// This is a dirty heuristics, but no other way :-(
// if Image Orientation (Patient) is not present
// This is a dirty heuristics, but no other way :-(
// if Image Orientation (Patient) is not present
// if Image Position (Patient) is not present
// I create one, incrementing zPositionComponent up by user supplied zSpacing
// if Image Position (Patient) is not present
// I create one, incrementing zPositionComponent up by user supplied zSpacing
fh[imageNumber]->InsertEntryString("1.0\\0.0\\0.0\\0.0\\1.0\\0.0",0x0020,0x0037, "DS"); //[1\0\0\0\1\0] : Axial
char charImagePosition[256];
fh[imageNumber]->InsertEntryString("1.0\\0.0\\0.0\\0.0\\1.0\\0.0",0x0020,0x0037, "DS"); //[1\0\0\0\1\0] : Axial
char charImagePosition[256];
sprintf(charImagePosition,"%f\\0.0\\0.0",zPositionComponent);
zPositionComponent += zSpacing;
sprintf(charImagePosition,"%f\\0.0\\0.0",zPositionComponent);
zPositionComponent += zSpacing;
- fh[imageNumber]->InsertEntryString(charImagePosition,0x0020,0x0032, "DS");
-
+ fh[imageNumber]->InsertEntryString(charImagePosition,0x0020,0x0032, "DS");
if (! f[imageNumber]->CheckIfEntryExist(0x0020,0x1041) ) // 0020 0x1041 DS 1 Slice Location
{
sprintf(charImagePosition,"%f",zPositionComponent);
fh[imageNumber]->InsertEntryString(charImagePosition,0x0020,0x1041, "DS");
if (! f[imageNumber]->CheckIfEntryExist(0x0020,0x1041) ) // 0020 0x1041 DS 1 Slice Location
{
sprintf(charImagePosition,"%f",zPositionComponent);
fh[imageNumber]->InsertEntryString(charImagePosition,0x0020,0x1041, "DS");
- fh[imageNumber]->SetWriteTypeToDcmExplVR();
- fh[imageNumber]->SetContentType(gdcm::UNMODIFIED_PIXELS_IMAGE);
+ fh[imageNumber]->SetWriteTypeToDcmExplVR();
+ fh[imageNumber]->SetContentType(GDCM_NAME_SPACE::UNMODIFIED_PIXELS_IMAGE);
-
- lastFilename = gdcm::Util::GetName( fullFilename );
- std::string fullWriteFilename = strDirNameout + gdcm::GDCM_FILESEPARATOR
+ lastFilename = GDCM_NAME_SPACE::Util::GetName( fullFilename );
+ std::string fullWriteFilename = strDirNameout + GDCM_NAME_SPACE::GDCM_FILESEPARATOR
if (!fh[imageNumber]->Write(fullWriteFilename))
{
std::cout << "Fail to write :[" << fullWriteFilename << "]"
if (!fh[imageNumber]->Write(fullWriteFilename))
{
std::cout << "Fail to write :[" << fullWriteFilename << "]"