Program: gdcm
Module: $RCSfile: PcpdenseToDicom.cxx,v $
Language: C++
- Date: $Date: 2008/09/08 08:10:33 $
- Version: $Revision: 1.2 $
+ Date: $Date: 2011/09/06 16:08:07 $
+ Version: $Revision: 1.9 $
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 LoadImageX2(std::ifstream &from, unsigned short int * );
+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);
+
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 ",
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";
else
mult=1;
- if (multiframe)
- image = new unsigned short int[NX*NY*mult*numberOfSlices];
- else
- image = new unsigned short int[NX*NY*mult];
-
-
+ 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];
+ }
// === Ecc ===
strSerieUID = GDCM_NAME_SPACE::Util::CreateUniqueUID();
-
- if (!multiframe) {
-
+
+ serieDescr = "Ecc";
+
+ if (!multiframe) {
for (int i=0; i<numberOfSlices; i++)
{
Ecc.str(rootfilename);
- Ecc << Ecc.str() << "_s" << i << "_Ecc.txt";
+ Ecc << Ecc.str() << "_s" << i << "_Ecc.txt";
std::ifstream fromEcc( Ecc.str().c_str() );
if ( !fromEcc )
exit(0);
}
std::cout << "Open file [" << Ecc.str() << "] : OK" << std::endl;
+ dcmImageName = Ecc.str() + ".dcm";
if (X2)
+ {
LoadImageX2(fromEcc, image);
+ 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, serieDescr, i, multiframe );
+ }
else
- LoadImage(fromEcc, image);
+ {
+ LoadImage(fromEcc, image);
+ RotateImage(image, image2, NX, NY);
+ FlipImage(image2, image2, NY, NX);
+ MakeDicomImage(image2, NY, NX, dcmImageName, patientName, 1, strStudyUID, strSerieUID, serieDescr, i, multiframe );
+ }
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) {
-
+ } // end : for (int i=0; i<numberOfSlices
+ }
+
+ if (multiframe) {
for (int i=0; i<numberOfSlices; i++)
{
Ecc.str(rootfilename);
std::cout << "Open file [" << Ecc.str() << "] : OK" << std::endl;
if (X2)
- LoadImageX2(fromEcc ,&image[NX*NY*i] );
+ {
+ LoadImageX2(fromEcc ,&image[NX*NY*4*i] );
+ 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] );
+ 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";
- MakeDicomImage(image, NX, NY, dcmImageName, patientName, numberOfSlices, strStudyUID, strSerieUID, serieDescr, 0, multiframe );
-
+ 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)
strSerieUID = GDCM_NAME_SPACE::Util::CreateUniqueUID();
+ serieDescr = "perf";
+
if (!multiframe) {
for (int i=0; i<numberOfSlices; i++)
{
fromperf.close();
- dcmImageName = Ecc.str() + ".dcm";
- MakeDicomImage(image, NX, NY, dcmImageName, patientName, 1, strStudyUID, strSerieUID, serieDescr, i, multiframe );
+ dcmImageName = perf.str() + ".dcm";
+
+ if (X2)
+ MakeDicomImage(image, NX*2, NY*2, dcmImageName, patientName, 1, strStudyUID, strSerieUID, serieDescr, i, multiframe );
+ else
+ MakeDicomImage(image, NX, NY, dcmImageName, patientName, 1, strStudyUID, strSerieUID, serieDescr, i, multiframe );
} // end : for (int i=0; i<numberOfSlices
}
std::cout << "Open file [" << perf.str() << "] : OK" << std::endl;
if (X2)
- LoadImageX2(fromperf, &image[NX*NY*i]);
+ LoadImageX2(fromperf, &image[NX*NY*i*4]);
else
LoadImage(fromperf, &image[NX*NY*i] );
} // end : for (int i=0; i<numberOfSlices
dcmImageName = deb + "_perf.dcm";
- MakeDicomImage(image, NX, NY, dcmImageName, patientName, numberOfSlices, strStudyUID, strSerieUID, serieDescr, numberOfSlices, multiframe );
+ if (X2)
+ MakeDicomImage(image, NX*2, NY*2, dcmImageName, patientName, numberOfSlices, strStudyUID, strSerieUID, serieDescr, 0, multiframe );
+ else
+ MakeDicomImage(image, NX, NY, dcmImageName, patientName, numberOfSlices, strStudyUID, strSerieUID, serieDescr, 0, multiframe );
}
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 );
- }
+ serieDescr = "WashoutTc";
if (!multiframe) {
LoadImage(fromWashoutTc,image );
fromWashoutTc.close();
- dcmImageName = Ecc.str() + ".dcm";
- MakeDicomImage(image, NX, NY, dcmImageName, patientName, 1, strStudyUID, strSerieUID, serieDescr, i1, multiframe );
+ dcmImageName = WashoutTc.str() + ".dcm";
+ if (X2)
+ MakeDicomImage(image, NX*2, NY*2, dcmImageName, patientName, 1, strStudyUID, strSerieUID, serieDescr, i1, multiframe );
+ else
+ MakeDicomImage(image, NX, NY, dcmImageName, patientName, 1, strStudyUID, strSerieUID, serieDescr, i1, multiframe );
} // end : for (int i=0; i<numberOfSlices
-
}
- delete []image;
+ 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*4*i]);
+ else
+ LoadImage(fromWashoutTc, &image[NX*NY*i] );
+ fromWashoutTc.close();
+
+ } // end : for (int i=0; i<numberOfSlices
+
+ dcmImageName = deb + "_WashoutTc.dcm";
+ if (X2)
+ MakeDicomImage(image, NX*2, NY*2, dcmImageName, patientName, numberOfSlices, strStudyUID, strSerieUID, serieDescr, 0, multiframe );
+ else
+ MakeDicomImage(image, NX, NY, dcmImageName, patientName, numberOfSlices, strStudyUID, strSerieUID, serieDescr, 0, multiframe );
+ }
+
+ delete []image;
return 1;
}
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 * 1000.); // Why do we multiply by 1000? // JPR
}
+ }
}
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*=1000.; // 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 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;