本文整理汇总了C++中imagetype::Pointer::GetNumberOfComponentsPerPixel方法的典型用法代码示例。如果您正苦于以下问题:C++ Pointer::GetNumberOfComponentsPerPixel方法的具体用法?C++ Pointer::GetNumberOfComponentsPerPixel怎么用?C++ Pointer::GetNumberOfComponentsPerPixel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类imagetype::Pointer
的用法示例。
在下文中一共展示了Pointer::GetNumberOfComponentsPerPixel方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ImageFileReaderException
std::vector<itk::SmartPointer<BaseData> > NrrdTensorImageReader::Read()
{
std::vector<itk::SmartPointer<mitk::BaseData> > result;
std::string location = GetInputLocation();
if ( location == "")
{
throw itk::ImageFileReaderException(__FILE__, __LINE__, "Sorry, the filename is empty!");
}
else
{
try
{
mitk::LocaleSwitch localeSwitch("C");
try
{
std::string fname3 = mitk::IOUtil::GetTempPath()+"/temp_dti.nii.gz";
int c = 0;
while( itksys::SystemTools::FileExists(fname3) )
{
fname3 = mitk::IOUtil::GetTempPath()+"/temp_dti_" + boost::lexical_cast<std::string>(c) + ".nii.gz";
++c;
}
itksys::SystemTools::CopyAFile(location.c_str(), fname3.c_str());
typedef itk::VectorImage<float,3> ImageType;
itk::NiftiImageIO::Pointer io = itk::NiftiImageIO::New();
typedef itk::ImageFileReader<ImageType> FileReaderType;
FileReaderType::Pointer reader = FileReaderType::New();
reader->SetImageIO(io);
reader->SetFileName(fname3);
reader->Update();
ImageType::Pointer img = reader->GetOutput();
TensorImage::ItkTensorImageType::Pointer vecImg = TensorImage::ItkTensorImageType::New();
vecImg->SetSpacing( img->GetSpacing() ); // Set the image spacing
vecImg->SetOrigin( img->GetOrigin() ); // Set the image origin
vecImg->SetDirection( img->GetDirection() ); // Set the image direction
vecImg->SetRegions( img->GetLargestPossibleRegion());
vecImg->Allocate();
itk::ImageRegionIterator<TensorImage::ItkTensorImageType> ot (vecImg, vecImg->GetLargestPossibleRegion() );
ot.GoToBegin();
itk::ImageRegionIterator<ImageType> it (img, img->GetLargestPossibleRegion() );
it.GoToBegin();
typedef ImageType::PixelType VarPixType;
typedef TensorImage::PixelType FixPixType;
int numComponents = img->GetNumberOfComponentsPerPixel();
if (numComponents==6)
{
MITK_INFO << "Trying to load dti as 6-comp nifti ...";
while (!it.IsAtEnd())
{
VarPixType vec = it.Get();
FixPixType fixVec(vec.GetDataPointer());
TensorImage::PixelType tensor;
tensor.SetElement(0, vec.GetElement(0));
tensor.SetElement(1, vec.GetElement(1));
tensor.SetElement(2, vec.GetElement(2));
tensor.SetElement(3, vec.GetElement(3));
tensor.SetElement(4, vec.GetElement(4));
tensor.SetElement(5, vec.GetElement(5));
fixVec = tensor;
ot.Set(fixVec);
++ot;
++it;
}
}
else if(numComponents==9)
{
MITK_INFO << "Trying to load dti as 9-comp nifti ...";
while (!it.IsAtEnd())
{
VarPixType vec = it.Get();
TensorImage::PixelType tensor;
tensor.SetElement(0, vec.GetElement(0));
tensor.SetElement(1, vec.GetElement(1));
tensor.SetElement(2, vec.GetElement(2));
tensor.SetElement(3, vec.GetElement(4));
tensor.SetElement(4, vec.GetElement(5));
tensor.SetElement(5, vec.GetElement(8));
FixPixType fixVec(tensor);
ot.Set(fixVec);
++ot;
++it;
}
}
else if (numComponents==1)
{
MITK_INFO << "Trying to load dti as 4D nifti ...";
//.........这里部分代码省略.........
示例2: ImageFileReaderException
//.........这里部分代码省略.........
}
this->GetOutput()->InitializeByItk(vecImg.GetPointer());
this->GetOutput()->SetVolume(vecImg->GetBufferPointer());
}
catch(...)
{
MITK_INFO << "Trying to load dti as nrrd ...";
typedef itk::VectorImage<float,3> ImageType;
itk::NrrdImageIO::Pointer io = itk::NrrdImageIO::New();
typedef itk::ImageFileReader<ImageType> FileReaderType;
FileReaderType::Pointer reader = FileReaderType::New();
reader->SetImageIO(io);
reader->SetFileName(this->m_FileName);
reader->Update();
ImageType::Pointer img = reader->GetOutput();
typedef itk::Image<itk::DiffusionTensor3D<float>,3> VecImgType;
VecImgType::Pointer vecImg = VecImgType::New();
vecImg->SetSpacing( img->GetSpacing() ); // Set the image spacing
vecImg->SetOrigin( img->GetOrigin() ); // Set the image origin
vecImg->SetDirection( img->GetDirection() ); // Set the image direction
vecImg->SetRegions( img->GetLargestPossibleRegion());
vecImg->Allocate();
itk::ImageRegionIterator<VecImgType> ot (vecImg, vecImg->GetLargestPossibleRegion() );
ot = ot.Begin();
itk::ImageRegionIterator<ImageType> it (img, img->GetLargestPossibleRegion() );
it = it.Begin();
typedef ImageType::PixelType VarPixType;
typedef VecImgType::PixelType FixPixType;
int numComponents = img->GetNumberOfComponentsPerPixel();
itk::MetaDataDictionary imgMetaDictionary = img->GetMetaDataDictionary();
std::vector<std::string> imgMetaKeys = imgMetaDictionary.GetKeys();
std::vector<std::string>::const_iterator itKey = imgMetaKeys.begin();
std::string metaString;
bool readFrame = false;
double xx, xy, xz, yx, yy, yz, zx, zy, zz;
MeasurementFrameType measFrame;
measFrame.SetIdentity();
MeasurementFrameType measFrameTransp;
measFrameTransp.SetIdentity();
for (; itKey != imgMetaKeys.end(); itKey ++)
{
itk::ExposeMetaData<std::string> (imgMetaDictionary, *itKey, metaString);
if (itKey->find("measurement frame") != std::string::npos)
{
sscanf(metaString.c_str(), " ( %lf , %lf , %lf ) ( %lf , %lf , %lf ) ( %lf , %lf , %lf ) \n", &xx, &xy, &xz, &yx, &yy, &yz, &zx, &zy, &zz);
if (xx>10e-10 || xy>10e-10 || xz>10e-10 ||
yx>10e-10 || yy>10e-10 || yz>10e-10 ||
zx>10e-10 || zy>10e-10 || zz>10e-10 )
{
readFrame = true;
measFrame(0,0) = xx;
measFrame(0,1) = xy;
measFrame(0,2) = xz;
measFrame(1,0) = yx;
measFrame(1,1) = yy;
measFrame(1,2) = yz;
示例3: TestComputeMaskedImage1DHistogram
void TestComputeMaskedImage1DHistogram()
{
// // Single channel
// {
// typedef itk::Image<unsigned char, 2> ImageType;
// ImageType::Pointer image = ImageType::New();
// ImageType::IndexType corner = {{0,0}};
// ImageType::SizeType size = {{100,100}};
// ImageType::RegionType region(corner, size);
// image->SetRegions(region);
// image->Allocate();
// itk::ImageRegionIterator<ImageType> imageIterator(image,region);
// while(!imageIterator.IsAtEnd())
// {
// if(imageIterator.GetIndex()[0] < 70)
// {
// imageIterator.Set(255);
// }
// else
// {
// imageIterator.Set(0);
// }
// ++imageIterator;
// }
// ImageType::PixelType rangeMin = 0;
// ImageType::PixelType rangeMax = 255;
// unsigned int numberOfBins = 10;
// typedef int BinValueType;
// typedef Histogram<BinValueType>::HistogramType HistogramType;
// HistogramType histogram = Histogram<BinValueType>::ComputeImageHistogram1D(image.GetPointer(),
// image->GetLargestPossibleRegion(),
// numberOfBins, rangeMin, rangeMax);
// Histogram<BinValueType>::OutputHistogram(histogram);
// std::cout << std::endl;
// }
// Multi channel VectorImage
{
typedef itk::VectorImage<unsigned char, 2> ImageType;
ImageType::Pointer image = ImageType::New();
ImageType::IndexType corner = {{0,0}};
ImageType::SizeType size = {{100,100}};
ImageType::RegionType region(corner, size);
image->SetRegions(region);
image->SetNumberOfComponentsPerPixel(3);
image->Allocate();
Mask::Pointer mask = Mask::New();
mask->SetRegions(region);
mask->Allocate();
itk::ImageRegionIterator<ImageType> imageIterator(image,region);
while(!imageIterator.IsAtEnd())
{
ImageType::PixelType pixel(image->GetNumberOfComponentsPerPixel());
if(imageIterator.GetIndex()[0] < 70)
{
for(unsigned int i = 0; i < pixel.GetSize(); ++i)
{
pixel[i] = 255;
}
}
else
{
for(unsigned int i = 0; i < pixel.GetSize(); ++i)
{
pixel[i] = 0;
}
}
imageIterator.Set(pixel);
++imageIterator;
}
// TypeTraits<ImageType::PixelType>::ComponentType rangeMin = 0;
// TypeTraits<ImageType::PixelType>::ComponentType rangeMax = 255;
ImageType::PixelType rangeMins;
rangeMins.SetSize(image->GetNumberOfComponentsPerPixel());
rangeMins.Fill(0);
ImageType::PixelType rangeMaxs;
rangeMaxs.SetSize(image->GetNumberOfComponentsPerPixel());
rangeMaxs.Fill(255);
unsigned int numberOfBinsPerComponent = 10;
typedef int BinValueType;
//.........这里部分代码省略.........
示例4: ImageFileReaderException
void NrrdTensorImageReader
::GenerateData()
{
if ( m_FileName == "")
{
throw itk::ImageFileReaderException(__FILE__, __LINE__, "Sorry, the filename is empty!");
}
else
{
try
{
const std::string& locale = "C";
const std::string& currLocale = setlocale( LC_ALL, NULL );
if ( locale.compare(currLocale)!=0 )
{
try
{
setlocale(LC_ALL, locale.c_str());
}
catch(...)
{
MITK_INFO << "Could not set locale " << locale;
}
}
typedef itk::VectorImage<float,3> ImageType;
itk::NrrdImageIO::Pointer io = itk::NrrdImageIO::New();
typedef itk::ImageFileReader<ImageType> FileReaderType;
FileReaderType::Pointer reader = FileReaderType::New();
reader->SetImageIO(io);
reader->SetFileName(this->m_FileName);
reader->Update();
ImageType::Pointer img = reader->GetOutput();
typedef itk::Image<itk::DiffusionTensor3D<float>,3> VecImgType;
VecImgType::Pointer vecImg = VecImgType::New();
vecImg->SetSpacing( img->GetSpacing() ); // Set the image spacing
vecImg->SetOrigin( img->GetOrigin() ); // Set the image origin
vecImg->SetDirection( img->GetDirection() ); // Set the image direction
vecImg->SetRegions( img->GetLargestPossibleRegion());
vecImg->Allocate();
itk::ImageRegionIterator<VecImgType> ot (vecImg, vecImg->GetLargestPossibleRegion() );
ot = ot.Begin();
itk::ImageRegionIterator<ImageType> it (img, img->GetLargestPossibleRegion() );
it = it.Begin();
typedef ImageType::PixelType VarPixType;
typedef VecImgType::PixelType FixPixType;
int numComponents = img->GetNumberOfComponentsPerPixel();
itk::MetaDataDictionary imgMetaDictionary = img->GetMetaDataDictionary();
std::vector<std::string> imgMetaKeys = imgMetaDictionary.GetKeys();
std::vector<std::string>::const_iterator itKey = imgMetaKeys.begin();
std::string metaString;
bool readFrame = false;
double xx, xy, xz, yx, yy, yz, zx, zy, zz;
MeasurementFrameType measFrame;
measFrame.SetIdentity();
MeasurementFrameType measFrameTransp;
measFrameTransp.SetIdentity();
for (; itKey != imgMetaKeys.end(); itKey ++)
{
itk::ExposeMetaData<std::string> (imgMetaDictionary, *itKey, metaString);
if (itKey->find("measurement frame") != std::string::npos)
{
sscanf(metaString.c_str(), " ( %lf , %lf , %lf ) ( %lf , %lf , %lf ) ( %lf , %lf , %lf ) \n", &xx, &xy, &xz, &yx, &yy, &yz, &zx, &zy, &zz);
if (xx>10e-10 || xy>10e-10 || xz>10e-10 ||
yx>10e-10 || yy>10e-10 || yz>10e-10 ||
zx>10e-10 || zy>10e-10 || zz>10e-10 )
{
readFrame = true;
measFrame(0,0) = xx;
measFrame(0,1) = xy;
measFrame(0,2) = xz;
measFrame(1,0) = yx;
measFrame(1,1) = yy;
measFrame(1,2) = yz;
measFrame(2,0) = zx;
measFrame(2,1) = zy;
measFrame(2,2) = zz;
measFrameTransp = measFrame.GetTranspose();
}
}
}
if (numComponents==6)
{
while (!it.IsAtEnd())
{
// T'=RTR'
VarPixType vec = it.Get();
FixPixType fixVec(vec.GetDataPointer());
//.........这里部分代码省略.........
示例5: on_btnCut_clicked
void LidarSegmentationWidget::on_btnCut_clicked()
{
// Normalize the image
ImageType::Pointer normalizedImage = ImageType::New();
normalizedImage->SetNumberOfComponentsPerPixel(this->Image->GetNumberOfComponentsPerPixel());
normalizedImage->SetRegions(this->Image->GetLargestPossibleRegion());
normalizedImage->Allocate();
std::cout << "Normalizing image..." << std::endl;
//ITKHelpers::DeepCopy(this->Image.GetPointer(), normalizedImage.GetPointer());
//ITKHelpers::NormalizeVectorImage(normalizedImage.GetPointer());
ITKHelpers::NormalizeImageChannels(this->Image.GetPointer(), normalizedImage.GetPointer());
std::cout << "Normalized image has " << normalizedImage->GetNumberOfComponentsPerPixel()
<< " channels." << std::endl;
//this->GraphCut.SetImage(this->Image);
this->GraphCut.SetImage(normalizedImage.GetPointer());
this->GraphCut.Debug = this->chkDebug->isChecked();
//this->GraphCut.SecondStep = this->chkSecondStep->isChecked();
this->GraphCut.IncludeDepthInHistogram = this->chkDepthHistogram->isChecked();
this->GraphCut.IncludeColorInHistogram = this->chkColorHistogram->isChecked();
this->GraphCut.BackgroundThreshold = this->txtBackgroundThreshold->text().toDouble();
if(this->GraphCut.DifferenceFunction)
{
delete this->GraphCut.DifferenceFunction;
}
// Setup the Difference object
if(this->chkDepthDifference->isChecked() && !this->chkColorDifference->isChecked())
{
std::cout << "Using depth-only N-weights." << std::endl;
this->GraphCut.DifferenceFunction = new DepthDifference;
}
else if(!this->chkDepthDifference->isChecked() && this->chkColorDifference->isChecked())
{
std::cout << "Using color-only N-weights." << std::endl;
this->GraphCut.DifferenceFunction = new ColorDifference;
}
else if(this->chkDepthDifference->isChecked() && this->chkColorDifference->isChecked())
{
std::cout << "Using depth+color N-weights." << std::endl;
std::vector<float> weights(4,1.0f);
weights[0] = spinRWeight->value();
weights[1] = spinGWeight->value();
weights[2] = spinBWeight->value();
weights[3] = spinDWeight->value();
std::cout << "Weights: " << weights[0] << " " << weights[1] << " " << weights[2] << " " << weights[3] << std::endl;
this->GraphCut.DifferenceFunction = new WeightedDifference(weights);
}
else
{
std::stringstream ss;
ss << "Something is wrong - you must select depth, color, or both." << std::endl;
throw std::runtime_error(ss.str());
}
// Get the number of bins from the slider
this->GraphCut.SetNumberOfHistogramBins(this->sldHistogramBins->value());
if(this->sldLambda->value() == 0)
{
QMessageBox msgBox;
msgBox.setText("You must select lambda > 0!");
msgBox.exec();
return;
}
// Setup the graph cut from the GUI and the scribble selection
this->GraphCut.SetLambda(ComputeLambda());
this->GraphCut.SetSources(this->Sources);
this->GraphCut.SetSinks(this->Sinks);
//this->GraphCut.SetSources(this->LeftInteractorStyle->GetForegroundSelection());
//this->GraphCut.SetSinks(this->LeftInteractorStyle->GetBackgroundSelection());
// Setup and start the actual cut computation in a different thread
QFuture<void> future = QtConcurrent::run(this->GraphCut, &ImageGraphCut::PerformSegmentation);
this->FutureWatcher.setFuture(future);
this->ProgressDialog->exec();
if(!this->RightRenderer->HasViewProp(this->ResultImageSlice))
{
std::cout << "Added ResultImageSlice view prop." << std::endl;
//this->RightRenderer->AddViewProp(this->ResultImageSlice);
this->ResultImageSlice->GetProperty()->SetLayerNumber(0); // 0 = bottom of the stack.
this->RightSourceSinkImageSlice->GetProperty()->SetLayerNumber(1); // The source/sink image should be displayed on top of the result image.
}
}
示例6: on_btnSegmentLiDAR_clicked
void LidarSegmentationWidget::on_btnSegmentLiDAR_clicked()
{
// Normalize the image
ImageType::Pointer normalizedImage = ImageType::New();
normalizedImage->SetNumberOfComponentsPerPixel(this->Image->GetNumberOfComponentsPerPixel());
normalizedImage->SetRegions(this->Image->GetLargestPossibleRegion());
normalizedImage->Allocate();
std::cout << "Normalizing image..." << std::endl;
//ITKHelpers::DeepCopy(this->Image.GetPointer(), normalizedImage.GetPointer());
ITKHelpers::NormalizeImageChannels(this->Image.GetPointer(), normalizedImage.GetPointer());
std::cout << "Normalized image has " << normalizedImage->GetNumberOfComponentsPerPixel()
<< " channels." << std::endl;
//this->GraphCut.SetImage(this->Image);
this->GraphCut.SetImage(normalizedImage.GetPointer());
this->GraphCut.IncludeDepthInHistogram = true;
this->GraphCut.IncludeColorInHistogram = true;
this->GraphCut.BackgroundThreshold = 0.4;
if(this->GraphCut.DifferenceFunction)
{
delete this->GraphCut.DifferenceFunction;
}
std::cout << "Using depth-only N-weights." << std::endl;
this->GraphCut.DifferenceFunction = new DepthDifference;
// Get the number of bins from the slider
this->GraphCut.SetNumberOfHistogramBins(this->sldHistogramBins->value());
// Setup the graph cut from the GUI and the scribble selection
//this->GraphCut.SetLambda(.0025);
this->GraphCut.SetLambda(ComputeLambda());
this->GraphCut.SetSources(this->Sources);
this->GraphCut.SetSinks(this->Sinks);
// Setup and start the actual cut computation in a different thread
QFuture<void> future = QtConcurrent::run(this->GraphCut, &ImageGraphCut::PerformSegmentation);
this->FutureWatcher.setFuture(future);
this->ProgressDialog->exec();
// Step 2 - color + depth
on_btnReseedForeground_clicked();
on_btnGenerateNeighborSinks_clicked();
this->GraphCut.SetSources(this->Sources);
this->GraphCut.SetSinks(this->Sinks);
std::cout << "Using depth+color N-weights." << std::endl;
std::vector<float> weights(4,1.0f);
// weights[0] = 1.0f;
// weights[1] = 1.0f;
// weights[2] = 1.0f;
// weights[3] = 1.0f;
this->GraphCut.DifferenceFunction = new WeightedDifference(weights);
QFuture<void> futureStep2 = QtConcurrent::run(this->GraphCut, &ImageGraphCut::PerformSegmentation);
this->FutureWatcher.setFuture(futureStep2);
this->ProgressDialog->exec();
if(!this->RightRenderer->HasViewProp(this->ResultImageSlice))
{
std::cout << "Added ResultImageSlice view prop." << std::endl;
this->ResultImageSlice->VisibilityOn();
this->ResultImageSlice->GetProperty()->SetLayerNumber(0); // 0 = Bottom of the stack
this->RightSourceSinkImageSlice->GetProperty()->SetLayerNumber(1); // The source/sink image should be displayed on top of the result image.
}
}