1 /*=========================================================================
4 Module: $RCSfile: exImageLighten.cxx,v $
6 Date: $Date: 2005/07/06 15:49:31 $
7 Version: $Revision: 1.2 $
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 "gdcmValEntry.h"
23 #include "gdcmBinEntry.h"
24 #include "gdcmSeqEntry.h"
26 #include <stdlib.h> // for exit
28 int main(int argc, char *argv[])
32 std::cout << "-----------------------------------------------" << std::endl;
33 std::cout << "Removes from a full gdcm-readable Dicom image" << std::endl;
34 std::cout << " all the 'Shadow groups' and the 'Sequence' entries"
35 << " Warning : 'Compressed images' are uncompressed"
37 << " : 'YBR images' are converted into 'RGB images'"
39 << " : 'RGB planes' are converted into 'RGB pixels'"
41 << " : 'Palette Color images' are kept 'as is'"
43 std::cout << "-----------------------------------------------" << std::endl;
47 std::cerr << "Usage " << argv[0] << " Source image.dcm "
48 << " Output image.dcm " << std::endl;
52 std::string fileName = argv[1];
53 std::string output = argv[2];
55 // ============================================================
56 // Read the input image.
57 // ============================================================
59 std::cout << argv[1] << std::endl;
61 f1 = new gdcm::File( fileName );
62 if (!f1->IsReadable()) {
63 std::cerr << "Sorry, " << fileName <<" not a gdcm-readable "
68 std::cout << " ... is readable " << std::endl;
70 // ============================================================
73 // ============================================================
75 // Pixel Reading must be done here, to be sure
76 // to load the Palettes Color (if any)
78 // First, create a gdcm::FileHelper
79 gdcm::FileHelper *fh1 = new gdcm::FileHelper(f1);
81 // Load the pixels, DO NOT transform LUT (if any) into RGB Pixels
82 uint8_t *imageDataRaw = fh1->GetImageDataRaw();
83 // Get the image data size
84 size_t dataRawSize = fh1->GetImageDataRawSize();
86 // ============================================================
87 // Create a new gdcm::Filehelper, to hold new image.
88 // ============================================================
90 gdcm::FileHelper *copy = new gdcm::FileHelper( output );
92 // ============================================================
93 // Selective copy of the entries (including Pixel Element).
94 // ============================================================
96 gdcm::DocEntry *d = f1->GetFirstEntry();
98 d = f1->GetFirstEntry();
101 // We skip SeqEntries, since user cannot do much with them
102 if ( !(dynamic_cast<gdcm::SeqEntry*>(d))
103 // We skip Shadow Groups, since nobody knows what they mean
104 && !( d->GetGroup()%2 ) )
107 if ( gdcm::BinEntry *b = dynamic_cast<gdcm::BinEntry*>(d) )
109 copy->GetFile()->InsertBinEntry( b->GetBinArea(),b->GetLength(),
110 b->GetGroup(),b->GetElement(),
113 else if ( gdcm::ValEntry *v = dynamic_cast<gdcm::ValEntry*>(d) )
115 copy->GetFile()->InsertValEntry( v->GetValue(),
116 v->GetGroup(),v->GetElement(),
121 // We skip gdcm::SeqEntries
124 d = f1->GetNextEntry();
127 // User wants to keep the Palette Color -if any-
128 // and write the image as it was
129 copy->SetImageData(imageDataRaw, dataRawSize);
130 copy->SetWriteModeToRaw();
131 copy->WriteDcmExplVR( output );
133 std::cout << std::endl
134 << "------------------------------------------------------------"