本文整理汇总了C++中mask::Pointer::GetPointer方法的典型用法代码示例。如果您正苦于以下问题:C++ Pointer::GetPointer方法的具体用法?C++ Pointer::GetPointer怎么用?C++ Pointer::GetPointer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mask::Pointer
的用法示例。
在下文中一共展示了Pointer::GetPointer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
typedef itk::Image<itk::CovariantVector<float, 3>, 2> ImageType;
// typedef FloatVectorImageType ImageType;
ImageType::Pointer image = ImageType::New();
Testing::GetBlankImage(image.GetPointer(), 4);
Mask::Pointer mask = Mask::New();
Testing::GetFullyValidMask(mask.GetPointer());
unsigned int patchRadius = 5;
PriorityCriminisi<ImageType> priority(image.GetPointer(), mask.GetPointer(),
patchRadius);
itk::Index<2> sourcePixel;
sourcePixel.Fill(0);
itk::Index<2> targetPixel;
targetPixel.Fill(1);
priority.Update(sourcePixel, targetPixel);
itk::Index<2> queryPixel = {{0,0}};
priority.ComputePriority(queryPixel);
return EXIT_SUCCESS;
}
示例2: main
int main()
{
FloatVectorImageType::Pointer image = FloatVectorImageType::New();
Testing::GetBlankImage(image.GetPointer(), 4);
Mask::Pointer mask = Mask::New();
Testing::GetFullyValidMask(mask.GetPointer());
UnsignedCharScalarImageType::Pointer manualPriorityImage = UnsignedCharScalarImageType::New();
Testing::GetBlankImage(manualPriorityImage.GetPointer());
unsigned int patchRadius = 5;
typedef PriorityConfidence ConfidencePriorityType;
ConfidencePriorityType priorityConfidence(mask, patchRadius);
PriorityManual<itk::Index<2>, UnsignedCharScalarImageType, ConfidencePriorityType>
priority(manualPriorityImage, &priorityConfidence);
itk::Index<2> filledPixel = {{0,0}};
priority.Update(filledPixel);
priority.SetManualPriorityImage(manualPriorityImage);
itk::Index<2> queryPixel = {{0,0}};
priority.ComputePriority(queryPixel);
return EXIT_SUCCESS;
}
示例3: main
int main(int argc, char*argv[])
{
Mask::Pointer mask = Mask::New();
CreateMask(mask);
OutputHelpers::WriteImage(mask.GetPointer(), "mask.png");
UnsignedCharScalarImageType::Pointer image = UnsignedCharScalarImageType::New();
CreateImage(image);
OutputHelpers::WriteImage(image.GetPointer(), "image.png");
FloatScalarImageType::Pointer output = FloatScalarImageType::New();
MaskOperations::MaskedLaplacian(image.GetPointer(), mask.GetPointer(), output.GetPointer());
OutputHelpers::WriteImage(output.GetPointer(), "laplacian.mha");
return EXIT_SUCCESS;
}
示例4: CreateBoundaryImageInRegion
void Mask::CreateBoundaryImageInRegion(const itk::ImageRegion<2>& region, BoundaryImageType* const boundaryImage,
const HoleMaskPixelTypeEnum& whichSideOfBoundary) const
{
// Create a binary image of the mask
unsigned char holeColor = 255;
unsigned char validColor = 0;
UnsignedCharImageType::Pointer fullBinaryImage = UnsignedCharImageType::New();
CreateBinaryImageInRegion(region, fullBinaryImage, holeColor, validColor);
// Extract the relevant region from the binary image
UnsignedCharImageType::Pointer binaryImage = UnsignedCharImageType::New();
binaryImage->SetRegions(region);
binaryImage->Allocate();
CopyRegion(fullBinaryImage.GetPointer(), binaryImage.GetPointer(), region, region);
// Extract the relevant region from the mask
Mask::Pointer extractedRegionMask = Mask::New();
extractedRegionMask->SetRegions(region);
extractedRegionMask->Allocate();
CopyRegion(this, extractedRegionMask.GetPointer(), region, region);
// Since the hole is white (we have specified this at the beginning of this function),
// we want the foreground value of the contour filter to be black.
// This means that the boundary will be detected in the black pixel region,
// which is on the outside edge of the hole like we want. However,
// The BinaryContourImageFilter will change all non-boundary pixels to the background color,
// so the resulting output will be inverted - the boundary pixels will be black and the
// non-boundary pixels will be white.
// Find the boundary
typedef itk::BinaryContourImageFilter<UnsignedCharImageType, UnsignedCharImageType> binaryContourImageFilterType;
binaryContourImageFilterType::Pointer binaryContourFilter = binaryContourImageFilterType::New();
binaryContourFilter->SetInput(binaryImage);
binaryContourFilter->SetFullyConnected(true);
if(whichSideOfBoundary == HoleMaskPixelTypeEnum::VALID)
{
// we want the boundary pixels to be in the valid region.
binaryContourFilter->SetForegroundValue(validColor);
binaryContourFilter->SetBackgroundValue(holeColor);
}
else if(whichSideOfBoundary == HoleMaskPixelTypeEnum::HOLE)
{
// we want the boundary pixels to be in the hole region.
binaryContourFilter->SetForegroundValue(holeColor);
binaryContourFilter->SetBackgroundValue(validColor);
}
else
{
throw std::runtime_error("An invalid side of the boundary was requested.");
}
binaryContourFilter->Update();
DeepCopy(binaryContourFilter->GetOutput(), boundaryImage);
}
示例5: main
int main(int argc, char*argv[])
{
if(argc < 4)
{
std::cerr << "Required arguments: image mask output" << std::endl;
return EXIT_FAILURE;
}
std::string imageFilename = argv[1];
std::string maskFilename = argv[2];
std::string outputFilename = argv[3];
std::cout << "imageFilename: " << imageFilename << std::endl;
std::cout << "maskFilename: " << maskFilename << std::endl;
std::cout << "outputFilename: " << outputFilename << std::endl;
typedef itk::ImageFileReader<ImageType> ImageReaderType;
ImageReaderType::Pointer imageReader = ImageReaderType::New();
imageReader->SetFileName(imageFilename);
imageReader->Update();
Mask::Pointer sourceMask = Mask::New();
sourceMask->Read(maskFilename);
Mask::Pointer targetMask = Mask::New();
targetMask->SetRegions(sourceMask->GetLargestPossibleRegion());
targetMask->Allocate();
ITKHelpers::SetImageToConstant(targetMask.GetPointer(), HoleMaskPixelTypeEnum::VALID);
typedef SSD<ImageType> DistanceFunctorType;
DistanceFunctorType* patchDistanceFunctor = new DistanceFunctorType;
patchDistanceFunctor->SetImage(imageReader->GetOutput());
typedef Propagator<DistanceFunctorType> PropagatorType;
PropagatorType* propagationFunctor = new PropagatorType;
typedef RandomSearch<ImageType, DistanceFunctorType> RandomSearchType;
RandomSearchType* randomSearchFunctor = new RandomSearchType;
typedef PatchMatch<ImageType, PropagatorType, RandomSearchType> PatchMatchType;
PatchMatchType patchMatch;
patchMatch.SetImage(imageReader->GetOutput());
patchMatch.SetPatchRadius(3);
patchMatch.SetPropagationFunctor(propagationFunctor);
patchMatch.SetRandomSearchFunctor(randomSearchFunctor);
patchMatch.Compute();
NNFieldType::Pointer output = patchMatch.GetNNField();
PatchMatchHelpers::WriteNNField(output.GetPointer(), "nnfield.mha");
return EXIT_SUCCESS;
}
示例6: Vector
void Vector()
{
typedef itk::Image<unsigned char, 2 > ChannelType;
const unsigned int NumberOfChannels = 3;
typedef itk::Image<itk::CovariantVector<unsigned char, NumberOfChannels>, 2 > ImageType;
ImageType::Pointer image = ImageType::New();
itk::Index<2> corner = {{0,0}};
itk::Size<2> imageSize = {{500,500}};
itk::ImageRegion<2> fullRegion(corner, imageSize);
image->SetRegions(fullRegion);
image->Allocate();
for(unsigned int i = 0; i < NumberOfChannels; ++i)
{
itk::RandomImageSource<ChannelType>::Pointer randomImageSource =
itk::RandomImageSource<ChannelType>::New();
randomImageSource->SetNumberOfThreads(1); // to produce non-random results
randomImageSource->SetSize(imageSize);
randomImageSource->Update();
ITKHelpers::SetChannel(image.GetPointer(), i, randomImageSource->GetOutput());
}
itk::Size<2> patchSize = {{21,21}};
// There is nothing magic about these particular patches
itk::Index<2> targetCorner = {{319, 302}};
itk::ImageRegion<2> targetRegion(targetCorner, patchSize);
itk::Index<2> sourceCorner = {{341, 300}};
itk::ImageRegion<2> sourceRegion(sourceCorner, patchSize);
Mask::Pointer mask = Mask::New();
mask->SetRegions(fullRegion);
mask->Allocate();
ITKHelpers::SetImageToConstant(mask.GetPointer(), mask->GetValidValue());
typedef SumSquaredPixelDifference<ImageType::PixelType> PixelDifferenceType;
typedef ImagePatchPixelDescriptor<ImageType> PatchType;
ImagePatchDifference<PatchType, PixelDifferenceType> imagePatchDifference;
PatchType targetPatch(image, mask, targetRegion);
PatchType sourcePatch(image, mask, sourceRegion);
float difference = imagePatchDifference(targetPatch, sourcePatch);
std::cout << "GMHDifference: " << difference << std::endl;
}
示例7: main
int main()
{
FloatVectorImageType::Pointer image = FloatVectorImageType::New();
Testing::GetBlankImage(image.GetPointer(), 4);
Mask::Pointer mask = Mask::New();
Testing::GetFullyValidMask(mask.GetPointer());
unsigned int patchRadius = 5;
PriorityDepth<FloatVectorImageType> priority(image, mask, patchRadius);
itk::Index<2> filledPixel = {{0,0}};
priority.Update(filledPixel);
itk::Index<2> queryPixel = {{0,0}};
priority.ComputePriority(queryPixel);
return EXIT_SUCCESS;
}
示例8: Scalar
void Scalar()
{
typedef itk::Image< unsigned char, 2 > ImageType;
itk::Size<2> imageSize = {{500,500}};
itk::RandomImageSource<ImageType>::Pointer randomImageSource =
itk::RandomImageSource<ImageType>::New();
randomImageSource->SetNumberOfThreads(1); // to produce non-random results
randomImageSource->SetSize(imageSize);
randomImageSource->Update();
ImageType* image = randomImageSource->GetOutput();
itk::Size<2> patchSize = {{21,21}};
// There is nothing magic about these particular patches
itk::Index<2> targetCorner = {{319, 302}};
itk::ImageRegion<2> targetRegion(targetCorner, patchSize);
itk::Index<2> sourceCorner = {{341, 300}};
itk::ImageRegion<2> sourceRegion(sourceCorner, patchSize);
Mask::Pointer mask = Mask::New();
mask->SetRegions(randomImageSource->GetOutput()->GetLargestPossibleRegion());
mask->Allocate();
ITKHelpers::SetImageToConstant(mask.GetPointer(), mask->GetValidValue());
typedef SumSquaredPixelDifference<ImageType::PixelType> PixelDifferenceType;
typedef ImagePatchPixelDescriptor<ImageType> PatchType;
ImagePatchDifference<PatchType, PixelDifferenceType> imagePatchDifference;
PatchType targetPatch(image, mask, targetRegion);
PatchType sourcePatch(image, mask, sourceRegion);
float difference = imagePatchDifference(targetPatch, sourcePatch);
std::cout << "Difference: " << difference << std::endl;
}
示例9: main
int main()
{
typedef itk::Image<itk::CovariantVector<float, 3>, 2> ImageType;
ImageType::Pointer image = ImageType::New();
Testing::GetBlankImage(image.GetPointer(), 4);
Mask::Pointer mask = Mask::New();
Testing::GetFullyValidMask(mask.GetPointer());
vtkSmartPointer<vtkStructuredGrid> structuredGrid = vtkSmartPointer<vtkStructuredGrid>::New();
unsigned int patchRadius = 5;
PriorityCurvature<itk::Index<2> > priority(structuredGrid, patchRadius);
itk::Index<2> filledPixel = {{0,0}};
itk::Index<2> sourcePixel = {{0,0}};
priority.Update(sourcePixel, filledPixel);
itk::Index<2> queryPixel = {{0,0}};
priority.ComputePriority(queryPixel);
return EXIT_SUCCESS;
}
示例10: TestComputeMaskedImage1DHistogram
//.........这里部分代码省略.........
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;
itk::ImageRegion<2> imageRegion = image->GetLargestPossibleRegion();
itk::ImageRegion<2> maskRegion = image->GetLargestPossibleRegion();
typedef MaskedHistogramGenerator<BinValueType> HistogramGeneratorType;
typedef HistogramGeneratorType::HistogramType HistogramType;
bool allowOutside = false;
HistogramType histogram =
HistogramGeneratorType::ComputeMaskedImage1DHistogram(image.GetPointer(), imageRegion,
mask.GetPointer(), maskRegion,
numberOfBinsPerComponent, rangeMins, rangeMaxs,
allowOutside, HoleMaskPixelTypeEnum::VALID);
histogram.Print();
std::cout << std::endl;
}
// // Multi channel Image<CovariantVector>
// {
// typedef itk::Image<itk::CovariantVector<unsigned char, 3>, 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())
// {
// ImageType::PixelType pixel(image->GetNumberOfComponentsPerPixel());
// if(imageIterator.GetIndex()[0] < 70)
// {
// for(unsigned int i = 0; i < pixel.GetNumberOfComponents(); ++i)
// {
// pixel[i] = 255;
// }
// }
// else
// {
// for(unsigned int i = 0; i < pixel.GetNumberOfComponents(); ++i)
// {
// pixel[i] = 0;
// }
// }
// imageIterator.Set(pixel);
// ++imageIterator;
// }
// TypeTraits<ImageType::PixelType>::ComponentType rangeMin = 0;
// TypeTraits<ImageType::PixelType>::ComponentType rangeMax = 255;
// unsigned int numberOfBinsPerComponent = 10;
// typedef int BinValueType;
// Histogram<BinValueType>::HistogramType histogram = Histogram<BinValueType>::ComputeImageHistogram1D(image.GetPointer(),
// image->GetLargestPossibleRegion(),
// numberOfBinsPerComponent, rangeMin, rangeMax);
// Histogram<BinValueType>::OutputHistogram(histogram);
// std::cout << std::endl;
// }
}
示例11: main
int main(int argc, char* argv[])
{
// Verify arguments
if(argc < 5)
{
std::cout << "Usage: PatchImage repeatX repeatY outputImage" << std::endl;
return EXIT_FAILURE;
}
// Parse arguments
std::string patchImageFilename = argv[1];
std::stringstream ssRepeatX;
ssRepeatX << argv[2];
unsigned int repeatX = 0;
ssRepeatX >> repeatX;
std::stringstream ssRepeatY;
ssRepeatY << argv[3];
unsigned int repeatY = 0;
ssRepeatY >> repeatY;
std::string outputFilename = argv[4];
// Output arguments
std::cout << "Patch image: " << patchImageFilename << std::endl
<< "Repeat X: " << repeatX << std::endl
<< "Repeat Y: " << repeatY << std::endl
<< "Output image: " << outputFilename << std::endl;
//typedef itk::VectorImage<float, 2> ImageType;
typedef itk::Image<itk::CovariantVector<float, 3>, 2> ImageType;
// Read patch image
typedef itk::ImageFileReader<ImageType> ImageReaderType;
ImageReaderType::Pointer patchImageReader = ImageReaderType::New();
patchImageReader->SetFileName(patchImageFilename);
patchImageReader->Update();
Mask::Pointer mask = Mask::New();
itk::ImageRegion<2> patchRegion = patchImageReader->GetOutput()->GetLargestPossibleRegion();
mask->SetRegions(patchRegion);
mask->Allocate();
itk::Index<2> holeCorner = {{1,1}};
itk::Size<2> holeSize = patchRegion.GetSize();
holeSize[0] -= 2; // Missing one row on the top, and one row on the bottom
holeSize[1] -= 2; // Missing one column on the left, and one column on the right
itk::ImageRegion<2> holeRegion(holeCorner, holeSize);
mask->SetValid(patchRegion);
mask->SetHole(holeRegion);
ImageType::Pointer seamlessPatch = ImageType::New();
ITKHelpers::DeepCopy(patchImageReader->GetOutput(), seamlessPatch.GetPointer());
// Enforce periodic boundary conditions
// Top and bottom
for(int i = 0; i < static_cast<int>(patchRegion.GetSize()[1]); ++i)
{
itk::Index<2> topPixelIndex = {{0, i}};
itk::Index<2> bottomPixelIndex = {{static_cast<int>(patchRegion.GetSize()[0])-1, i}};
ImageType::PixelType topPixelValue = seamlessPatch->GetPixel(topPixelIndex);
ImageType::PixelType bottomPixelValue = seamlessPatch->GetPixel(bottomPixelIndex);
ImageType::PixelType averageValue = (topPixelValue + bottomPixelValue)/2.0f;
seamlessPatch->SetPixel(topPixelIndex, averageValue);
seamlessPatch->SetPixel(bottomPixelIndex, averageValue);
}
// Left and right
for(int i = 0; i < static_cast<int>(patchRegion.GetSize()[0]); ++i)
{
itk::Index<2> leftPixelIndex = {{i, 0}};
itk::Index<2> rightPixelIndex = {{i, static_cast<int>(patchRegion.GetSize()[1])-1}};
ImageType::PixelType leftPixelValue = seamlessPatch->GetPixel(leftPixelIndex);
ImageType::PixelType rightPixelValue = seamlessPatch->GetPixel(rightPixelIndex);
ImageType::PixelType averageValue = (leftPixelValue + rightPixelValue)/2.0f;
seamlessPatch->SetPixel(leftPixelIndex, averageValue);
seamlessPatch->SetPixel(rightPixelIndex, averageValue);
}
typedef PoissonEditingParent::GuidanceFieldType GuidanceFieldType;
std::vector<GuidanceFieldType::Pointer> guidanceFields = PoissonEditingParent::ComputeGuidanceField(patchImageReader->GetOutput());
ImageType::Pointer output = ImageType::New();
FillImage(seamlessPatch.GetPointer(), mask.GetPointer(),
guidanceFields, output.GetPointer(),
patchRegion, seamlessPatch.GetPointer());
// Write output
ITKHelpers::WriteRGBImage(output.GetPointer(), outputFilename);
// Original tiled
ImageType::Pointer originalTiled = ImageType::New();
TilePatch(patchImageReader->GetOutput(), repeatX, repeatY, originalTiled.GetPointer());
ITKHelpers::WriteRGBImage(originalTiled.GetPointer(), "original_tiled.png");
//.........这里部分代码省略.........
示例12: main
int main(int, char*[])
{
// typedef itk::Image<itk::CovariantVector<int, 3>, 2> ImageType;
typedef itk::Image<itk::CovariantVector<unsigned char, 3>, 2> ImageType;
ImageType::PixelType red;
red.Fill(0);
red[0] = 255;
ImageType::PixelType black;
black.Fill(0);
ImageType::PixelType white;
white.Fill(255);
ImageType::PixelType green; // Note this is not 255 because then the magnitude of red and green would be the same,
// which makes debugging hard since the gradient of the magnitude image is used internally (in IntroducedEnergy).
green.Fill(0);
green[1] = 122;
ImageType::PixelType blue;
blue.Fill(0);
blue[2] = 255;
ImageType::Pointer image = ImageType::New();
itk::Index<2> imageCorner = {{0,0}};
itk::Size<2> imageSize = {{100,100}};
itk::ImageRegion<2> region(imageCorner,imageSize);
image->SetRegions(region);
image->Allocate();
Mask::Pointer mask = Mask::New();
mask->SetRegions(region);
mask->Allocate();
itk::ImageRegionIteratorWithIndex<Mask> initializeMaskIterator(mask, mask->GetLargestPossibleRegion());
while(!initializeMaskIterator.IsAtEnd())
{
if(initializeMaskIterator.GetIndex()[0] < 55)
{
initializeMaskIterator.Set(mask->GetHoleValue());
}
else
{
initializeMaskIterator.Set(mask->GetValidValue());
}
++initializeMaskIterator;
}
ITKHelpers::WriteImage(mask.GetPointer(), "mask.png");
// Create a red image
itk::ImageRegionIterator<ImageType> initializeIterator(image, image->GetLargestPossibleRegion());
while(!initializeIterator.IsAtEnd())
{
initializeIterator.Set(red);
++initializeIterator;
}
// Setup source and target patch
itk::Size<2> patchSize = {{10,10}};
itk::Index<2> sourceCorner = {{10,10}};
itk::ImageRegion<2> sourceRegion(sourceCorner, patchSize);
itk::Index<2> targetCorner = {{50,50}};
itk::ImageRegion<2> targetRegion(targetCorner, patchSize);
itk::Index<2> perfectSourceCorner = {{75,75}};
itk::ImageRegion<2> perfectSourceRegion(perfectSourceCorner, patchSize);
// Make the source patch green
itk::ImageRegionIterator<ImageType> sourceRegionIterator(image, sourceRegion);
while(!sourceRegionIterator.IsAtEnd())
{
sourceRegionIterator.Set(green);
++sourceRegionIterator;
}
ITKHelpers::WriteImage(image.GetPointer(), "image.png");
{
ImageType::Pointer regionHighlightImage = ImageType::New();
ITKHelpers::DeepCopy(image.GetPointer(), regionHighlightImage.GetPointer());
ITKHelpers::OutlineRegion(regionHighlightImage.GetPointer(), sourceRegion, white);
ITKHelpers::OutlineRegion(regionHighlightImage.GetPointer(), targetRegion, black);
ITKHelpers::OutlineRegion(regionHighlightImage.GetPointer(), perfectSourceRegion, blue);
ITKHelpers::WriteImage(regionHighlightImage.GetPointer(), "regions.png");
}
IntroducedEnergy<ImageType> introducedEnergy;
//.........这里部分代码省略.........
示例13: main
int main(int argc, char*argv[])
{
if(argc != 6)
{
std::cerr << "Required arguments: image output R G B" << std::endl;
return EXIT_FAILURE;
}
std::vector<int> values(3,0);
std::stringstream ss;
unsigned int counter = 0;
for(int i = 3; i < argc; ++i)
{
ss << argv[i] << " ";
counter++;
}
for(int i = 0; i < 3; ++i)
{
ss >> values[i];
}
// itk::RGBPixel<unsigned char> color;
// color.SetRed(values[0]);
// color.SetGreen(values[1]);
// color.SetBlue(values[2]);
Color color;
color.r = values[0];
color.g = values[1];
color.b = values[2];
std::string imageFilename = argv[1];
std::string outputMaskFilename = argv[2];
std::cout << "Reading image: " << imageFilename << std::endl;
std::cout << "outputMaskFilename: " << outputMaskFilename << std::endl;
std::cout << "Color: " << static_cast<int>(values[0]) << " " << static_cast<int>(values[1]) << " " << static_cast<int>(values[2]) << std::endl;
//typedef itk::Image<float, 2> ImageType;
typedef itk::Image<itk::CovariantVector<unsigned char, 3>, 2> ImageType;
ImageType::PixelType pixelColor;
pixelColor[0] = color.r;
pixelColor[1] = color.g;
pixelColor[2] = color.b;
typedef itk::ImageFileReader<ImageType> ImageReaderType;
ImageReaderType::Pointer imageReader = ImageReaderType::New();
imageReader->SetFileName(imageFilename.c_str());
imageReader->Update();
Mask::Pointer mask = Mask::New();
mask->SetRegions(imageReader->GetOutput()->GetLargestPossibleRegion());
mask->Allocate();
mask->CreateFromImage(imageReader->GetOutput(), pixelColor);
OutputHelpers::WriteImage(mask.GetPointer(), outputMaskFilename);
return EXIT_SUCCESS;
}
示例14: AcceptMatch
bool AcceptMatch(VertexDescriptorType target, VertexDescriptorType source, float& computedEnergy) const
{
//std::cout << "DilatedVarianceDifferenceAcceptanceVisitor::AcceptMatch" << std::endl;
itk::Index<2> targetPixel = ITKHelpers::CreateIndex(target);
itk::ImageRegion<2> targetRegion = ITKHelpers::GetRegionInRadiusAroundPixel(targetPixel, HalfWidth);
itk::Index<2> sourcePixel = ITKHelpers::CreateIndex(source);
itk::ImageRegion<2> sourceRegion = ITKHelpers::GetRegionInRadiusAroundPixel(sourcePixel, HalfWidth);
// Compute the functor on the pixels in the region just inside the hole in the source patch
typename TypeTraits<typename TImage::PixelType>::LargerType sourceValue;
{
Mask::Pointer originalHole = Mask::New();
ITKHelpers::ExtractRegion(MaskImage, targetRegion, originalHole.GetPointer());
Mask::Pointer shrunkHole = Mask::New();
shrunkHole->DeepCopyFrom(originalHole);
shrunkHole->ShrinkHole(5);
typedef itk::Image<bool, 2> BoolImage;
BoolImage::Pointer holeRindImage = BoolImage::New(); // "rind" like an "orange rind"
ITKHelpers::XORRegions(originalHole.GetPointer(), originalHole->GetLargestPossibleRegion(),
shrunkHole.GetPointer(), shrunkHole->GetLargestPossibleRegion(), holeRindImage.GetPointer());
std::vector<itk::Index<2> > holeRindPixels = ITKHelpers::GetPixelsWithValue(holeRindImage.GetPointer(), holeRindImage->GetLargestPossibleRegion(), true);
itk::Index<2> zeroIndex = {{0,0}};
std::vector<itk::Offset<2> > holeRindOffsets = ITKHelpers::IndicesToOffsets(holeRindPixels, zeroIndex);
std::vector<itk::Index<2> > sourceRindPixelIndices = ITKHelpers::OffsetsToIndices(holeRindOffsets, sourceRegion.GetIndex());
std::vector<typename TImage::PixelType> sourceRindPixels = ITKHelpers::GetPixelValues(Image, sourceRindPixelIndices);
sourceValue = Functor(sourceRindPixels);
}
// Compute the functor on the pixels in the region just outside the hole in the target patch
typename TypeTraits<typename TImage::PixelType>::LargerType targetValue;
{
Mask::Pointer originalHole = Mask::New();
ITKHelpers::ExtractRegion(MaskImage, targetRegion, originalHole.GetPointer());
Mask::Pointer expandedHole = Mask::New();
expandedHole->DeepCopyFrom(originalHole);
expandedHole->ExpandHole(5);
typedef itk::Image<bool, 2> BoolImage;
BoolImage::Pointer validRindImage = BoolImage::New(); // "rind" like an "orange rind"
ITKHelpers::XORRegions(originalHole.GetPointer(), originalHole->GetLargestPossibleRegion(),
expandedHole.GetPointer(), expandedHole->GetLargestPossibleRegion(), validRindImage.GetPointer());
std::vector<itk::Index<2> > validRindPixels = ITKHelpers::GetPixelsWithValue(validRindImage.GetPointer(), validRindImage->GetLargestPossibleRegion(), true);
itk::Index<2> zeroIndex = {{0,0}};
std::vector<itk::Offset<2> > validRindOffsets = ITKHelpers::IndicesToOffsets(validRindPixels, zeroIndex);
std::vector<itk::Index<2> > targetRindPixelIndices = ITKHelpers::OffsetsToIndices(validRindOffsets, targetRegion.GetIndex());
std::vector<typename TImage::PixelType> targetRindPixels = ITKHelpers::GetPixelValues(Image, targetRindPixelIndices);
targetValue = Functor(targetRindPixels);
}
// Compute the difference
computedEnergy = (targetValue - sourceValue).GetNorm();
//std::cout << this->VisitorName << " Energy: " << computedEnergy << std::endl;
if(computedEnergy < DifferenceThreshold)
{
std::cout << this->VisitorName << ": Match accepted (" << computedEnergy << " is less than " << DifferenceThreshold << ")" << std::endl << std::endl;
return true;
}
else
{
std::cout << this->VisitorName << ": Match rejected (" << computedEnergy << " is greater than " << DifferenceThreshold << ")" << std::endl << std::endl;
return false;
}
};
开发者ID:nocnokneo,项目名称:PatchBasedInpainting,代码行数:75,代码来源:DilatedSourceHoleTargetValidAcceptanceVisitor.hpp
示例15: main
//.........这里部分代码省略.........
// OutputHelpers::OutputVector(pixelDifferenceFunctor.Weights);
// typedef ImagePatchDifference<ImagePatchPixelDescriptorType, PixelDifferenceFunctorType >
// ImagePatchDifferenceType;
//
// ImagePatchDifferenceType imagePatchDifferenceFunction(pixelDifferenceFunctor);
typedef CompositeDescriptorVisitor<VertexListGraphType> CompositeDescriptorVisitorType;
CompositeDescriptorVisitorType compositeDescriptorVisitor;
compositeDescriptorVisitor.AddVisitor(&imagePatchDescriptorVisitor);
typedef CompositeAcceptanceVisitor<VertexListGraphType> CompositeAcceptanceVisitorType;
CompositeAcceptanceVisitorType compositeAcceptanceVisitor;
typedef InpaintingVisitor<VertexListGraphType, ImageType, BoundaryNodeQueueType,
CompositeDescriptorVisitorType, CompositeAcceptanceVisitorType, PriorityType,
PriorityMapType, BoundaryStatusMapType>
InpaintingVisitorType;
InpaintingVisitorType inpaintingVisitor(image, mask, boundaryNodeQueue,
compositeDescriptorVisitor, compositeAcceptanceVisitor, priorityMap,
&priorityFunction, patchHalfWidth,
boundaryStatusMap, outputFilename);
typedef DisplayVisitor<VertexListGraphType, ImageType> DisplayVisitorType;
DisplayVisitorType displayVisitor(image, mask, patchHalfWidth);
typedef DebugVisitor<VertexListGraphType, ImageType, BoundaryStatusMapType, BoundaryNodeQueueType>
DebugVisitorType;
DebugVisitorType debugVisitor(image, mask, patchHalfWidth, boundaryStatusMap, boundaryNodeQueue);
LoggerVisitor<VertexListGraphType> loggerVisitor("log.txt");
PaintPatchVisitor<VertexListGraphType, ImageType> inpaintRGBVisitor(image,
mask.GetPointer(), patchHalfWidth);
typedef CompositeInpaintingVisitor<VertexListGraphType> CompositeInpaintingVisitorType;
CompositeInpaintingVisitorType compositeInpaintingVisitor;
compositeInpaintingVisitor.AddVisitor(&inpaintingVisitor);
//compositeInpaintingVisitor.AddVisitor(&inpaintRGBVisitor);
compositeInpaintingVisitor.AddVisitor(&displayVisitor);
compositeInpaintingVisitor.AddVisitor(&debugVisitor);
//compositeInpaintingVisitor.AddVisitor(&loggerVisitor);
InitializePriority(mask, boundaryNodeQueue, priorityMap, &priorityFunction, boundaryStatusMap);
// Initialize the boundary node queue from the user provided mask image.
InitializeFromMaskImage<CompositeInpaintingVisitorType, VertexDescriptorType>(mask, &compositeInpaintingVisitor);
// Create the nearest neighbor finders
typedef LinearSearchKNNProperty<ImagePatchDescriptorMapType,
ImagePatchDifferenceType > KNNSearchType;
KNNSearchType knnSearch(imagePatchDescriptorMap, 50000, 1, imagePatchDifferenceFunction);
// For debugging we use LinearSearchBestProperty instead of DefaultSearchBest
// because it can output the difference value.
typedef LinearSearchBestProperty<ImagePatchDescriptorMapType,
ImagePatchDifferenceType > BestSearchType;
BestSearchType bestSearch(imagePatchDescriptorMap, imagePatchDifferenceFunction);
BasicViewerWidget<ImageType> basicViewerWidget(image, mask);
basicViewerWidget.show();
// These connections are Qt::BlockingQueuedConnection because the algorithm quickly
// goes on to fill the hole, and since we are sharing the image memory, we want to make sure these things are
// refreshed at the right time, not after the hole has already been filled
// (this actually happens, it is not just a theoretical thing).