From a4704902060fca3d4b2c6e10702136c8a24fe9c7 Mon Sep 17 00:00:00 2001 From: jpr Date: Tue, 29 Mar 2011 07:45:00 +0000 Subject: [PATCH] uncomitted yet oldies : unMosaic --- Example/CMakeLists.txt | 1 + Example/exUnMosaic.cxx | 133 ++++++++++++++++++++++++++++ Example/exUnMosaic2.cxx | 148 +++++++++++++++++++++++++++++++ Example/exUnMosaicStack.cxx | 171 ++++++++++++++++++++++++++++++++++++ 4 files changed, 453 insertions(+) create mode 100755 Example/exUnMosaic.cxx create mode 100755 Example/exUnMosaic2.cxx create mode 100755 Example/exUnMosaicStack.cxx diff --git a/Example/CMakeLists.txt b/Example/CMakeLists.txt index 3962d224..4083a71b 100644 --- a/Example/CMakeLists.txt +++ b/Example/CMakeLists.txt @@ -6,6 +6,7 @@ INCLUDE_DIRECTORIES( SET(EXAMPLE_SOURCES #names starting with 'ex' are examples #------------------------------------- + exUnMosaic #SingleFrames2Multiframe #Txt2Mat #exDicomRTStructSetFile diff --git a/Example/exUnMosaic.cxx b/Example/exUnMosaic.cxx new file mode 100755 index 00000000..28126d94 --- /dev/null +++ b/Example/exUnMosaic.cxx @@ -0,0 +1,133 @@ +/*========================================================================= + + Program: gdcm + Module: $RCSfile: exUnMosaic.cxx,v $ + Language: C++ + Date: $Date: 2011/03/29 07:45:00 $ + Version: $Revision: 1.1 $ + + Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de + l'Image). All rights reserved. See Doc/License.txt or + http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details. + + 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. + +=========================================================================*/ + +#include // for exit +#include // for sqrt, ceil +#include "gdcmFile.h" +#include "gdcmFileHelper.h" + +bool reorganize_mosaic(const unsigned short *input, const unsigned int *inputdims, unsigned int square, + const unsigned int *outputdims, unsigned short *output ); + + + +bool reorganize_mosaic(const unsigned short *input, const unsigned int *inputdims, unsigned int nbImagesPerRow, + const unsigned int *outputdims, unsigned short *output ) +{ + for(unsigned x = 0; x < outputdims[0]; ++x) + { + for(unsigned y = 0; y < outputdims[1]; ++y) + { + for(unsigned z = 0; z < outputdims[2]; ++z) + { + output[ x + y*outputdims[0] + z*outputdims[0]*outputdims[1] ] = + input[ (x + z * outputdims[0]) + (y + (z/nbImagesPerRow)*outputdims[0])*inputdims[0] ]; + } + } + } + return true; +} + + +int main(int argc, char *argv[]) +{ + + std::string fileName = argv[1]; + std::string outputFileName = argv[2]; + unsigned int nbImagesPerRow = 8; + unsigned int numberOfImagesInMosaic = 52; + + unsigned int inputdims[2]; + inputdims[0] = 1024; + inputdims[1] = 1024; + + unsigned int outputdims[3]; + +// ============================================================ +// Read the input image. +// ============================================================ + + std::cout << argv[1] << std::endl; + + GDCM_NAME_SPACE::File *f = GDCM_NAME_SPACE::File::New(); + f->SetLoadMode( GDCM_NAME_SPACE::LD_ALL); + f->SetFileName( fileName ); + bool res = f->Load(); + + if (!res) { + std::cerr << "Sorry, " << fileName <<" not a gdcm-readable " + << "DICOM / ACR File" + <Delete(); + return 0; + } + std::cout << " ... is readable " << std::endl; + + +// ============================================================ +// Read the Pixels +// +// ============================================================ + + // Pixel Reading must be done here, to be sure + // to load the Palettes Color (if any) + + // First, create a GDCM_NAME_SPACE::FileHelper + GDCM_NAME_SPACE::FileHelper *fh = GDCM_NAME_SPACE::FileHelper::New(f); + + // Load the pixels, DO NOT transform LUT (if any) into RGB Pixels + uint8_t *imageDataRaw = fh->GetImageDataRaw(); + // Get the image data size + size_t dataRawSize = fh->GetImageDataRawSize(); + +// ============================================================ +// Create a new GDCM_NAME_SPACE::Filehelper, to hold new image. +// ============================================================ + + GDCM_NAME_SPACE::FileHelper *copy = GDCM_NAME_SPACE::FileHelper::New( ); + copy->SetFileName( outputFileName ); + // copy->Load(); + + unsigned int div = (unsigned int)ceil(sqrt( (double)numberOfImagesInMosaic ) ); + outputdims[0] = inputdims[0]/ div; + outputdims[1] = inputdims[1] / div; + outputdims[2] = numberOfImagesInMosaic; + +/* + if (outputdims[0] * outputdims[1] * outputdims[2] * 2 != dataRawSize) + { + std::cout << "outputdims[0] : " << outputdims[0] << " outputdims[1] : " << outputdims[1] << " numberOfImagesInMosaic : " << numberOfImagesInMosaic + << " ( = " << outputdims[0] * outputdims[1] * outputdims[2] * 2 << " ) doesn't match with dataRawSize : " << dataRawSize << std::endl; + //exit(0); + } +*/ + + + unsigned short *input = (unsigned short *)imageDataRaw; + + unsigned short *output = (unsigned short *) malloc(outputdims[0] * outputdims[1] * numberOfImagesInMosaic * 2); + + reorganize_mosaic(input, inputdims, + nbImagesPerRow, + outputdims, output); + + FILE *fPixels; + fPixels = fopen(outputFileName.c_str(), "w"); + fwrite(output,2, outputdims[0] * outputdims[1] * numberOfImagesInMosaic, fPixels); +} + diff --git a/Example/exUnMosaic2.cxx b/Example/exUnMosaic2.cxx new file mode 100755 index 00000000..60bd1b07 --- /dev/null +++ b/Example/exUnMosaic2.cxx @@ -0,0 +1,148 @@ +/*========================================================================= + + Program: gdcm + Module: $RCSfile: exUnMosaic2.cxx,v $ + Language: C++ + Date: $Date: 2011/03/29 07:45:00 $ + Version: $Revision: 1.1 $ + + Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de + l'Image). All rights reserved. See Doc/License.txt or + http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details. + + 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. + +=========================================================================*/ + +#include // for exit +#include // for sqrt, ceil +#include "gdcmFile.h" +#include "gdcmFileHelper.h" +#include "vtkGdcmReader.h" + +bool reorganize_mosaic(const unsigned short *input, const unsigned int *inputdims, unsigned int square, + const unsigned int *outputdims, unsigned short *output ); + + + +bool reorganize_mosaic(const unsigned short *input, const unsigned int *inputdims, unsigned int nbImagesPerRow, + const unsigned int *outputdims, unsigned short *output ) +{ + for(unsigned x = 0; x < outputdims[0]; ++x) + { + for(unsigned y = 0; y < outputdims[1]; ++y) + { + for(unsigned z = 0; z < outputdims[2]; ++z) + { + output[ x + y*outputdims[0] + z*outputdims[0]*outputdims[1] ] = + input[ (x + z * outputdims[0]) + (y + (z/nbImagesPerRow)*outputdims[0])*inputdims[0] ]; + } + } + } + return true; +} + + +int main(int argc, char *argv[]) +{ + + std::string fileName = argv[1]; + std::string outputFileName = argv[2]; + unsigned int nbImagesPerRow = 8; + unsigned int numberOfImagesInMosaic = 52; + + unsigned int inputdims[3]; + // inputdims[0] = 1024; + // inputdims[1] = 1024; + + unsigned int outputdims[3]; + +// ============================================================ +// Read the input image. +// ============================================================ + + vtkGdcmReader *reader = vtkGdcmReader::New(); + reader->SetFileName( fileName ); + reader->Update(); + + vtkImageData *vtkimage = reader->GetOutput(); + vtkimage-> + +/* + std::cout << argv[1] << std::endl; + + GDCM_NAME_SPACE::File *f = GDCM_NAME_SPACE::File::New(); + f->SetLoadMode( GDCM_NAME_SPACE::LD_ALL); + f->SetFileName( fileName ); + bool res = f->Load(); + + if (!res) { + std::cerr << "Sorry, " << fileName <<" not a gdcm-readable " + << "DICOM / ACR File" + <Delete(); + return 0; + } + std::cout << " ... is readable " << std::endl; + +*/ + +// ============================================================ +// Read the Pixels +// +// ============================================================ + +/* + // Pixel Reading must be done here, to be sure + // to load the Palettes Color (if any) + + // First, create a GDCM_NAME_SPACE::FileHelper + GDCM_NAME_SPACE::FileHelper *fh = GDCM_NAME_SPACE::FileHelper::New(f); + + // Load the pixels, DO NOT transform LUT (if any) into RGB Pixels + uint8_t *imageDataRaw = fh->GetImageDataRaw(); + // Get the image data size + size_t dataRawSize = fh->GetImageDataRawSize(); + +*/ + + // ============================================================ +// Create a new GDCM_NAME_SPACE::Filehelper, to hold new image. +// ============================================================ + +/* + GDCM_NAME_SPACE::FileHelper *copy = GDCM_NAME_SPACE::FileHelper::New( ); + copy->SetFileName( outputFileName ); + // copy->Load(); +*/ + + unsigned int div = (unsigned int)ceil(sqrt( (double)numberOfImagesInMosaic ) ); + outputdims[0] = inputdims[0]/ div; + outputdims[1] = inputdims[1] / div; + outputdims[2] = numberOfImagesInMosaic; + +/* + if (outputdims[0] * outputdims[1] * outputdims[2] * 2 != dataRawSize) + { + std::cout << "outputdims[0] : " << outputdims[0] << " outputdims[1] : " << outputdims[1] << " numberOfImagesInMosaic : " << numberOfImagesInMosaic + << " ( = " << outputdims[0] * outputdims[1] * outputdims[2] * 2 << " ) doesn't match with dataRawSize : " << dataRawSize << std::endl; + //exit(0); + } +*/ + + + unsigned short *input = (unsigned short *)imageDataRaw; + + unsigned short *output = (unsigned short *) malloc(outputdims[0] * outputdims[1] * numberOfImagesInMosaic * 2); + + reorganize_mosaic(input, inputdims, + nbImagesPerRow, + outputdims, output); + + FILE *fPixels; + fPixels = fopen(outputFileName.c_str(), "w"); + fwrite(output,2, outputdims[0] * outputdims[1] * numberOfImagesInMosaic, fPixels); +} + diff --git a/Example/exUnMosaicStack.cxx b/Example/exUnMosaicStack.cxx new file mode 100755 index 00000000..b065f469 --- /dev/null +++ b/Example/exUnMosaicStack.cxx @@ -0,0 +1,171 @@ +/*========================================================================= + + Program: gdcm + Module: $RCSfile: exUnMosaicStack.cxx,v $ + Language: C++ + Date: $Date: 2011/03/29 07:45:00 $ + Version: $Revision: 1.1 $ + + Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de + l'Image). All rights reserved. See Doc/License.txt or + http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details. + + 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. + +=========================================================================*/ + + +// UNFINISHED ! JPRx + + +#include // for exit +#include // for sqrt, ceil +#include "gdcmFile.h" +#include "gdcmFileHelper.h" + +bool reorganize_mosaic(const unsigned short *input, const unsigned int *inputdims, unsigned int square, + const unsigned int *outputdims, unsigned short *output ); + + + +bool reorganize_mosaic(const unsigned short *input, const unsigned int *inputdims, unsigned int nbImagesPerRow, + const unsigned int *outputdims, unsigned short *output ) +{ + for(unsigned x = 0; x < outputdims[0]; ++x) + { + for(unsigned y = 0; y < outputdims[1]; ++y) + { + for(unsigned z = 0; z < outputdims[2]; ++z) + { + output[ x + y*outputdims[0] + z*outputdims[0]*outputdims[1] ] = + input[ (x + z * outputdims[0]) + (y + (z/nbImagesPerRow)*outputdims[0])*inputdims[0] ]; + } + } + } + return true; +} + + +bool reorganize_mosaic_stack(const unsigned short *input, const unsigned int *inputdims, unsigned int nbImagesPerRow, + const unsigned int *outputdims, unsigned short *output ) +{ + for(unsigned x = 0; x < outputdims[0]; ++x) + { + for(unsigned y = 0; y < outputdims[1]; ++y) + { + for(unsigned z = 0; z < outputdims[2]; ++z) + { + output[ x + y*outputdims[0] + z*outputdims[0]*outputdims[1] ] = + input[ (x + z * outputdims[0]) + (y + (z/nbImagesPerRow)*outputdims[0])*inputdims[0] ]; + } + } + } + return true; +} + + +int main(int argc, char *argv[]) +{ + + std::string fileName = argv[1]; + std::string outputFileName = argv[2]; + unsigned int nbImagesPerRow = 8; + unsigned int numberOfImagesInMosaic = 52; + unsigned int numberMosaics = 52; + + unsigned int inputdims[2]; + inputdims[0] = 1024; + inputdims[1] = 1024; + + unsigned int outputdims[3]; + +// ============================================================ +// Read the input image. +// ============================================================ + + std::cout << argv[1] << std::endl; + + std::cout << "dirName [" << dirName << "]" << std::endl; + + GDCM_NAME_SPACE::DirList dirList(dirName,rec); // gets recursively (or not) the file list + GDCM_NAME_SPACE::DirListType fileList = dirList.GetFilenames(); + GDCM_NAME_SPACE::File *f; + bool res; + + if (fileList.size() == 0) + { + std::cout << "No file found in : [" << dirName << "]" << std::endl; + } + + + + + GDCM_NAME_SPACE::File *f = GDCM_NAME_SPACE::File::New(); + f->SetLoadMode( GDCM_NAME_SPACE::LD_ALL); + f->SetFileName( fileName ); + bool res = f->Load(); + + if (!res) { + std::cerr << "Sorry, " << fileName <<" not a gdcm-readable " + << "DICOM / ACR File" + <Delete(); + return 0; + } + std::cout << " ... is readable " << std::endl; + + +// ============================================================ +// Read the Pixels +// +// ============================================================ + + // Pixel Reading must be done here, to be sure + // to load the Palettes Color (if any) + + // First, create a GDCM_NAME_SPACE::FileHelper + GDCM_NAME_SPACE::FileHelper *fh = GDCM_NAME_SPACE::FileHelper::New(f); + + // Load the pixels, DO NOT transform LUT (if any) into RGB Pixels + uint8_t *imageDataRaw = fh->GetImageDataRaw(); + // Get the image data size + size_t dataRawSize = fh->GetImageDataRawSize(); + + // ============================================================ +// Create a new GDCM_NAME_SPACE::Filehelper, to hold new image. +// ============================================================ + + GDCM_NAME_SPACE::FileHelper *copy = GDCM_NAME_SPACE::FileHelper::New( ); + copy->SetFileName( outputFileName ); + // copy->Load(); + + unsigned int div = (unsigned int)ceil(sqrt( (double)numberOfImagesInMosaic ) ); + outputdims[0] = inputdims[0]/ div; + outputdims[1] = inputdims[1] / div; + outputdims[2] = numberOfImagesInMosaic; + +/* + if (outputdims[0] * outputdims[1] * outputdims[2] * 2 != dataRawSize) + { + std::cout << "outputdims[0] : " << outputdims[0] << " outputdims[1] : " << outputdims[1] << " numberOfImagesInMosaic : " << numberOfImagesInMosaic + << " ( = " << outputdims[0] * outputdims[1] * outputdims[2] * 2 << " ) doesn't match with dataRawSize : " << dataRawSize << std::endl; + //exit(0); + } +*/ + + + unsigned short *input = (unsigned short *)imageDataRaw; + + unsigned short *output = (unsigned short *) malloc(outputdims[0] * outputdims[1] * numberOfImagesInMosaic * 2); + + reorganize_mosaic(input, inputdims, + nbImagesPerRow, + outputdims, output); + + FILE *fPixels; + fPixels = fopen(outputFileName.c_str(), "w"); + fwrite(output,2, outputdims[0] * outputdims[1] * numberOfImagesInMosaic, fPixels); +} + -- 2.45.0