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
GDCM_NAME_SPACE::Debug::DebugOn();
int verbose = am->ArgMgrDefined("verbose");
int oververbose = am->ArgMgrDefined("oververbose");
GDCM_NAME_SPACE::Debug::DebugOn();
int verbose = am->ArgMgrDefined("verbose");
int oververbose = am->ArgMgrDefined("oververbose");
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 loadMode = GDCM_NAME_SPACE::LD_ALL;
if ( am->ArgMgrDefined("noshadowseq") )
loadMode |= GDCM_NAME_SPACE::LD_NOSHADOWSEQ;
int loadMode = GDCM_NAME_SPACE::LD_ALL;
if ( am->ArgMgrDefined("noshadowseq") )
loadMode |= GDCM_NAME_SPACE::LD_NOSHADOWSEQ;
{
if ( am->ArgMgrDefined("noshadow") )
loadMode |= GDCM_NAME_SPACE::LD_NOSHADOW;
if ( am->ArgMgrDefined("noseq") )
loadMode |= GDCM_NAME_SPACE::LD_NOSEQ;
}
{
if ( am->ArgMgrDefined("noshadow") )
loadMode |= GDCM_NAME_SPACE::LD_NOSHADOW;
if ( am->ArgMgrDefined("noseq") )
loadMode |= GDCM_NAME_SPACE::LD_NOSEQ;
}
//std::cout << "dirIn [" << dirIn << "]" << std::endl;
if ( ! GDCM_NAME_SPACE::DirList::IsDirectory(dirIn) )
{
std::cout << "KO : [" << dirIn << "] is not a Directory." << std::endl;
return 0;
//std::cout << "dirIn [" << dirIn << "]" << std::endl;
if ( ! GDCM_NAME_SPACE::DirList::IsDirectory(dirIn) )
{
std::cout << "KO : [" << dirIn << "] is not a Directory." << std::endl;
return 0;
<< "] already exists; Used as is." << std::endl;
}
GDCM_NAME_SPACE::DirList dirList(dirIn,false); // gets (at single level) the file list
GDCM_NAME_SPACE::DirListType fileList = dirList.GetFilenames();
<< "] already exists; Used as is." << std::endl;
}
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
-
- 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];
+
GDCM_NAME_SPACE::File **f = new GDCM_NAME_SPACE::File *[nbOfImagesInVolume];
GDCM_NAME_SPACE::FileHelper **fh = new GDCM_NAME_SPACE::FileHelper *[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;
// 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");
lastFilename = GDCM_NAME_SPACE::Util::GetName( fullFilename );
std::string fullWriteFilename = strDirNameout + GDCM_NAME_SPACE::GDCM_FILESEPARATOR
+ lastFilename;
if (verbose)
std::cout << "Write : [" << fullWriteFilename << "]" << std::endl;
lastFilename = GDCM_NAME_SPACE::Util::GetName( fullFilename );
std::string fullWriteFilename = strDirNameout + GDCM_NAME_SPACE::GDCM_FILESEPARATOR
+ lastFilename;
if (verbose)
std::cout << "Write : [" << fullWriteFilename << "]" << std::endl;
if (!fh[imageNumber]->Write(fullWriteFilename))
{
std::cout << "Fail to write :[" << fullWriteFilename << "]"
if (!fh[imageNumber]->Write(fullWriteFilename))
{
std::cout << "Fail to write :[" << fullWriteFilename << "]"