1 /*=========================================================================
4 Module: $RCSfile: GdcmToBaseline.cxx,v $
6 Date: $Date: 2004/11/30 15:44:44 $
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 =========================================================================*/
18 #include "vtkGdcmReader.h"
19 #include "vtkImageViewer.h"
20 #include "vtkImageData.h"
21 #include "vtkPNGWriter.h"
22 #include "vtkWindowToImageFilter.h"
32 #include "gdcmDataImages.h"
34 int main(int argc, char *argv[])
38 std::cerr << "Usage: " << argv[0] << " image.dcm image.png\n";
42 std::string filename = argv[1];
43 std::cout << "Filename: " << filename << std::endl;
45 //Extract name to find the png file matching:
46 std::string pngfile = argv[2];
47 std::cerr << "PNG file: " << pngfile << std::endl;
49 // Ok for now still use the original image,
50 vtkGdcmReader *reader = vtkGdcmReader::New();
51 reader->SetFileName( filename.c_str() );
52 //reader->SetFileName( "../Testing/Temporary/TestWrite.dcm" );
55 vtkImageViewer *viewer = vtkImageViewer::New();
56 viewer->SetInput ( reader->GetOutput() );
58 vtkFloatingPointType *range = reader->GetOutput()->GetScalarRange();
59 viewer->SetColorWindow (range[1] - range[0]);
60 viewer->SetColorLevel (0.5 * (range[1] + range[0]));
63 reader->GetOutput()->GetDimensions( dim );
64 viewer->SetSize(dim[0], dim[1]);
65 viewer->OffScreenRenderingOn();
69 //For multifame dicom, take a snapshot of the center slice (+/- 1)
70 viewer->SetZSlice( dim[2] / 2 );
76 vtkWindowToImageFilter *wif = vtkWindowToImageFilter::New();
77 wif->SetInput(viewer->GetRenderWindow());
80 vtkPNGWriter *writer=vtkPNGWriter::New();
81 writer->SetFileName(argv[2]);
82 writer->SetInput(wif->GetOutput());