1 /*=========================================================================
4 Module: $RCSfile: exImageLighten.cxx,v $
6 Date: $Date: 2005/10/18 08:35:44 $
7 Version: $Revision: 1.8 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
20 #include "gdcmFileHelper.h"
21 #include "gdcmDocument.h"
22 #include "gdcmDataEntry.h"
23 #include "gdcmSeqEntry.h"
25 #include <stdlib.h> // for exit
27 int main(int argc, char *argv[])
29 std::cout << "-----------------------------------------------" << std::endl;
30 std::cout << "Removes from a full gdcm-readable Dicom image" << std::endl;
31 std::cout << " all the 'Shadow groups' and the 'Sequence' entries"
32 << " Warning : 'Compressed images' are uncompressed"
34 << " : 'YBR images' are converted into 'RGB images'"
36 << " : 'RGB planes' are converted into 'RGB pixels'"
38 << " : 'Palette Color images' are kept 'as is'"
40 std::cout << "-----------------------------------------------" << std::endl;
44 std::cerr << "Usage " << argv[0] << " Source image.dcm "
45 << " Output image.dcm " << std::endl;
49 std::string fileName = argv[1];
50 std::string output = argv[2];
52 // ============================================================
53 // Read the input image.
54 // ============================================================
56 std::cout << argv[1] << std::endl;
58 gdcm::File *f = new gdcm::File();
59 f->SetLoadMode( gdcm::LD_ALL);
60 f->SetFileName( fileName );
64 std::cerr << "Sorry, " << fileName <<" not a gdcm-readable "
69 std::cout << " ... is readable " << std::endl;
71 // ============================================================
74 // ============================================================
76 // Pixel Reading must be done here, to be sure
77 // to load the Palettes Color (if any)
79 // First, create a gdcm::FileHelper
80 gdcm::FileHelper *fh = new gdcm::FileHelper(f);
82 // Load the pixels, DO NOT transform LUT (if any) into RGB Pixels
83 uint8_t *imageDataRaw = fh->GetImageDataRaw();
84 // Get the image data size
85 size_t dataRawSize = fh->GetImageDataRawSize();
87 // ============================================================
88 // Create a new gdcm::Filehelper, to hold new image.
89 // ============================================================
91 gdcm::FileHelper *copy = new gdcm::FileHelper( );
92 copy->SetFileName( output );
95 // ============================================================
96 // Selective copy of the entries (including Pixel Element).
97 // ============================================================
99 gdcm::DocEntry *d = f->GetFirstEntry();
102 // We skip SeqEntries, since user cannot do much with them
103 if ( !(dynamic_cast<gdcm::SeqEntry*>(d))
104 // We skip Shadow Groups, since nobody knows what they mean
105 && !( d->GetGroup()%2 ) )
108 if ( gdcm::DataEntry *de = dynamic_cast<gdcm::DataEntry *>(d) )
110 copy->GetFile()->InsertEntryBinArea( de->GetBinArea(),de->GetLength(),
111 de->GetGroup(),de->GetElement(),
116 // We skip gdcm::SeqEntries
119 d = f->GetNextEntry();
122 // User wants to keep the Palette Color -if any-
123 // and write the image as it was
124 copy->SetImageData(imageDataRaw, dataRawSize);
125 copy->SetWriteModeToRaw();
126 copy->WriteDcmExplVR( output );
128 std::cout << std::endl
129 << "------------------------------------------------------------"