本文整理汇总了C++中readertype::Pointer::SetImageIO方法的典型用法代码示例。如果您正苦于以下问题:C++ Pointer::SetImageIO方法的具体用法?C++ Pointer::SetImageIO怎么用?C++ Pointer::SetImageIO使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类readertype::Pointer
的用法示例。
在下文中一共展示了Pointer::SetImageIO方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadImage
// ------------------------------------------------------------------------
void LoadImage(const std::string &filename, ImageType::Pointer &image)
{
typedef itk::Image<unsigned short, 4> InImageType;
typedef itk::ImageFileReader<InImageType> ReaderType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(filename);
reader->SetImageIO(itk::NrrdImageIO::New());
reader->Update();
typedef itk::ExtractImageFilter<InImageType, ImageType> ExtractorType;
ExtractorType::Pointer extractor = ExtractorType::New();
extractor->SetInput(reader->GetOutput());
InImageType::RegionType exRegion = reader->GetOutput()->GetLargestPossibleRegion();
InImageType::SizeType exSize = exRegion.GetSize();
InImageType::IndexType exIndex = exRegion.GetIndex();
exSize[3] = 0;
exIndex[3] = 0;
exRegion.SetSize(exSize);
exRegion.SetIndex(exIndex);
extractor->SetExtractionRegion(exRegion);
extractor->SetDirectionCollapseToSubmatrix();
extractor->Update();
image = extractor->GetOutput();
}
示例2: loadImageSeries
// ------------------------------------------------------------------------
void loadImageSeries(SeriesTransform &series,
const unsigned int &instanceNumbers)
{
// resize the image vector
series.images.resize(series.imageFilenames.size());
typedef itk::GDCMImageIO IOType;
typedef itk::ImageFileReader<ImageType> ReaderType;
for(unsigned int i = 0; i < instanceNumbers; i++)
{
ReaderType::Pointer reader = ReaderType::New();
reader->SetImageIO(IOType::New());
reader->SetFileName(series.imageFilenames[i]);
try
{
reader->Update();
}
catch(itk::ExceptionObject &e)
{
std::cout << e << std::endl;
exit(1);
}
series.images[i] = reader->GetOutput();
}
}
示例3: retrieveITKImage
//read CT image
void CTImageTreeItem::retrieveITKImage(QProgressDialog *progress, int progressScale, int progressBase) {
//define and create file reader
typedef ReaderProgress::ReaderType ReaderType;
ReaderType::Pointer imageReader = ReaderType::New();
ReaderType::FileNamesContainer fc;
//assign filenames
fc.assign(m_fnList.begin(), m_fnList.end());
//set ImageIO and filenames
itk::GDCMImageIO::Pointer gdcmImageIO = itk::GDCMImageIO::New();
imageReader->SetImageIO( gdcmImageIO );
imageReader->SetFileNames(fc);
//create reader progress
ReaderProgress::Pointer progressor = ReaderProgress::New();
if (progress)
{
progressor->setDialog( progress, progressScale, progressBase );
imageReader->AddObserver(itk::AnyEvent(), progressor);
}
//try to read the images
try {
imageReader->Update();
}catch( itk::ExceptionObject & excep ) {
std::cerr << "Exception caught !" << std::endl;
std::cerr << excep << std::endl;
}
//assign the reader output to an image pointer
ImageType::Pointer imagePtr = imageReader->GetOutput();
setITKImage(imagePtr, 1);
//emit signal, that data has changed
m_model->dataChanged(m_model->createIndex(childNumber(),0,parent()),m_model->createIndex(childNumber(),columnCount()-1,parent()));
}
示例4: main
int main(int argc, char** argv) {
if(argc != 3){
std::cout << "Usage: Test2DImage inputFilename outputFilename";
return 1;
}
typedef signed int InputPixelType;
const unsigned int Dimension = 2;
typedef itk::Image<InputPixelType, Dimension> InputImageType;
typedef itk::RGBPixel<unsigned char> RGBPixelType;
typedef itk::Image<RGBPixelType, 2> RGBImageType;
typedef itk::ImageFileReader<InputImageType> ReaderType;
typedef itk::ImageFileWriter<RGBImageType> WriterType;
typedef itk::GDCMImageIO ImageIOType;
typedef itk::GradientAnisotropicDiffusionImageFilter<InputImageType,
InputImageType> DiffusionFilterType;
typedef itk::GradientMagnitudeImageFilter<InputImageType, InputImageType>
GradientMagnitudeFilterType;
typedef itk::Functor::ScalarToRGBPixelFunctor<int> ColorMapFunctorType;
typedef itk::UnaryFunctorImageFilter<InputImageType,
RGBImageType, ColorMapFunctorType> ColorMapFilterType;
typedef itk::JPEGImageIO JImageIOType;
ReaderType::Pointer reader = ReaderType::New();
WriterType::Pointer writer = WriterType::New();
ImageIOType::Pointer GDCMImageIO = ImageIOType::New();
JImageIOType::Pointer JPEGImageIO = JImageIOType::New();
ColorMapFilterType::Pointer colormapper = ColorMapFilterType::New();
reader->SetFileName(argv[1]);
reader->SetImageIO(GDCMImageIO);
try {
reader->Update();
}
catch (itk::ExceptionObject & e) {
std::cerr << "exception in file reader " << std::endl;
std::cerr << e << std::endl;
return 1;
}
DiffusionFilterType::Pointer diffusion = DiffusionFilterType::New();
diffusion->SetNumberOfIterations(1);
diffusion->SetConductanceParameter(4);
diffusion->SetTimeStep(0.125);
GradientMagnitudeFilterType::Pointer gradient = GradientMagnitudeFilterType::New();
diffusion->SetInput(reader->GetOutput());
gradient->SetInput(diffusion->GetOutput());
gradient->Update();
MyWatershedSegmenter<InputImageType> watershed(gradient->GetOutput());
watershed.buildLowerCompleteImage();
watershed.buildLabeledImage();
colormapper->SetInput(watershed.returnFinalImage());
writer->SetInput(colormapper->GetOutput());
writer->UseInputMetaDataDictionaryOff();
writer->SetImageIO(JPEGImageIO);
writer->SetFileName(argv[2]);
writer->Update();
}
示例5: extractPointAndNormalFromMask
bool extractPointAndNormalFromMask(string filename, CVector3 &point, CVector3 &normal1, CVector3 &normal2)
{
ReaderType::Pointer reader = ReaderType::New();
itk::NiftiImageIO::Pointer io = itk::NiftiImageIO::New();
reader->SetImageIO(io);
reader->SetFileName(filename);
try {
reader->Update();
} catch( itk::ExceptionObject & e ) {
cerr << "Exception caught while reading input image " << endl;
cerr << e << endl;
return false;
}
ImageType::Pointer image = reader->GetOutput();
vector<CVector3> result;
ImageType::IndexType ind;
itk::Point<double,3> pnt;
ImageIterator it( image, image->GetRequestedRegion() );
it.GoToBegin();
while(!it.IsAtEnd())
{
if (it.Get()!=0)
{
ind = it.GetIndex();
image->TransformIndexToPhysicalPoint(ind, pnt);
bool added = false;
if (result.size() == 0) {
result.push_back(CVector3(pnt[0],pnt[1],pnt[2]));
added = true;
}
else {
for (vector<CVector3>::iterator it=result.begin(); it!=result.end(); it++) {
if (pnt[2] < (*it)[2]) {
result.insert(it, CVector3(pnt[0],pnt[1],pnt[2]));
added = true;
break;
}
}
}
if (!added) result.push_back(CVector3(pnt[0],pnt[1],pnt[2]));
}
++it;
}
if (result.size() != 3) {
cerr << "Error: Not enough of too many points in the binary mask. Number of point needed = 3. Detected points = " << result.size() << endl;
return false;
}
point = result[1];
normal1 = (result[0]-result[1]).Normalize();
normal2 = (result[2]-result[1]).Normalize();
return true;
}
示例6: writeSeries
// ------------------------------------------------------------------------
void DicomParser::writeSeries(const DicomSeries &series, const QString &outputFolder)
{
// create the series name
QString name = QString::fromStdString(series.description);
name.replace(" ","_");
name += "_" + QString::number(series.images.front().seriesNumber);
name += ".nrrd";
QDir path(outputFolder);
QString fullPath = path.absoluteFilePath(name);
std::vector<DicomImage> images = series.images;
std::sort(images.begin(), images.end());
// write and build the output images
typedef itk::Image<unsigned short, 3> ImageType;
typedef itk::Image<unsigned short, 4> OutputImageType;
typedef itk::ImageFileReader<ImageType> ReaderType;
typedef itk::JoinSeriesImageFilter<ImageType, OutputImageType> JoinerType;
JoinerType::Pointer joiner = JoinerType::New();
ImageType::Pointer orig;
for(unsigned int i = 0; i < images.size(); i++)
{
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(images[i].filename);
std::cout << images[i].filename << std::endl;
reader->SetImageIO(itk::GDCMImageIO::New());
reader->Update();
ImageType::Pointer im = reader->GetOutput();
if(i == 0) orig = im;
im->SetOrigin(orig->GetOrigin());
im->SetDirection(orig->GetDirection());
im->SetSpacing(orig->GetSpacing());
joiner->SetInput(i, reader->GetOutput());
}
std::cout << joiner->GetOutput()->GetDirection() << std::endl;
typedef itk::ImageFileWriter<OutputImageType> WriterType;
WriterType::Pointer writer = WriterType::New();
writer->SetInput(joiner->GetOutput());
writer->SetFileName(fullPath.toStdString());
writer->SetImageIO(itk::NrrdImageIO::New());
writer->Update();
}
示例7: getImage
FilterImageType::Pointer getImage(const FileNamesContainer &filenames, DictionaryArray &dictArray) {
typedef itk::ImageSeriesReader< FilterImageType > ReaderType;
ReaderType::Pointer reader = ReaderType::New();
ImageIOType::Pointer gdcmImageIO = ImageIOType::New();
reader->SetImageIO( gdcmImageIO );
reader->SetFileNames(filenames);
reader->Update();
ReaderType::DictionaryArrayRawPointer dict;
dict = reader->GetMetaDataDictionaryArray();
for( ReaderType::DictionaryArrayType::const_iterator it = dict->begin(); it != dict->end(); ++it) {
dictArray.push_back( **it );
}
return reader->GetOutput();
}
示例8:
itk::Image<unsigned char, 3>::Pointer boner::Importer::import(std::string path)
{
itk::Image<unsigned char, 3>::Pointer image;
typedef itk::ImageSeriesReader<itk::Image<unsigned char, 3>> ReaderType;
ReaderType::Pointer reader = ReaderType::New();
itk::GDCMSeriesFileNames::Pointer namegenerator = itk::GDCMSeriesFileNames::New();
namegenerator->SetInputDirectory(path);
reader->SetImageIO(itk::GDCMImageIO::New());
reader->SetFileNames(namegenerator->GetInputFileNames());
image = reader->GetOutput();
image->Update();
return image;
}
示例9: Compute
// ------------------------------------------------------------------------
void InitialTransformExtractor::Compute()
{
GetFilenames(m_Filenames);
BuildMapping(m_Mapping);
std::string referenceFilename = GetReferenceImageFilename();
// load the reference file
typedef itk::ImageFileReader<ImageType> ReaderType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(referenceFilename);
reader->SetImageIO(itk::GDCMImageIO::New());
reader->Update();
ImageType::Pointer refImage = reader->GetOutput();
// flip the x and y axis
typedef itk::PermuteAxesImageFilter<ImageType> FlipperType;
FlipperType::Pointer flipper = FlipperType::New();
itk::FixedArray<unsigned int, 3> order;
order[0] = 1;
order[1] = 0;
order[2] = 2;
flipper->SetOrder(order);
flipper->SetInput(refImage);
flipper->Update();
//refImage = flipper->GetOutput();
// transformation is the negative origin of the reference
ImageType::PointType origin = refImage->GetOrigin();
m_Translation[0] = -origin[0];
m_Translation[1] = -origin[1];
m_Translation[2] = -origin[2];
m_Rotation = refImage->GetDirection().GetInverse();
m_Reference = refImage;
}
示例10: memcpy
void
NrrdPlugin::readSlice(int idx[3], int sz[3],
int nbytes, uchar *slice)
{
typedef itk::Image<T, 3> ImageType;
typedef itk::ImageFileReader<ImageType> ReaderType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(m_fileName[0].toAscii().data());
typedef itk::NrrdImageIO NrrdIOType;
NrrdIOType::Pointer nrrdIO = NrrdIOType::New();
reader->SetImageIO(nrrdIO);
typedef itk::RegionOfInterestImageFilter<ImageType,ImageType> RegionExtractor;
ImageType::RegionType region;
ImageType::SizeType size;
ImageType::IndexType index;
index[2] = idx[2];
index[1] = idx[1];
index[0] = idx[0];
size[2] = sz[2];
size[1] = sz[1];
size[0] = sz[0];
region.SetIndex(index);
region.SetSize(size);
// Extract the relevant sub-region.
RegionExtractor::Pointer extractor = RegionExtractor::New();
extractor->SetInput(reader->GetOutput());
extractor->SetRegionOfInterest(region);
extractor->Update();
ImageType *dimg = extractor->GetOutput();
char *tdata = (char*)(dimg->GetBufferPointer());
memcpy(slice, tdata, nbytes);
}
示例11: main
//.........这里部分代码省略.........
// extract the image information
std::string descriptionStr = mapping[fname][seriesDescription];
std::string instanceNumberStr = mapping[fname][instanceNumber];
QString description = QString::fromStdString(descriptionStr);
unsigned int instanceNumber = QString::fromStdString(instanceNumberStr).toInt();
// check that the description is a short axis one and is instance 1
if(instanceNumber == 1 && description.contains("sa", Qt::CaseInsensitive))
{
targetFilenames.push_back(filenames[i]);
}
}
// sort the images based on their slice position
/*
gdcm::Sorter sorter;
sorter.SetSortFunction(position_sort);
sorter.StableSort(targetFilenames);
gdcm::Directory::FilenamesType sorted = sorter.GetFilenames();
for(unsigned int i = 0; i < sorted.size(); i++)
{
const char * fname = sorted[i].c_str();
std::string position = mapping[fname][imagePosition];
std::cout << position << std::endl;
std::cout << mapping[fname][sliceLocation] << std::endl;
}
*/
std::cout << targetFilenames.size() << std::endl;
// find the slice with the smallest slice position
double smallest = 1000000.0;
int smallestIndex;
for(unsigned int i = 0; i < targetFilenames.size(); i++)
{
const char * fname = targetFilenames[i].c_str();
std::string slicePosition = mapping[fname][sliceLocation];
double pos = QString::fromStdString(slicePosition).toDouble();
std::cout << pos << std::endl;
if(pos < smallest)
{
smallest = pos;
smallestIndex = i;
}
}
// load the image
typedef itk::Image<unsigned short, 3> ImageType;
typedef itk::ImageFileReader<ImageType> ReaderType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(targetFilenames[smallestIndex]);
reader->SetImageIO(itk::GDCMImageIO::New());
reader->Update();
// flip the x and y axis
typedef itk::PermuteAxesImageFilter<ImageType> FlipperType;
FlipperType::Pointer flipper = FlipperType::New();
itk::FixedArray<unsigned int, 3> order;
order[0] = 1;
order[1] = 0;
order[2] = 2;
flipper->SetOrder(order);
flipper->SetInput(reader->GetOutput());
flipper->Update();
ImageType::Pointer referenceImage = flipper->GetOutput();
ImageType::DirectionType direction = referenceImage->GetDirection();
direction.SetIdentity();
referenceImage->SetDirection(direction);
ImageType::PointType origin = referenceImage->GetOrigin();
origin.Fill(20.0);
referenceImage->SetOrigin(origin);
ImageType::SpacingType spacing;
spacing.Fill(1.0);
referenceImage->SetSpacing(spacing);
flipper->GetOutput()->Print(std::cout);
typedef itk::ImageFileWriter<ImageType> WriterType;
WriterType::Pointer writer = WriterType::New();
writer->SetInput(referenceImage);
writer->SetImageIO(itk::NrrdImageIO::New());
writer->SetFileName("test.nrrd");
writer->Update();
std::cout << targetFilenames[smallestIndex] << std::endl;
return 0;
}
示例12: main
//.........这里部分代码省略.........
typedef itk::GDCMSeriesFileNames NamesGeneratorType;
NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();
ReaderType::Pointer reader = ReaderType::New();
typedef itk::GDCMImageIO ImageIOType;
ImageIOType::Pointer dicomIO = ImageIOType::New();
nameGenerator->SetRecursive(true);
nameGenerator->SetUseSeriesDetails(true);
nameGenerator->AddSeriesRestriction("0008|0021");
nameGenerator->SetDirectory(dicomDirectory);
//get all the series (by series UID) under the input folder
typedef std::vector< std::string > SeriesIdContainer;
const SeriesIdContainer & seriesUID = nameGenerator->GetSeriesUIDs();
SeriesIdContainer::const_iterator seriesItr = seriesUID.begin();
SeriesIdContainer::const_iterator seriesEnd = seriesUID.end();
//get the correspondence between series UID and PatientID,studyId,studyDate,accessNumber,seriesNumber,seriesDescription
//key is series UID, vector<string> is PatientID,studyID,studyDate,accessNumber,seriesNumber,seriesDescription
map< string, vector<string> > seriesUidToOtherStuff;
seriesItr = seriesUID.begin();
while (seriesItr != seriesUID.end())
{
string seriesIdentifier = seriesItr->c_str();
//get file names belong to specific series
vector< string > fileNames = nameGenerator->GetFileNames(seriesIdentifier);
vector< string > otherStuff;
//read tags(PatientID StudyID StudyDate Access# Series# SeriesDescription) value from the first file of each series
if (!fileNames.empty())
{
reader2D->SetFileName(fileNames[0]);
reader2D->SetImageIO(dicomIO);
try
{
reader2D->UpdateLargestPossibleRegion(); //do not use reader->Update(),since image size is different across series.
}
catch (itk::ExceptionObject &ex)
{
cout << ex << endl;
return 1;
}
typedef itk::MetaDataDictionary DictionaryType;
const DictionaryType & dictionary = dicomIO->GetMetaDataDictionary();
typedef itk::MetaDataObject< std::string > MetaDataStringType;
DictionaryType::ConstIterator itr = dictionary.Begin();
DictionaryType::ConstIterator end = dictionary.End();
for (int i = 0; i < tags.size(); i++)
{
string entryId = tags[i];
DictionaryType::ConstIterator tagItr = dictionary.Find( entryId );
if( tagItr != end )
{
MetaDataStringType::ConstPointer entryvalue =dynamic_cast<const MetaDataStringType *>(tagItr->second.GetPointer() );
if( entryvalue )//entry found
{
string tagvalue = entryvalue->GetMetaDataObjectValue();
tagvalue = regex_replace(tagvalue, regex("^ +| +$|( ) +"), "$1");//remove leading,trailing and extra white space
otherStuff.push_back(tagvalue);
}
else
{
otherStuff.push_back("EntryNotFound");
示例13: convert
void QtDcmConvert::convert()
{
if (QtDcmPreferences::instance()->useDcm2nii())
{
QString program = QtDcmPreferences::instance()->getDcm2niiPath();
QStringList arguments;
arguments << "-x" << "N";
arguments << "-r" << "N";
arguments << "-g" << "N";
arguments << "-o" << d->outputDirectory << d->inputDirectory;
QProcess * process = new QProcess(this);
process->setStandardOutputFile(d->tempDirectory + QDir::separator() + "logs" + QDir::separator() + d->serieUID + ".txt");
process->start(program, arguments);
process->waitForFinished();
delete process;
}
else
{
typedef signed short PixelType;
const unsigned int Dimension = 3;
typedef itk::Image< PixelType, Dimension > ImageType;
typedef itk::ImageSeriesReader< ImageType > ReaderType;
typedef itk::ImageFileWriter<ImageType> WriterType;
typedef itk::GDCMImageIO ImageIOType;
typedef itk::GDCMSeriesFileNames NamesGeneratorType;
typedef std::vector< std::string > FileNamesContainer;
typedef std::vector< std::string > SeriesIdContainer;
// ImageType::Pointer image = 0;
ReaderType::Pointer reader = ReaderType::New();
ImageIOType::Pointer dicomIO = ImageIOType::New();
NamesGeneratorType::Pointer inputNames = NamesGeneratorType::New();
inputNames->SetUseSeriesDetails ( true );
inputNames->AddSeriesRestriction ( "0008|0021" );
inputNames->AddSeriesRestriction ( "0020,0037" );
inputNames->LoadSequencesOn();
inputNames->LoadPrivateTagsOn();
inputNames->SetInputDirectory ( d->inputDirectory.toStdString() );
try
{
const SeriesIdContainer & seriesUID = inputNames->GetSeriesUIDs();
std::string seriesIdentifier = seriesUID.begin()->c_str();
FileNamesContainer filenames = inputNames->GetFileNames ( seriesIdentifier );
dicomIO->SetFileName ( filenames.begin()->c_str() );
try
{
dicomIO->ReadImageInformation();
}
catch ( itk::ExceptionObject &e )
{
qDebug() << e.GetDescription();
return;
}
reader->UseStreamingOn();
reader->SetFileNames ( filenames );
reader->SetImageIO ( dicomIO );
try
{
reader->Update();
}
catch ( itk::ExceptionObject &excp )
{
std::cerr << excp << std::endl;
return;
}
// IteratorType itOut;
//
// image = reader->GetOutput();
//
// RegionType region;
// region.SetSize ( 0, image->GetLargestPossibleRegion().GetSize() [0] );
// region.SetSize ( 1, image->GetLargestPossibleRegion().GetSize() [1] );
// region.SetSize ( 2, image->GetLargestPossibleRegion().GetSize() [2] );
// image->SetRegions ( region );
// image->Allocate();
// SpacingType spacing;
// spacing[0] = image->GetSpacing() [0];
// spacing[1] = image->GetSpacing() [1];
// spacing[2] = image->GetSpacing() [2];
// spacing[3] = 1;
// image->SetSpacing ( spacing );
// PointType origin;
// origin[0] = image->GetOrigin() [0];
// origin[1] = image->GetOrigin() [1];
// origin[2] = image->GetOrigin() [2];
// origin[3] = 0;
// image->SetOrigin ( origin );
// DirectionType direction;
// for ( unsigned int i=0; i<4; i++ )
// for ( unsigned int j=0; j<4; j++ )
// {
// if ( ( i < 3 ) && ( j < 3 ) )
//.........这里部分代码省略.........
示例14: loadImages
// ------------------------------------------------------------------------
void DicomParser::loadImages()
{
// group the series into sa and not sa
DicomSeriesList saList;
DicomSeriesList otherList;
for(unsigned int i = 0; i < series.size(); i++)
{
std::string description = series[i].description;
QString desc = QString::fromStdString(description);
if(desc.contains("Cine_SA"))
saList.push_back(series[i]);
else if(desc.contains("cine_SA"))
saList.push_back(series[i]);
else if(desc.contains("Cine_sa"))
saList.push_back(series[i]);
else if(desc.contains("Cine_ipat SA"))
saList.push_back(series[i]);
//else if(desc.contains("sa"))
//saList.push_back(series[i]);
else
otherList.push_back(series[i]);
}
// sort the sa list based on position
std::sort(saList.begin(), saList.end(), series_sort);
std::sort(otherList.begin(), otherList.end(), series_sort);
for(unsigned int i = 0; i < saList.size(); i++)
{
seriesAgain.push_back(saList[i]);
}
for(unsigned int i = 0; i < otherList.size(); i++)
{
seriesAgain.push_back(otherList[i]);
}
for(unsigned int i = 0; i < seriesAgain.size(); i++)
{
std::string filename = seriesAgain[i].images.front().filename;
typedef itk::Image<unsigned short,3> ImageType;
typedef itk::ImageFileReader<ImageType> ReaderType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetImageIO(itk::GDCMImageIO::New());
reader->SetFileName(filename);
typedef itk::ImageToVTKImageFilter<ImageType> VTKFilterType;
VTKFilterType::Pointer vtkFilter = VTKFilterType::New();
vtkFilter->SetInput(reader->GetOutput());
vtkFilter->Update();
vtkSmartPointer<vtkImageData> image =
vtkSmartPointer<vtkImageData>::New();
image->DeepCopy(vtkFilter->GetOutput());
image->Print(std::cout);
vtkSmartPointer<vtkImageSliceMapper> mapper =
vtkSmartPointer<vtkImageSliceMapper>::New();
mapper->SetInputData(image);
vtkSmartPointer<vtkImageSlice> actor =
vtkSmartPointer<vtkImageSlice>::New();
actor->SetMapper(mapper);
actor->GetProperty()->SetColorLevel(177.48);
actor->GetProperty()->SetColorWindow(512.04);
images.push_back(actor);
}
}
示例15: readImage
virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
std::string ext = osgDB::getLowerCaseFileExtension(file);
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;
std::string fileName = osgDB::findDataFile( file, options );
if (fileName.empty()) return ReadResult::FILE_NOT_FOUND;
notice()<<"Reading DICOM file "<<fileName<<std::endl;
typedef unsigned short PixelType;
const unsigned int Dimension = 3;
typedef itk::Image< PixelType, Dimension > ImageType;
typedef itk::ImageFileReader< ImageType > ReaderType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( fileName.c_str() );
typedef itk::GDCMImageIO ImageIOType;
ImageIOType::Pointer gdcmImageIO = ImageIOType::New();
reader->SetImageIO( gdcmImageIO );
try
{
reader->Update();
}
catch (itk::ExceptionObject & e)
{
std::cerr << "exception in file reader " << std::endl;
std::cerr << e.GetDescription() << std::endl;
std::cerr << e.GetLocation() << std::endl;
return ReadResult::ERROR_IN_READING_FILE;
}
ImageType::Pointer inputImage = reader->GetOutput();
ImageType::RegionType region = inputImage->GetBufferedRegion();
ImageType::SizeType size = region.GetSize();
ImageType::IndexType start = region.GetIndex();
//inputImage->GetSpacing();
//inputImage->GetOrigin();
unsigned int width = size[0];
unsigned int height = size[1];
unsigned int depth = size[2];
osg::RefMatrix* matrix = new osg::RefMatrix;
notice()<<"width = "<<width<<" height = "<<height<<" depth = "<<depth<<std::endl;
for(unsigned int i=0; i<Dimension; ++i)
{
(*matrix)(i,i) = inputImage->GetSpacing()[i];
(*matrix)(3,i) = inputImage->GetOrigin()[i];
}
osg::Image* image = new osg::Image;
image->allocateImage(width, height, depth, GL_LUMINANCE, GL_UNSIGNED_BYTE, 1);
unsigned char* data = image->data();
typedef itk::ImageRegionConstIterator< ImageType > IteratorType;
IteratorType it(inputImage, region);
it.GoToBegin();
while (!it.IsAtEnd())
{
*data = it.Get();
++data;
++it;
}
image->setUserData(matrix);
matrix->preMult(osg::Matrix::scale(double(image->s()), double(image->t()), double(image->r())));
return image;
}