Program: gdcm
Module: $RCSfile: PcpdenseToDicom.cxx,v $
Language: C++
- Date: $Date: 2008/09/15 15:49:20 $
- Version: $Revision: 1.3 $
+ Date: $Date: 2011/09/12 23:27:41 $
+ Version: $Revision: 1.11 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
* Hope they don't change soon!
*/
-void MakeDicomImage(unsigned short int *tabVal, int X, int Y, std::string dcmImageName,
- const char * patientname, int nbFrames, std::string studyUID, std::string serieUID, std::string studyUID, int imgNum,bool m );
+void MakeDicomImage(unsigned short int *tabVal, int X, int Y, std::string dcmImageName, const char * patientName, int nbFrames,
+ std::string studyUID, std::string serieUID, std::string SerieDescr, int imgNum, bool m );
-void LoadImage(std::ifstream &from, unsigned short int * );
+void LoadImage(std::ifstream &from, unsigned short int *, int multFact);
-void LoadImageX2(std::ifstream &from, unsigned short int * );
+void LoadImageX2(std::ifstream &from, unsigned short int *, int multFact);
+void RotateImage(unsigned short int *image, unsigned short int *image2, int NX, int NY);
+void FlipImage (unsigned short int *image, unsigned short int *image2, int NX, int NY);
+
+void WholeBazar (unsigned short int *image, int NX, int NY, int numberOfSlices, std::string strStudyUID, std::string serieDescr, const char* patientName, bool multiframe, bool X2, int multFact, const char *rootfilename);
bool verbose;
int main(int argc, char *argv[])
{
START_USAGE(usage)
- " \n pcpdenseToDicom :\n ",
- " Converts the '.txt' files into 16 bits Dicom Files, ",
+ " \n pcpdenseToDicom :\n ",
+ " Converts the '.txt' files into 16 bits Dicom-like Files, ",
" usage: ",
- " pcpdenseToDicom rootfilename=... ",
+ " pcpdenseToDicom rootfilename=... ",
" (e.g.. : meas_MID380_DENSE_stacked_slices_aif_FID81637)",
" numberOfSlices = (default : 3) ",
" X2 : multiply x 2 image size ",
+ " multFact = (default : 1000) multiply pixel value by ... ",
" m :create multiframe files instead of image stacks ",
" [patientname = Patient's name] ",
" [verbose] [debug] ",
const char *rootfilename = am->ArgMgrWantString("rootfilename",usage);
int numberOfSlices = am->ArgMgrGetInt("numberOfSlices",3);
+ int multFact = am->ArgMgrGetInt("multFact",1000);
const char *patientName = am->ArgMgrGetString("patientname", "Patient^Name");
if (am->ArgMgrDefined("debug"))
std::string strSerieUID;
std::string strStudyUID = GDCM_NAME_SPACE::Util::CreateUniqueUID();
- std::string dcmImageName, textFileName, patientname,/* studyUID, serieUID, */ serieDescr ;
+ std::string /*dcmImageName,*/ textFileName, patientname, serieDescr;
std::string deb(rootfilename);
unsigned short int *image;
-
+// unsigned short int *image2;
+
int NX, NY;
// Get some info
// -------------
- {
+ {
Ecc.str(rootfilename);
Ecc << Ecc.str() << "_s0" << "_Ecc.txt";
fromEcc >> NX;
fromEcc >> NY;
std::cout << "NX, NY : " << NX << ", " << NY << std::endl;
- }
-
- int mult;
- if (X2)
- mult=4;
- else
- mult=1;
-
- if (multiframe)
- image = new unsigned short int[NX*NY*mult*numberOfSlices];
- else
- image = new unsigned short int[NX*NY*mult];
-
-
-
- // === Ecc ===
-
- strSerieUID = GDCM_NAME_SPACE::Util::CreateUniqueUID();
-
- if (!multiframe) {
-
- for (int i=0; i<numberOfSlices; i++)
- {
- Ecc.str(rootfilename);
- Ecc << Ecc.str() << "_s" << i << "_Ecc.txt";
-
- std::ifstream fromEcc( Ecc.str().c_str() );
- if ( !fromEcc )
- {
- std::cout << "Can't open file [" << Ecc.str() << "]" << std::endl;
- exit(0);
- }
- std::cout << "Open file [" << Ecc.str() << "] : OK" << std::endl;
-
- if (X2)
- LoadImageX2(fromEcc, image);
- else
- LoadImage(fromEcc, image);
- fromEcc.close();
-
- dcmImageName = Ecc.str() + ".dcm";
-
- MakeDicomImage(image, NX, NY, dcmImageName, patientName, 1, strStudyUID, strSerieUID, serieDescr, i, multiframe );
- } // end : for (int i=0; i<numberOfSlices
- delete []image;
-}
-
-
- if (multiframe) {
-
- for (int i=0; i<numberOfSlices; i++)
- {
- Ecc.str(rootfilename);
- Ecc << Ecc.str() << "_s" << i << "_Ecc.txt";
-
- std::ifstream fromEcc( Ecc.str().c_str() );
- if ( !fromEcc )
- {
- std::cout << "Can't open file [" << Ecc.str() << "]" << std::endl;
- exit(0);
- }
-
- std::cout << "Open file [" << Ecc.str() << "] : OK" << std::endl;
- if (X2)
- LoadImageX2(fromEcc ,&image[NX*NY*i] );
- else
- LoadImage(fromEcc, &image[NX*NY*i] );
-
- fromEcc.close();
- } // end : for (int i=0; i<numberOfSlices
-
- dcmImageName = deb + "_Ecc.dcm";
- MakeDicomImage(image, NX, NY, dcmImageName, patientName, numberOfSlices, strStudyUID, strSerieUID, serieDescr, 0, multiframe );
-
- } // end : if (multiframe)
-
-
-
-// === perf ===
-
- strSerieUID = GDCM_NAME_SPACE::Util::CreateUniqueUID();
-
- if (!multiframe) {
- for (int i=0; i<numberOfSlices; i++)
- {
- perf.str(rootfilename);
- perf << perf.str() << "_s" << i << "_perf.txt";
-
- std::ifstream fromperf( perf.str().c_str() );
- if ( !fromperf )
- {
- std::cout << "Can't open file [" << perf.str() << "]" << std::endl;
- exit(0);
- }
- std::cout << "Open file [" << perf.str() << "] : OK" << std::endl;
-
- if (X2)
- LoadImageX2(fromperf ,image );
- else
- LoadImage(fromperf, image );
-
- fromperf.close();
-
- dcmImageName = Ecc.str() + ".dcm";
- MakeDicomImage(image, NX, NY, dcmImageName, patientName, 1, strStudyUID, strSerieUID, serieDescr, i, multiframe );
-
- } // end : for (int i=0; i<numberOfSlices
}
-
- if (multiframe) {
- for (int i=0; i<numberOfSlices; i++)
- {
- perf.str(rootfilename);
- perf << perf.str() << "_s" << i << "_perf.txt";
-
- std::ifstream fromperf( perf.str().c_str() );
- if ( !fromperf )
- {
- std::cout << "Can't open file [" << perf.str() << "]" << std::endl;
- exit(0);
- }
- std::cout << "Open file [" << perf.str() << "] : OK" << std::endl;
-
- if (X2)
- LoadImageX2(fromperf, &image[NX*NY*i]);
- else
- LoadImage(fromperf, &image[NX*NY*i] );
-
- fromperf.close();
- } // end : for (int i=0; i<numberOfSlices
- dcmImageName = deb + "_perf.dcm";
- MakeDicomImage(image, NX, NY, dcmImageName, patientName, numberOfSlices, strStudyUID, strSerieUID, serieDescr, numberOfSlices, multiframe );
- }
-
-
+serieDescr = "Ecc";
+WholeBazar(image, NX, NY, numberOfSlices, strStudyUID, serieDescr, patientName, multiframe, X2, multFact, rootfilename);
-// === WashoutTc ===
+serieDescr = "perf";
+WholeBazar(image, NX, NY, numberOfSlices, strStudyUID, serieDescr, patientName, multiframe, X2, multFact, rootfilename);
+serieDescr = "WashoutTc";
+WholeBazar(image, NX, NY, numberOfSlices, strStudyUID, serieDescr, patientName, multiframe, X2, multFact, rootfilename);
- strSerieUID = GDCM_NAME_SPACE::Util::CreateUniqueUID();
-
- if (multiframe) {
- for (int i=0; i<numberOfSlices; i++)
- {
- WashoutTc.str(rootfilename);
- WashoutTc << WashoutTc.str() << "_s" << i << "_WashoutTc.txt";
-
- std::ifstream fromWashoutTc( WashoutTc.str().c_str() );
- if ( !fromWashoutTc )
- {
- std::cout << "Can't open file [" << WashoutTc.str() << "]" << std::endl;
- exit(0);
- }
- std::cout << "Open file [" << WashoutTc.str() << "] : OK" << std::endl;
-
- if (X2)
- LoadImageX2(fromWashoutTc, &image[NX*NY*i]);
- else
- LoadImage(fromWashoutTc, &image[NX*NY*i] );
- fromWashoutTc.close();
-
- } // end : for (int i=0; i<numberOfSlices
-
- dcmImageName = deb + "_WashoutTc.dcm";
- MakeDicomImage(image, NX, NY, dcmImageName, patientName, numberOfSlices, strStudyUID, strSerieUID, serieDescr, numberOfSlices, multiframe );
- }
-
-
- if (!multiframe) {
-
- for (int i1=0; i1<numberOfSlices; i1++)
- {
- WashoutTc.str(rootfilename);
- WashoutTc << WashoutTc.str() << "_s" << i1 << "_WashoutTc.txt";
-
- std::ifstream fromWashoutTc( WashoutTc.str().c_str() );
- if ( !fromWashoutTc )
- {
- std::cout << "Can't open file [" << WashoutTc.str() << "]" << std::endl;
- exit(0);
- }
-
- std::cout << "Open file [" << WashoutTc.str() << "] : OK" << std::endl;
- if (X2)
- LoadImageX2(fromWashoutTc,image );
- else
- LoadImage(fromWashoutTc,image );
- fromWashoutTc.close();
-
- dcmImageName = Ecc.str() + ".dcm";
- MakeDicomImage(image, NX, NY, dcmImageName, patientName, 1, strStudyUID, strSerieUID, serieDescr, i1, multiframe );
- } // end : for (int i=0; i<numberOfSlices
-
- }
-
- delete []image;
+ // delete []image;
return 1;
}
// =====================================================================================================================
-void LoadImage(std::ifstream &from, unsigned short int *image)
+void LoadImage(std::ifstream &from, unsigned short int *image, int multFact)
{
// in any file ".txt" :
if (!from)
return;
-
+
std::string str1;
- from >> str1;
- from >> str1;
+ from >> str1;
+ from >> str1;
- int NX, NY;
- from >> NX;
- from >> NY;
- std::cout << "NX, NY : " << NX << ", " << NY << std::endl;
+ int NX, NY;
+ from >> NX;
+ from >> NY;
+ std::cout << "NX, NY : " << NX << ", " << NY << std::endl;
- float pixelValue;
+ float pixelValue;
- int i, j;
- for( i=0;i<NY;i++)
+ int i, j;
+ for( i=0;i<NY;i++) {
for(j=0;j<NX;j++) {
from >> pixelValue;
- image[i*NX+j] = (unsigned short int)(pixelValue * 1000.);
+ image[i*NX+j] = (unsigned short int)(pixelValue * multFact); // Why do we multiply by 1000? // JPR
}
+ }
}
// =====================================================================================================================
-void LoadImageX2(std::ifstream &from, unsigned short int *image )
+void LoadImageX2(std::ifstream &from, unsigned short int *image, int multFact )
{
// in any file ".txt" :
from >> NY;
std::cout << "NX, NY : " << NX << ", " << NY << std::endl;
+ int k;
+ for( k=0;k<NX*NY*4;k++)
+ image[k] = 0;
+
float pixelValue;
int i, j;
+ /*
for( i=0;i<NY;i++) {
for(j=0;j<NX;j++) {
from >> pixelValue;
- pixelValue*=1000.;
+ pixelValue*=1000.; // Why do we multiply by 1000? // JPR
image[i*4*NX + j*2] = image[i*4*NX + j*2+1] = image[(i*4+2)*NX + j*2] = image[(i*4+2)*NX + j*2+1] = (unsigned short int)(pixelValue);
+ }
+ }
+ */
+
+ int lgrLigneNvlleImage = NX+NX;
+ int debLigneNvlleImage = 0;
+ for( i=0;i<NY;i++) {
+ for(j=0;j<NX;j++) {
+ from >> pixelValue;
+ pixelValue*=multFact; // Why do we multiply by 1000? // JPR
+ image[debLigneNvlleImage + j+j] =
+ image[debLigneNvlleImage + j+j +1] =
+ image[debLigneNvlleImage + lgrLigneNvlleImage +j+j] =
+ image[debLigneNvlleImage + lgrLigneNvlleImage + j+j +1] =
+ (unsigned short int)(pixelValue);
+ }
+ debLigneNvlleImage += 2*lgrLigneNvlleImage;
+ }
+}
+// =====================================================================================================================================
+void RotateImage(unsigned short int *image, unsigned short int *image2, int NX, int NY)
+{
+ int k = 0;
+ for( int i=0;i<NY;i++) {
+ for(int j=0;j<NX;j++) {
+ image2[NY*j + i] = image[k];
+ k++;
+ }
+ }
+}
+
+
+// =====================================================================================================================================
+void FlipImage(unsigned short int *image, unsigned short int *image2, int NX, int NY)
+{
+ unsigned short int temp;
+ for(int i=0;i<NY/2;i++) {
+ for(int j=0;j<NX;j++) {
+ temp = image[NX*i + j];
+ image2[NX*i + j] = image[NX*(NY-i-1) + j];
+ image2[NX*(NY-i-1) + j] = temp;
+ }
+ }
+}
+
+// =====================================================================================================================================
+
+void WholeBazar(unsigned short int *image, int NX, int NY, int numberOfSlices, std::string strStudyUID, std::string serieDescr, const char *patientName, bool multiframe, bool X2, int multFact, const char *rootfilename)
+{
+ unsigned short int *image2;
+ std::string strSerieUID = GDCM_NAME_SPACE::Util::CreateUniqueUID();
+ std::string deb(rootfilename);
+ std::ostringstream Ecc;
+ std::ostringstream trueSerieDescr;
+ std::string dcmImageName;
+
+ int mult;
+ if (X2)
+ mult=4;
+ else
+ mult=1;
+
+ if (multiframe) {
+ image = new unsigned short int[NX*NY*mult*numberOfSlices];
+ image2 = new unsigned short int[NX*NY*mult*numberOfSlices];
+ } else {
+ image = new unsigned short int[NX*NY*mult];
+ image2 = new unsigned short int[NX*NY*mult];
+ }
+
+ if (!multiframe) {
+ for (int i=0; i<numberOfSlices; i++)
+ {
+ Ecc.str(rootfilename);
+ //Ecc << Ecc.str() << "_s" << i << "_Ecc.txt";
+ Ecc << Ecc.str() << "_s" << i << "_" << serieDescr << ".txt";
+
+ trueSerieDescr.str("");
+
+ trueSerieDescr << serieDescr << "_" "s" << i;
+ //std::cout << "-------------------------------------------------------" << trueSerieDescr.str() << std::endl;
+
+ std::ifstream fromEcc( Ecc.str().c_str() );
+ if ( !fromEcc )
+ {
+ std::cout << "Can't open file [" << Ecc.str() << "]" << std::endl;
+ exit(0);
+ }
+ std::cout << "Open file [" << Ecc.str() << "] : OK" << std::endl;
+ dcmImageName = Ecc.str() + ".dcm";
+
+ if (X2)
+ {
+ LoadImageX2(fromEcc, image, multFact);
+ RotateImage(image, image2, NX*2, NY*2);
+ FlipImage(image2, image2, NY*2, NX*2);
+ MakeDicomImage(image, NY*2, NX*2, dcmImageName, patientName, 1, strStudyUID, strSerieUID, trueSerieDescr.str(), i, multiframe );
+ }
+ else
+ {
+ LoadImage(fromEcc, image, multFact);
+ RotateImage(image, image2, NX, NY);
+ FlipImage(image2, image2, NY, NX);
+ MakeDicomImage(image2, NY, NX, dcmImageName, patientName, 1, strStudyUID, strSerieUID, trueSerieDescr.str(), i, multiframe );
+ }
+ fromEcc.close();
+
+ } // end : for (int i=0; i<numberOfSlices
}
+
+ if (multiframe) {
+ for (int i=0; i<numberOfSlices; i++)
+ {
+ Ecc.str(rootfilename);
+ //Ecc << Ecc.str() << "_s" << i << "_Ecc.txt";
+ Ecc << Ecc.str() << "_s" << i << "_" << serieDescr << ".txt";
+
+ std::ifstream fromEcc( Ecc.str().c_str() );
+ if ( !fromEcc )
+ {
+ std::cout << "Can't open file [" << Ecc.str() << "]" << std::endl;
+ exit(0);
}
+ std::cout << "Open file [" << Ecc.str() << "] : OK" << std::endl;
+ if (X2)
+ {
+ LoadImageX2(fromEcc ,&image[NX*NY*4*i] , multFact);
+ RotateImage(&image[NX*NY*4*i], &image2[NX*NY*4*i], NX*2, NY*2);
+ FlipImage( &image2[NX*NY*4*i], &image2[NX*NY*4*i], NY*2, NX*2);
+ }
+ else
+ {
+ LoadImage(fromEcc, &image[NX*NY*i], multFact );
+ RotateImage(&image[NX*NY*i], &image2[NX*NY*i], NX, NY);
+ FlipImage( &image2[NX*NY*i], &image2[NX*NY*i], NY, NX);
+ }
+
+ fromEcc.close();
+ } // end : for (int i=0; i<numberOfSlices
+
+ // dcmImageName = deb + "_Ecc.dcm";
+ dcmImageName = deb + "_" + serieDescr + ".dcm";
+ if (X2)
+ MakeDicomImage(image2, NY*2, NX*2, dcmImageName, patientName, numberOfSlices, strStudyUID, strSerieUID, serieDescr, 0, multiframe );
+ else
+ MakeDicomImage(image2, NY, NX, dcmImageName, patientName, numberOfSlices, strStudyUID, strSerieUID, serieDescr, 0, multiframe );
+ } // end : if (multiframe)
}
-// =====================================================================================================================================
+//=====================================================================================================================================
void MakeDicomImage(unsigned short int *tabVal, int X, int Y, std::string dcmImageName, const char * patientName, int nbFrames, std::string studyUID, std::string serieUID, std::string SerieDescr, int imgNum, bool m)
{
+//std::cout << "========================> in MakeDicomImage : dcmImageName = [" << dcmImageName << "] NX= " << X << " NY= " << Y << std::endl;
// GDCM_NAME_SPACE::Debug::DebugOn();
std::ostringstream str;
// delete img;
file->Delete();
- fileH->Delete();
+ fileH->Delete();
+ //std::cout << "========================> out of MakeDicomImage : " << std::endl;
}
-
// =====================================================================================================================
-