本文整理汇总了C++中itk::ImageRegion::GetIndex方法的典型用法代码示例。如果您正苦于以下问题:C++ ImageRegion::GetIndex方法的具体用法?C++ ImageRegion::GetIndex怎么用?C++ ImageRegion::GetIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类itk::ImageRegion
的用法示例。
在下文中一共展示了ImageRegion::GetIndex方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: imageIndices
typename MaskedHistogramGenerator<TBinValue, TQuadrantProperties>::HistogramType MaskedHistogramGenerator<TBinValue, TQuadrantProperties>::ComputeMaskedScalarImageHistogram
(const TImage* const image, const itk::ImageRegion<2>& imageRegion,
const Mask* const mask, const itk::ImageRegion<2>& maskRegion, const unsigned int numberOfBins,
const TRangeValue& rangeMin, const TRangeValue& rangeMax, const bool allowOutside, const HoleMaskPixelTypeEnum& maskValue)
{
std::vector<itk::Index<2> > maskIndices = ITKHelpers::GetPixelsWithValueInRegion(mask, maskRegion, maskValue);
// Compute the corresponding locations in the imageRegion
std::vector<itk::Index<2> > imageIndices(maskIndices.size());
itk::Offset<2> maskRegionToImageRegionOffset = imageRegion.GetIndex() - maskRegion.GetIndex(); // The offset from the maskRegion to the imageRegion
for(size_t i = 0; i < maskIndices.size(); ++i)
{
imageIndices[i] = maskIndices[i] + maskRegionToImageRegionOffset;
}
HistogramType histogram;
// Get this channels masked scalar values
std::vector<typename TImage::PixelType> validPixels =
ITKHelpers::GetPixelValues(image, imageIndices);
// Compute the histogram of the scalar values
if(allowOutside)
{
histogram = HistogramGeneratorType::ScalarHistogramAllowOutside(validPixels, numberOfBins, rangeMin, rangeMax);
}
else
{
histogram = HistogramGeneratorType::ScalarHistogram(validPixels, numberOfBins, rangeMin, rangeMax);
}
return histogram;
}
示例2: GetRandomRegionInRegion
itk::ImageRegion<2> GetRandomRegionInRegion(const itk::ImageRegion<2>& region, const unsigned int patchRadius)
{
itk::Index<2> randomPixel;
randomPixel[0] = Helpers::RandomInt(region.GetIndex()[0], region.GetIndex()[0] + region.GetSize()[0]);
randomPixel[1] = Helpers::RandomInt(region.GetIndex()[1], region.GetIndex()[1] + region.GetSize()[1]);
itk::ImageRegion<2> randomRegion = ITKHelpers::GetRegionInRadiusAroundPixel(randomPixel, patchRadius);
return randomRegion;
}
示例3: OutlineRegion
void OutlineRegion(vtkImageData* const image, const itk::ImageRegion<2>& region, const unsigned char color[3])
{
// std::cout << "Outlining region: " << region << std::endl;
// std::cout << "Outline color: " << static_cast<int>(color[0])
// << " " << static_cast<int>(color[1]) << " "
// << static_cast<int>(color[2]) << std::endl;
// std::cout << "Image components: " << image->GetNumberOfScalarComponents() << std::endl;
unsigned int leftEdge = region.GetIndex()[0];
//std::cout << "leftEdge : " << leftEdge << std::endl;
unsigned int rightEdge = region.GetIndex()[0] + region.GetSize()[0] - 1;
//std::cout << "rightEdge : " << rightEdge << std::endl;
unsigned int topEdge = region.GetIndex()[1];
//std::cout << "topEdge : " << topEdge << std::endl;
unsigned int bottomEdge = region.GetIndex()[1] + region.GetSize()[1] - 1;
//std::cout << "bottomEdge : " << bottomEdge << std::endl;
// Move along the top and bottom of the region, setting the border pixels.
unsigned int counter = 0;
for(unsigned int xpos = leftEdge; xpos <= rightEdge; ++xpos)
{
//std::cout << "xpos : " << xpos << std::endl;
unsigned char* topPixel = static_cast<unsigned char*>(image->GetScalarPointer(xpos, topEdge, 0));
topPixel[0] = color[0];
topPixel[1] = color[1];
topPixel[2] = color[2];
topPixel[3] = 255; // visible
unsigned char* bottomPixel = static_cast<unsigned char*>(image->GetScalarPointer(xpos, bottomEdge, 0));
bottomPixel[0] = color[0];
bottomPixel[1] = color[1];
bottomPixel[2] = color[2];
bottomPixel[3] = 255; // visible
counter++;
}
//std::cout << "Set " << counter << " pixels." << std::endl;
// Move along the left and right of the region, setting the border pixels.
for(unsigned int j = region.GetIndex()[1]; j < region.GetIndex()[1] + region.GetSize()[1]; ++j)
{
unsigned char* pixel = static_cast<unsigned char*>(image->GetScalarPointer(region.GetIndex()[0], j, 0));
pixel[0] = color[0];
pixel[1] = color[1];
pixel[2] = color[2];
pixel[3] = 255; // visible
pixel = static_cast<unsigned char*>(image->GetScalarPointer(region.GetIndex()[0] + region.GetSize()[0] - 1, j, 0));
pixel[0] = color[0];
pixel[1] = color[1];
pixel[2] = color[2];
pixel[3] = 255; // visible
}
image->Modified();
}
示例4: BlankRegion
void BlankRegion(vtkImageData* image, const itk::ImageRegion<2>& region)
{
// Blank the image
for(unsigned int i = region.GetIndex()[0]; i < region.GetIndex()[0] + region.GetSize()[0]; ++i)
{
for(unsigned int j = region.GetIndex()[1]; j < region.GetIndex()[1] + region.GetSize()[1]; ++j)
{
unsigned char* pixel = static_cast<unsigned char*>(image->GetScalarPointer(i, region.GetIndex()[1], 0));
pixel[0] = 0;
pixel[1] = 0;
pixel[2] = 0;
pixel[3] = 0; // transparent
}
}
image->Modified();
}
示例5: GetRandomPixelInRegion
itk::Index<2> GetRandomPixelInRegion(const itk::ImageRegion<2>& region)
{
itk::Index<2> pixel;
pixel[0] = region.GetIndex()[0] + Helpers::RandomInt(0, region.GetSize()[0] - 1);
pixel[1] = region.GetIndex()[1] + Helpers::RandomInt(0, region.GetSize()[1] - 1);
return pixel;
}
示例6: GetRegionCenter
itk::Index<2> GetRegionCenter(const itk::ImageRegion<2>& region)
{
// This assumes that the region is an odd size in both dimensions
itk::Index<2> center;
center[0] = region.GetIndex()[0] + region.GetSize()[0] / 2;
center[1] = region.GetIndex()[1] + region.GetSize()[1] / 2;
return center;
}
示例7: SetRegion
void PatchHighlighter::SetRegion(const itk::ImageRegion<2>& region)
{
// Snap user patch to integer pixels
double position[3];
position[0] = region.GetIndex()[0];
position[1] = region.GetIndex()[1];
position[2] = 0;
this->PatchLayer.ImageSlice->SetPosition(position);
}
示例8: assert
void LocalPCADistance<TImage>::ComputeProjectionMatrix(const itk::ImageRegion<2>& region)
{
assert(this->Image);
// Dilate the query region
itk::Index<2> dilatedRegionCorner = {{region.GetIndex()[0] - 1, region.GetIndex()[1] - 1}};
itk::Size<2> dilatedRegionSize = {{region.GetSize()[0] + 2, region.GetSize()[1] + 2}};
itk::ImageRegion<2> dilatedRegion(dilatedRegionCorner, dilatedRegionSize);
dilatedRegion.Crop(this->Image->GetLargestPossibleRegion());
// Compute a local feature matrix (the query patch and all of it's neighbors (if they are inside the image)
MatrixType featureMatrix = PatchProjection<Eigen::MatrixXf, Eigen::VectorXf>::
VectorizeImage(this->Image, region.GetSize()[0]/2, dilatedRegion);
unsigned int inputPoints = featureMatrix.cols();
this->ProjectionMatrix = PatchProjection<MatrixType, VectorType>::ProjectionMatrixFromFeatureMatrix(featureMatrix, this->MeanVector);
// Only keep the number of columns corresponding to the number of input points used
this->ProjectionMatrix = EigenHelpers::TruncateColumns<MatrixType>(this->ProjectionMatrix, inputPoints);
}
示例9: SetRegionCenterPixel
void SetRegionCenterPixel(vtkImageData* const image, const itk::ImageRegion<2>& region, const unsigned char color[3])
{
int dims[3];
image->GetDimensions(dims);
unsigned char* pixel = static_cast<unsigned char*>(image->GetScalarPointer(region.GetIndex()[0] + region.GetSize()[0]/2,
region.GetIndex()[1] + region.GetSize()[1]/2, 0));
pixel[0] = color[0];
pixel[1] = color[1];
pixel[2] = color[2];
pixel[3] = 255; // visible
}
示例10: GetPixelsWithValueInRegion
std::vector<itk::Offset<2> > Mask::GetHoleOffsetsInRegion(itk::ImageRegion<2> region) const
{
// Ensure the region is inside the image
region.Crop(this->GetLargestPossibleRegion());
std::vector<itk::Index<2> > indices =
GetPixelsWithValueInRegion(this, region, HoleMaskPixelTypeEnum::HOLE);
std::vector<itk::Offset<2> > holeOffsets =
IndicesToOffsets(indices, region.GetIndex());
return holeOffsets;
}
示例11: qimage
void ManualPatchSelectionDialog<TImage>::slot_UpdateResult(const itk::ImageRegion<2>& sourceRegion,
const itk::ImageRegion<2>& targetRegion)
{
assert(sourceRegion.GetSize() == targetRegion.GetSize());
if(!this->Image->GetLargestPossibleRegion().IsInside(sourceRegion))
{
std::cerr << "Source region is outside the image!" << std::endl;
return;
}
QImage qimage(sourceRegion.GetSize()[0], sourceRegion.GetSize()[1], QImage::Format_RGB888);
if(MaskImage->CountHolePixels(sourceRegion) > 0)
{
//std::cerr << "The source patch must not have any hole pixels!" << std::endl;
//btnAccept->setVisible(false);
qimage.fill(Qt::green);
}
else
{
typename TImage::Pointer tempImage = TImage::New();
ITKHelpers::ConvertTo3Channel(this->Image, tempImage.GetPointer());
if(this->Image->GetNumberOfComponentsPerPixel() != 3)
{
ITKHelpers::ScaleAllChannelsTo255(tempImage.GetPointer());
}
itk::ImageRegionIterator<TImage> sourceIterator(tempImage, sourceRegion);
itk::ImageRegionIterator<TImage> targetIterator(tempImage, targetRegion);
itk::ImageRegionIterator<Mask> maskIterator(MaskImage, targetRegion);
typename TImage::Pointer resultPatch = TImage::New();
resultPatch->SetNumberOfComponentsPerPixel(Image->GetNumberOfComponentsPerPixel());
itk::ImageRegion<2> resultPatchRegion;
resultPatchRegion.SetSize(sourceRegion.GetSize());
resultPatch->SetRegions(resultPatchRegion);
resultPatch->Allocate();
while(!maskIterator.IsAtEnd())
{
ITKHelpers::FloatVectorImageType::PixelType pixel;
if(MaskImage->IsHole(maskIterator.GetIndex()))
{
pixel = sourceIterator.Get();
}
else
{
pixel = targetIterator.Get();
}
itk::Offset<2> offset = sourceIterator.GetIndex() - sourceRegion.GetIndex();
itk::Index<2> offsetIndex;
offsetIndex[0] = offset[0];
offsetIndex[1] = offset[1];
resultPatch->SetPixel(offsetIndex, pixel);
++sourceIterator;
++targetIterator;
++maskIterator;
} // end iterator loop
qimage = ITKQtHelpers::GetQImageColor(resultPatch.GetPointer(), resultPatch->GetLargestPossibleRegion());
} // end else
this->ResultPatchScene->clear();
QGraphicsPixmapItem* item = this->ResultPatchScene->addPixmap(QPixmap::fromImage(qimage));
gfxResult->fitInView(item);
}
示例12: operator
bool operator()(const itk::ImageRegion<2> region1, const itk::ImageRegion<2> region2) const
{
return IndexCompareFunctor(region1.GetIndex(), region2.GetIndex());
}