1 /*=========================================================================
4 Module: $RCSfile: exImageLighten.cxx,v $
6 Date: $Date: 2005/02/09 14:39:49 $
7 Version: $Revision: 1.1 $
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 int main(int argc, char *argv[])
30 std::cout << "-----------------------------------------------" << std::endl;
31 std::cout << "Removes from a full gdcm-readable Dicom image" << std::endl;
32 std::cout << " all the 'Shadow groups' and the 'Sequence' entries"
33 << " Warning : 'Compressed images' are uncompressed"
35 << " : 'YBR images' are converted into 'RGB images'"
37 << " : 'RGB planes' are converted into 'RGB pixels'"
39 << " : 'Palette Color images' are kept 'as is'"
41 std::cout << "-----------------------------------------------" << std::endl;
45 std::cerr << "Usage " << argv[0] << " Source image.dcm "
46 << " Output image.dcm " << std::endl;
50 std::string fileName = argv[1];
51 std::string output = argv[2];
53 // ============================================================
54 // Read the input image.
55 // ============================================================
57 std::cout << argv[1] << std::endl;
59 f1 = new gdcm::File( fileName );
60 if (!f1->IsReadable()) {
61 std::cerr << "Sorry, " << fileName <<" not a gdcm-readable "
66 std::cout << " ... is readable " << std::endl;
68 // ============================================================
71 // ============================================================
73 // Pixel Reading must be done here, to be sure
74 // to load the Palettes Color (if any)
76 // First, create a gdcm::FileHelper
77 gdcm::FileHelper *fh1 = new gdcm::FileHelper(f1);
79 // Load the pixels, DO NOT transform LUT (if any) into RGB Pixels
80 uint8_t *imageDataRaw = fh1->GetImageDataRaw();
81 // Get the image data size
82 size_t dataRawSize = fh1->GetImageDataRawSize();
84 // ============================================================
85 // Create a new gdcm::Filehelper, to hold new image.
86 // ============================================================
88 gdcm::FileHelper *copy = new gdcm::FileHelper( output );
90 // ============================================================
91 // Selective copy of the entries (including Pixel Element).
92 // ============================================================
94 gdcm::DocEntry *d = f1->GetFirstEntry();
96 d = f1->GetFirstEntry();
99 // We skip SeqEntries, since user cannot do much with them
100 if ( !(dynamic_cast<gdcm::SeqEntry*>(d))
101 // We skip Shadow Groups, since nobody knows what they mean
102 && !( d->GetGroup()%2 ) )
105 if ( gdcm::BinEntry *b = dynamic_cast<gdcm::BinEntry*>(d) )
107 copy->GetFile()->InsertBinEntry( b->GetBinArea(),b->GetLength(),
108 b->GetGroup(),b->GetElement(),
111 else if ( gdcm::ValEntry *v = dynamic_cast<gdcm::ValEntry*>(d) )
113 copy->GetFile()->InsertValEntry( v->GetValue(),
114 v->GetGroup(),v->GetElement(),
119 // We skip gdcm::SeqEntries
122 d = f1->GetNextEntry();
125 // User wants to keep the Palette Color -if any-
126 // and write the image as it was
127 copy->SetImageData(imageDataRaw, dataRawSize);
128 copy->SetWriteModeToRaw();
129 copy->WriteDcmExplVR( output );
131 std::cout << std::endl
132 << "------------------------------------------------------------"